Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linusw@kernel.org>, Bartosz Golaszewski <brgl@kernel.org>
Subject: Re: [PATCH v1 1/1] gpiolib: shared: Don't define variable in the middle of the code
Date: Tue, 13 Oct 2026 12:04:41 +0200	[thread overview]
Message-ID: <d5508a2a-518e-46ee-a821-b6209ef35bfb@kernel.org> (raw)
In-Reply-To: <20261013094412.945609-1-andriy.shevchenko@linux.intel.com>

On 13. 10. 26, 11:44, Andy Shevchenko wrote:
> While the C11 allows us to define variables in the code, we do not
> do this style (see more at [1]). Move the declaration to the top of
> the function.
> 
> Link: https://lore.kernel.org/lkml/58fd478f408a34b578ee8d949c5c4b4da4d4f41d.camel@HansenPartnership.com/ [1]

 From the link, I have just learnt two things:
1) I am not alone preferring declarations in the middle of blocks (it 
has more pros than cons IMO). But again, I spend a lot of time in the 
c++ universe.
2) the kernel defines "auto" even for < c23. Therefore:

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/gpio/gpiolib-shared.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
> index 5f9623e40b0f..40c08f1ae5f0 100644
> --- a/drivers/gpio/gpiolib-shared.c
> +++ b/drivers/gpio/gpiolib-shared.c
> @@ -196,6 +196,7 @@ static int gpio_shared_of_traverse(struct device_node *curr)
>   		for (i = 0; i < count; i++) {
>   			struct device_node *np __free(device_node) = NULL;
>   			char *con_id __free(kfree) = NULL;
> +			struct fwnode_handle *curr_fwnode;
>   
>   			ret = of_parse_phandle_with_args(curr, prop->name,
>   							 "#gpio-cells", i,
> @@ -261,8 +262,7 @@ static int gpio_shared_of_traverse(struct device_node *curr)
>   				con_id[con_id_len - suffix_len] = '\0';
>   			}
>   
> -			struct fwnode_handle *curr_fwnode =
> -				fwnode_handle_get(of_fwnode_handle(curr));
> +			curr_fwnode = fwnode_handle_get(of_fwnode_handle(curr));

For me, much cleaner would be the c++ way. Ie. doing:

   auto curr_fwnode = fwnode_handle_get(of_fwnode_handle(curr));

Everyone is supposed to use clangd, tree-sitter or alike nowadays. So 
inferring the type is the very same for start-of-block-declaration 
(which is miles away from the assignment now) and auto-declaration. 
While the latter obfuscates the code less (and eases local vars addition 
w/o jumping back and forth).

>   			ref = gpio_shared_make_ref(curr_fwnode, con_id, args.args[1]);
>   			if (!ref) {
>   				fwnode_handle_put(curr_fwnode);

thanks,
-- 
js
suse labs

      reply	other threads:[~2026-10-13 10:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  9:44 [PATCH v1 1/1] gpiolib: shared: Don't define variable in the middle of the code Andy Shevchenko
2026-10-13 10:04 ` Jiri Slaby [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=d5508a2a-518e-46ee-a821-b6209ef35bfb@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.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