From: Kent Gibson <warthog618@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: heminhong <heminhong@kylinos.cn>,
linus.walleij@linaro.org, brgl@bgdev.pl, andy@kernel.org,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/gpio: prevent resource leak
Date: Thu, 9 Nov 2023 21:58:31 +0800 [thread overview]
Message-ID: <ZUzlh9M-w4ZITvGW@rigel> (raw)
In-Reply-To: <CAHp75Vd5Ea_yFb7tEQw5ZBr90CcETa-_BsbfpfFshFx8ddZqQA@mail.gmail.com>
On Thu, Nov 09, 2023 at 03:53:45PM +0200, Andy Shevchenko wrote:
> On Thu, Nov 9, 2023 at 2:36 PM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > On Thu, Nov 09, 2023 at 04:54:19PM +0800, heminhong wrote:
> > > In the main() function, the open() function is used to open the file.
> > > When the file is successfully opened, fd is used to interact with the file,
> > > but the fd is not closed, it will cause resource leak.
> > >
> >
> > All open files are automatically closed when a process exits.
> > That includes both those returned by open() and by the GPIO ioctls.
> > So explicitly closing them here before exiting is redundant.
>
> I would argue that this is a good practice for GPIO cases.
> More the GPIOs we have, the more line handles we can get, then default
> MAX open FD limit may occur. The best is to combine both.
>
That makes sense if the application is long lived and is continually
requesting and releasing resources, but that is not the case here - this
is a short lived app that makes a single request.
Note the "here" in my initial reply.
Cheers,
Kent.
prev parent reply other threads:[~2023-11-09 13:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 8:54 [PATCH] tools/gpio: prevent resource leak heminhong
2023-11-09 12:36 ` Kent Gibson
2023-11-09 12:50 ` Linus Walleij
2023-11-09 13:53 ` Andy Shevchenko
2023-11-09 13:58 ` Kent Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZUzlh9M-w4ZITvGW@rigel \
--to=warthog618@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=heminhong@kylinos.cn \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox