From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Linus Walleij <linusw@kernel.org>
Cc: Bartosz Golaszewski <brgl@kernel.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] gpio: Fix resource leaks on errors in gpiochip_add_data_with_key()
Date: Thu, 5 Feb 2026 09:34:57 +0000 [thread overview]
Message-ID: <aYRkQRqmJZ-CMEhU@google.com> (raw)
In-Reply-To: <CAD++jL=vkMYQSKxq+5LsEW7aQAkbvVf00gv64hYRjWwsqzSHZg@mail.gmail.com>
On Tue, Feb 03, 2026 at 10:35:14AM +0100, Linus Walleij wrote:
> On Tue, Feb 3, 2026 at 7:02 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
> > Also reorder the instructions to make the error handling simpler.
> > Now gpiochip_add_data_with_key() roughly looks like:
> >
> > >>> Some memory allocation. Go to ERR ZONE 1 on errors.
> > >>> device_initialize().
> >
> > (gpiodev_release() takes over the responsibility for freeing the
> > resources of `gdev->dev`. The subsequent error handling paths
> > shouldn't go through ERR ZONE 1 again which leads to double free.)
>
> This doesn't need to be parenthesized, it should be pointed out
> so people can follow it, also:
>
[...]
> > + device_initialize(&gdev->dev);
> > + gdev->dev.type = &gpio_dev_type;
>
>
> This is the point where, from this point on, gpiodev_release() will
> get called from the type.
>
> This is worth a comment in the code don't you think?
>
> Something like:
>
> /*
> * After this point any allocated resources will be free():d by
> * gpiodev_release(), if you add new resources then make sure
> * they get free():ed there.
> */
> gdev->dev.type = &gpio_dev_type;
>
> This helps developers to do the right thing.
>
> With that added comment:
> Reviewed-by: Linus Walleij <linusw@kernel.org>
Thanks for your review. Fix both of them in v3
https://lore.kernel.org/all/20260205092840.2574840-1-tzungbi@kernel.org/.
prev parent reply other threads:[~2026-02-05 9:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-03 6:02 [PATCH v2] gpio: Fix resource leaks on errors in gpiochip_add_data_with_key() Tzung-Bi Shih
2026-02-03 9:35 ` Linus Walleij
2026-02-05 9:34 ` Tzung-Bi Shih [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=aYRkQRqmJZ-CMEhU@google.com \
--to=tzungbi@kernel.org \
--cc=brgl@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.