[PATCH] gpio: merrifield: check the return value of devm_kstrdup()

xkernel.wang@foxmail.com posted 1 patch 4 years, 5 months ago
There is a newer version of this series
drivers/gpio/gpio-merrifield.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] gpio: merrifield: check the return value of devm_kstrdup()
Posted by xkernel.wang@foxmail.com 4 years, 5 months ago
From: Xiaoke Wang <xkernel.wang@foxmail.com>

devm_kstrdup() returns pointer to allocated string on success,
NULL on failure. So it is better to check the return value of it.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/gpio/gpio-merrifield.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c
index 42c4d9d..f3d1bae 100644
--- a/drivers/gpio/gpio-merrifield.c
+++ b/drivers/gpio/gpio-merrifield.c
@@ -409,6 +409,9 @@ static int mrfld_gpio_add_pin_ranges(struct gpio_chip *chip)
 	int retval;
 
 	pinctrl_dev_name = mrfld_gpio_get_pinctrl_dev_name(priv);
+	if (!pinctrl_dev_name)
+		return -ENOMEM;
+
 	for (i = 0; i < ARRAY_SIZE(mrfld_gpio_ranges); i++) {
 		range = &mrfld_gpio_ranges[i];
 		retval = gpiochip_add_pin_range(&priv->chip, pinctrl_dev_name,
-- 
Re: [PATCH] gpio: merrifield: check the return value of devm_kstrdup()
Posted by Andy Shevchenko 4 years, 5 months ago
On Sun, Jan 16, 2022 at 10:21 AM <xkernel.wang@foxmail.com> wrote:
>
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> devm_kstrdup() returns pointer to allocated string on success,
> NULL on failure. So it is better to check the return value of it.

Before if devm_kstrdup() fails, the GPIO driver will be registered
without pin control, now it will fail the registration.

It's not that I'm against the patch (the above is quite unlikely and
brings a not fully working system on most of the known platforms with
this SoC), but you need to do better your analysis. That said, please
rethink a bit the commit message you put there and send an updated
version.


-- 
With Best Regards,
Andy Shevchenko