Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	linus.walleij@linaro.org, linux-gpio@vger.kernel.org
Subject: Re: [PATCH] gpio: gpiolib: fix refcount imbalance in gpiochip_setup_dev()
Date: Tue, 17 Dec 2024 17:50:04 +0300	[thread overview]
Message-ID: <83a0821e-eac8-442f-bbeb-de2d439c02dd@stanley.mountain> (raw)
In-Reply-To: <1cbec5a7-6c83-4abe-8532-041dbf891e16@pf.is.s.u-tokyo.ac.jp>

Most static checker stuff is cleanup code.  I've written a blog entry on
clean up code.

https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/

You mostly get this right, but one thing which could help is rule #6
where ideally the cleanup in the function is copy and pasted to create
the release function.

So when you add cleanup to the error paths, check the release function
and see what it does.  Sometimes you've seen the clean up code is missing
in the release function.  Other times it calls wrapper like
gpio_put_device() instead of calling put_device() directly.  The function
calls should be in a specific order, (hopefully the reverse order of how
they're allocated).

regards,
dan carpenter


      parent reply	other threads:[~2024-12-17 14:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 12:21 [PATCH] gpio: gpiolib: fix refcount imbalance in gpiochip_setup_dev() Joe Hattori
2024-12-04 17:09 ` Linus Walleij
2024-12-05 12:09 ` Bartosz Golaszewski
2024-12-05 13:20 ` Andy Shevchenko
2024-12-05 13:23   ` Andy Shevchenko
2024-12-05 13:30   ` Bartosz Golaszewski
2024-12-06  8:53     ` Joe Hattori
2024-12-06 15:40       ` Andy Shevchenko
2024-12-17 14:50       ` Dan Carpenter [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=83a0821e-eac8-442f-bbeb-de2d439c02dd@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=brgl@bgdev.pl \
    --cc=joe@pf.is.s.u-tokyo.ac.jp \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@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