All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Kent Gibson <warthog618@gmail.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	akpm@linux-foundation.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH v3 2/2] gpio: sim: initialize a managed pointer when declaring it
Date: Mon, 18 Sep 2023 10:06:00 +0300	[thread overview]
Message-ID: <ZQf22FxCiPe2GUcd@smile.fi.intel.com> (raw)
In-Reply-To: <20230917091225.6350-3-brgl@bgdev.pl>

On Sun, Sep 17, 2023 at 11:12:25AM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> Variables managed with __free() should typically be initialized where
> they are declared so that the __free() callback is paired with its
> counterpart resource allocator. Fix the second instance of using
> __free() in gpio-sim to follow this pattern.

...

>  {
> -	struct gpio_sim_device *dev __free(kfree) = NULL;
>  	int id;
>  
> -	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> +	struct gpio_sim_device *dev __free(kfree) = kzalloc(sizeof(*dev),
> +							    GFP_KERNEL);
>  	if (!dev)
>  		return ERR_PTR(-ENOMEM);

Aside: Oh, this might be a downside of the __free() sugar, as we can
theoretically end up with a code in the future like

	struct bar *foo;
	...
	struct baz *foo __free() = ...
	...

and I am not sure how it goes to work. Or relaxed variant with

	struct bar *foo;
	...
	{
		struct baz *foo __free() = ...
		...
	}

where we would have two variables with the same name, but different scope
(this, perhaps, would work, but I assume compiler should warn about shadowed
 name for the variable).

(Also what if in both cases bar == baz, i.e. same type?)

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2023-09-18  7:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-17  9:12 [PATCH v3 0/2] gpio: sim: improve the usage of __free() Bartosz Golaszewski
2023-09-17  9:12 ` [PATCH v3 1/2] gpio: sim: fix an invalid __free() usage Bartosz Golaszewski
2023-09-17 16:46   ` Linus Torvalds
2023-09-17 18:59     ` Bartosz Golaszewski
2023-09-17  9:12 ` [PATCH v3 2/2] gpio: sim: initialize a managed pointer when declaring it Bartosz Golaszewski
2023-09-18  7:06   ` Andy Shevchenko [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=ZQf22FxCiPe2GUcd@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=warthog618@gmail.com \
    /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.