mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] scripts: generate_rust_analyzer.py: avoid FD leak
@ 2026-01-27 16:35 Tamir Duberstein
  2026-01-27 16:41 ` Gary Guo
  0 siblings, 1 reply; 4+ messages in thread
From: Tamir Duberstein @ 2026-01-27 16:35 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Alex Gaynor, Fiona Behrens,
	Boris-Chengbiao Zhou
  Cc: Kees Cook, rust-for-linux, linux-kernel, stable, Daniel Almeida,
	Tamir Duberstein

Use `pathlib.Path.read_text()` to avoid leaking file descriptors.

Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
Cc: stable@vger.kernel.org
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
Changes in v2:
- Use pathlib.Path.read_text. (Levi Zim)
- Drop errant Tested-by tag. (Miguel Ojeda)
- Link to v1: https://patch.msgid.link/20260122-rust-analyzer-fd-leak-v1-1-945577813b20@kernel.org
---
 scripts/generate_rust_analyzer.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 3b645da90092..152bd3705303 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -190,9 +190,10 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
 
     def is_root_crate(build_file, target):
         try:
-            return f"{target}.o" in open(build_file).read()
+            contents = build_file.read_text()
         except FileNotFoundError:
             return False
+        return f"{target}.o" in contents
 
     # Then, the rest outside of `rust/`.
     #

---
base-commit: 2af6ad09fc7dfe9b3610100983cccf16998bf34d
change-id: 20260122-rust-analyzer-fd-leak-b247830d666e

Best regards,
--  
Tamir Duberstein <tamird@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scripts: generate_rust_analyzer.py: avoid FD leak
  2026-01-27 16:35 [PATCH v2] scripts: generate_rust_analyzer.py: avoid FD leak Tamir Duberstein
@ 2026-01-27 16:41 ` Gary Guo
  2026-01-27 16:46   ` Tamir Duberstein
  0 siblings, 1 reply; 4+ messages in thread
From: Gary Guo @ 2026-01-27 16:41 UTC (permalink / raw)
  To: Tamir Duberstein, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Alex Gaynor, Fiona Behrens,
	Boris-Chengbiao Zhou
  Cc: Kees Cook, rust-for-linux, linux-kernel, stable, Daniel Almeida

On Tue Jan 27, 2026 at 4:35 PM GMT, Tamir Duberstein wrote:
> Use `pathlib.Path.read_text()` to avoid leaking file descriptors.
>
> Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
> Cc: stable@vger.kernel.org
> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
> Reviewed-by: Fiona Behrens <me@kloenk.dev>
> Reviewed-by: Trevor Gross <tmgross@umich.edu>
> Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> ---
> Changes in v2:
> - Use pathlib.Path.read_text. (Levi Zim)
> - Drop errant Tested-by tag. (Miguel Ojeda)
> - Link to v1: https://patch.msgid.link/20260122-rust-analyzer-fd-leak-v1-1-945577813b20@kernel.org
> ---
>  scripts/generate_rust_analyzer.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 3b645da90092..152bd3705303 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -190,9 +190,10 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
>  
>      def is_root_crate(build_file, target):
>          try:
> -            return f"{target}.o" in open(build_file).read()
> +            contents = build_file.read_text()

Couldn't this just be

    return f"{target.o}" in build_file.read_text()

?

Best,
Gary

>          except FileNotFoundError:
>              return False
> +        return f"{target}.o" in contents
>  
>      # Then, the rest outside of `rust/`.
>      #
>
> ---
> base-commit: 2af6ad09fc7dfe9b3610100983cccf16998bf34d
> change-id: 20260122-rust-analyzer-fd-leak-b247830d666e
>
> Best regards,
> --  
> Tamir Duberstein <tamird@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scripts: generate_rust_analyzer.py: avoid FD leak
  2026-01-27 16:41 ` Gary Guo
@ 2026-01-27 16:46   ` Tamir Duberstein
  2026-03-02 16:28     ` Tamir Duberstein
  0 siblings, 1 reply; 4+ messages in thread
From: Tamir Duberstein @ 2026-01-27 16:46 UTC (permalink / raw)
  To: Gary Guo
  Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Alex Gaynor, Fiona Behrens, Boris-Chengbiao Zhou, Kees Cook,
	rust-for-linux, linux-kernel, stable, Daniel Almeida

On Tue, Jan 27, 2026 at 11:41 AM Gary Guo <gary@garyguo.net> wrote:
>
> On Tue Jan 27, 2026 at 4:35 PM GMT, Tamir Duberstein wrote:
> > Use `pathlib.Path.read_text()` to avoid leaking file descriptors.
> >
> > Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
> > Cc: stable@vger.kernel.org
> > Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
> > Reviewed-by: Fiona Behrens <me@kloenk.dev>
> > Reviewed-by: Trevor Gross <tmgross@umich.edu>
> > Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> > ---
> > Changes in v2:
> > - Use pathlib.Path.read_text. (Levi Zim)
> > - Drop errant Tested-by tag. (Miguel Ojeda)
> > - Link to v1: https://patch.msgid.link/20260122-rust-analyzer-fd-leak-v1-1-945577813b20@kernel.org
> > ---
> >  scripts/generate_rust_analyzer.py | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > index 3b645da90092..152bd3705303 100755
> > --- a/scripts/generate_rust_analyzer.py
> > +++ b/scripts/generate_rust_analyzer.py
> > @@ -190,9 +190,10 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> >
> >      def is_root_crate(build_file, target):
> >          try:
> > -            return f"{target}.o" in open(build_file).read()
> > +            contents = build_file.read_text()
>
> Couldn't this just be
>
>     return f"{target.o}" in build_file.read_text()
>
> ?

Yes, of course. I chose this form to be just a bit more explicit about
exception handling.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scripts: generate_rust_analyzer.py: avoid FD leak
  2026-01-27 16:46   ` Tamir Duberstein
@ 2026-03-02 16:28     ` Tamir Duberstein
  0 siblings, 0 replies; 4+ messages in thread
From: Tamir Duberstein @ 2026-03-02 16:28 UTC (permalink / raw)
  To: Gary Guo
  Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Alex Gaynor, Fiona Behrens, Boris-Chengbiao Zhou, Kees Cook,
	rust-for-linux, linux-kernel, stable, Daniel Almeida

On Tue, Jan 27, 2026 at 11:46 AM Tamir Duberstein <tamird@kernel.org> wrote:
>
> On Tue, Jan 27, 2026 at 11:41 AM Gary Guo <gary@garyguo.net> wrote:
> >
> > On Tue Jan 27, 2026 at 4:35 PM GMT, Tamir Duberstein wrote:
> > > Use `pathlib.Path.read_text()` to avoid leaking file descriptors.
> > >
> > > Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
> > > Cc: stable@vger.kernel.org
> > > Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
> > > Reviewed-by: Fiona Behrens <me@kloenk.dev>
> > > Reviewed-by: Trevor Gross <tmgross@umich.edu>
> > > Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> > > ---
> > > Changes in v2:
> > > - Use pathlib.Path.read_text. (Levi Zim)
> > > - Drop errant Tested-by tag. (Miguel Ojeda)
> > > - Link to v1: https://patch.msgid.link/20260122-rust-analyzer-fd-leak-v1-1-945577813b20@kernel.org
> > > ---
> > >  scripts/generate_rust_analyzer.py | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > > index 3b645da90092..152bd3705303 100755
> > > --- a/scripts/generate_rust_analyzer.py
> > > +++ b/scripts/generate_rust_analyzer.py
> > > @@ -190,9 +190,10 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > >
> > >      def is_root_crate(build_file, target):
> > >          try:
> > > -            return f"{target}.o" in open(build_file).read()
> > > +            contents = build_file.read_text()
> >
> > Couldn't this just be
> >
> >     return f"{target.o}" in build_file.read_text()
> >
> > ?
>
> Yes, of course. I chose this form to be just a bit more explicit about
> exception handling.

Applied to `rust-analyzer-next`. Thanks all.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-02 16:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-27 16:35 [PATCH v2] scripts: generate_rust_analyzer.py: avoid FD leak Tamir Duberstein
2026-01-27 16:41 ` Gary Guo
2026-01-27 16:46   ` Tamir Duberstein
2026-03-02 16:28     ` Tamir Duberstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®