linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-serial@vger.kernel.org, linux-gpio@vger.kernel.org,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Pavel Machek <pavel@denx.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)
Date: Thu, 8 Aug 2019 15:59:36 +0200	[thread overview]
Message-ID: <c4d14b64-6c2f-7e87-ea45-aa780dca85b8@denx.de> (raw)
In-Reply-To: <20190808134859.GY30120@smile.fi.intel.com>

Hi Andy,

On 08.08.19 15:48, Andy Shevchenko wrote:
> On Thu, Aug 08, 2019 at 03:25:43PM +0200, Stefan Roese wrote:
>> This patch fixes a backward compatibility issue, when boards use the
>> old style GPIO suffix "-gpio" instead of the new "-gpios". This
>> potential problem has been introduced by commit d99482673f95 ("serial:
>> mctrl_gpio: Check if GPIO property exisits before requesting it").
>>
>> This patch now fixes this issue by iterating over all supported GPIO
>> suffixes by using the newly introduced for_each_gpio_suffix() helper.
>>
>> Also, the string buffer is now allocated on the stack to avoid the
>> problem of allocation in a loop and its potential failure.
> 
>>   	for (i = 0; i < UART_GPIO_MAX; i++) {
>>   		enum gpiod_flags flags;
>> -		char *gpio_str;
>> +		const char *suffix;
>> +		char gpio_str[32];	/* 32 is max size of property name */
> 
> Hmm... don't we have some define for the maximum length of property?

I've come up with this assumption from this code (identical comment):

https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib-of.c#L293

(and other places in drivers/gpio/*)
  
> Or maybe we can still continue using kasprintf() approach?

Frankly, I was feeling a bit uncomfortable with this memory allocation
in a loop. And Pavel also commented on this:

https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg2066286.html

So I would really prefer to move this buffer to the stack instead.
  
>>   		bool present;
>> +		int k;
>> +
>> +		/*
>> +		 * Check if GPIO property exists and continue if not. Iterate
>> +		 * over all supported GPIO suffixes (foo-gpios vs. foo-gpio).
>> +		 */
>> +		for_each_gpio_suffix(k, suffix) {
>> +			snprintf(gpio_str, sizeof(gpio_str), "%s-%s",
>> +				 mctrl_gpios_desc[i].name, suffix);
>> +
>> +			present = device_property_present(dev, gpio_str);
>> +			if (present)
>> +				break;
>> +		}
>>   
>> -		/* Check if GPIO property exists and continue if not */
>> -		gpio_str = kasprintf(GFP_KERNEL, "%s-gpios",
>> -				     mctrl_gpios_desc[i].name);
>> -		if (!gpio_str)
>> -			continue;
>> -
> 
>> -		present = device_property_present(dev, gpio_str);
> 
> Because there is no more explicit assignment of present outside of the loop,
> the compiler may warn about uninitialized variable in use...
> 
>> -		kfree(gpio_str);
> 
>>   		if (!present)
> 
> ...here.

My compiler does not warn (MIPS GCC 8.1) but I see your point. I'll add
an initialization in the next version.

Thanks,
Stefan

  reply	other threads:[~2019-08-08 13:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 13:25 [PATCH 1/2] gpiolib: Add for_each_gpio_suffix() helper Stefan Roese
2019-08-08 13:25 ` [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio) Stefan Roese
2019-08-08 13:48   ` Andy Shevchenko
2019-08-08 13:59     ` Stefan Roese [this message]
2019-08-12 10:53       ` Andy Shevchenko
2019-08-13 11:42         ` Pavel Machek
2019-08-13 12:15           ` Andy Shevchenko
2019-08-12 11:17   ` Geert Uytterhoeven
2019-08-12 11:53     ` Stefan Roese
2019-08-12 12:11       ` Geert Uytterhoeven
2019-08-12 12:31         ` Andy Shevchenko
2019-08-08 13:44 ` [PATCH 1/2] gpiolib: Add for_each_gpio_suffix() helper Andy Shevchenko
2019-08-08 14:13   ` Stefan Roese
2019-08-10  8:27 ` Linus Walleij
2019-08-10  8:48   ` Greg Kroah-Hartman
2019-08-12 11:18   ` Geert Uytterhoeven
2019-08-14  8:48     ` Linus Walleij
2019-08-14 13:17       ` Stefan Roese
2019-08-14 13:32         ` Geert Uytterhoeven
2019-08-14 13:38         ` Andy Shevchenko

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=c4d14b64-6c2f-7e87-ea45-aa780dca85b8@denx.de \
    --to=sr@denx.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=pavel@denx.de \
    /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;
as well as URLs for NNTP newsgroup(s).