Skip to contentSkip to conversation

gpio: davinci: Add missing return checks

PATCH Superseded Keerthy 3 participants 13 messages Jul 20, 2017 – Aug 7, 2017

Subsystems (2)
lore
Share & tools
lore

Keerthy

author maintainer
#0 lore raw

v2 cover gpio: davinci: Add missing return checks

The patch series does a couple of important return handling which were missed earlier in the driver probe.

This is based on Suman's:

http://marc.info/?l=linux-arm-kernel&m=150034845427555&w=2
http://marc.info/?l=linux-arm-kernel&m=150034856627618&w=2

Changes in v2:

* Removed the device tree patch for to keep the series independent.

Keerthy (3):
gpio: davinci: Use devm_gpiochip_add_data in place of
gpiochip_add_data
gpio: davinci: Handle the return value of davinci_gpio_irq_setup
function
gpio: davinci: Convert prinkt to dev_err

 drivers/gpio/gpio-davinci.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH v2 1/3 gpio: davinci: Use devm_gpiochip_add_data in place of gpiochip_add_data

Use the devm version of gpiochip_add_data and pass on the return value. This avoids memory leak due to gpiochip_add_data in case the driver is unbound.

---

Changes in v2:

* Restoring the previous values of ctrl_num and bank_base in case of an error.

 drivers/gpio/gpio-davinci.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/gpio/gpio-davinci.c +12 -2
index 65cb359..27499ec 100644
@@ -166,7 +166,7 @@ static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
 static int davinci_gpio_probe(struct platform_device *pdev)
 {
 	static int ctrl_num, bank_base;
-	int gpio, bank;
+	int gpio, bank, ret = 0;
 	unsigned ngpio, nbank;
 	struct davinci_gpio_controller *chips;
 	struct davinci_gpio_platform_data *pdata;
@@ -232,10 +232,20 @@ static int davinci_gpio_probe(struct platform_device *pdev)
 	for (gpio = 0, bank = 0; gpio < ngpio; gpio += 32, bank++)
 		chips->regs[bank] = gpio_base + offset_array[bank];
 
-	gpiochip_add_data(&chips->chip, chips);
+	ret = devm_gpiochip_add_data(dev, &chips->chip, chips);
+	if (ret)
+		goto err;
+
 	platform_set_drvdata(pdev, chips);
 	davinci_gpio_irq_setup(pdev);
 	return 0;
+
+err:
+	/* Revert the static variable increments */
+	ctrl_num--;
+	bank_base -= ngpio;
+
+	return ret;
 }
 
 /*--------------------------------------------------------------------------*/
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 1/3 gpio: davinci: Use devm_gpiochip_add_data in place of gpiochip_add_data

Quoted 5 lines · Keerthy

Use the devm version of gpiochip_add_data and pass on the return value. This avoids memory leak due to gpiochip_add_data in case the driver is unbound.

Patch applied.

Yours,
Linus Walleij

author maintainer
#3 lore raw

PATCH v2 2/3 gpio: davinci: Handle the return value of davinci_gpio_irq_setup function

In reply to Keerthy

Currently davinci_gpio_irq_setup return value is ignored. Handle the return value appropriately.

---
 drivers/gpio/gpio-davinci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpio/gpio-davinci.c +4 -1
index 27499ec..d6fb1ce 100644
@@ -237,7 +237,10 @@ static int davinci_gpio_probe(struct platform_device *pdev)
 		goto err;
 
 	platform_set_drvdata(pdev, chips);
-	davinci_gpio_irq_setup(pdev);
+	ret = davinci_gpio_irq_setup(pdev);
+	if (ret)
+		goto err;
+
 	return 0;
 
 err:
Signature · 1 line
1.9.1
author maintainer
#4 lore raw

PATCH v2 2/3 gpio: davinci: Handle the return value of davinci_gpio_irq_setup function

Quoted 2 lines · Keerthy

Currently davinci_gpio_irq_setup return value is ignored. Handle the return value appropriately.

Linus,

Any comments on this? Sorry if i pinged too soon. The rest 2 of this series were pulled by you. So just wanted to check on this one if you had specific comments.

Regards,
Keerthy

Quoted 23 lines
---
 drivers/gpio/gpio-davinci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpio/gpio-davinci.c +4 -1
index 27499ec..d6fb1ce 100644
@@ -237,7 +237,10 @@ static int davinci_gpio_probe(struct platform_device *pdev)
 		goto err;
 
 	platform_set_drvdata(pdev, chips);
-	davinci_gpio_irq_setup(pdev);
+	ret = davinci_gpio_irq_setup(pdev);
+	if (ret)
+		goto err;
+
 	return 0;
 
 err:
#5 lore raw

PATCH v2 2/3 gpio: davinci: Handle the return value of davinci_gpio_irq_setup function

Quoted 9 lines · Keerthy
Quoted 2 lines · Keerthy

Currently davinci_gpio_irq_setup return value is ignored. Handle the return value appropriately.

Linus,

Any comments on this? Sorry if i pinged too soon. The rest 2 of this series were pulled by you. So just wanted to check on this one if you had specific comments.

I got the impression you would send this in a series with a new patch requested by Johan.

Do we have consensus that this patch should be applied as-is?

Yours,
Linus Walleij

author maintainer
#6 lore raw

PATCH v2 2/3 gpio: davinci: Handle the return value of davinci_gpio_irq_setup function

Quoted 7 lines · Linus Walleij
Quoted 6 lines · Keerthy
Quoted 2 lines · Keerthy

Currently davinci_gpio_irq_setup return value is ignored. Handle the return value appropriately.

Linus,

Quoted 8 lines
Quoted 3 lines

Any comments on this? Sorry if i pinged too soon. The rest 2 of this series were pulled by you. So just wanted to check on this one if you had specific comments.

I got the impression you would send this in a series with a new patch requested by Johan.

Do we have consensus that this patch should be applied as-is?

IIUC a separate patch is needed to implement remove function. This can still be independent of that.

https://www.mail-archive.com/linux-kernel at vger.kernel.org/msg1450395.html

Quoted 4 lines

Yours,
Linus Walleij

#7 lore raw

PATCH v2 2/3 gpio: davinci: Handle the return value of davinci_gpio_irq_setup function

In reply to Keerthy
Quoted 4 lines · Keerthy

Currently davinci_gpio_irq_setup return value is ignored. Handle the return value appropriately.

Patch applied.

Yours,
Linus Walleij

author maintainer
#8 lore raw

PATCH v2 3/3 gpio: davinci: Convert prinkt to dev_err

In reply to Keerthy

In case of devm_clk_get failure use dev_err instead of printk

---
 drivers/gpio/gpio-davinci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-davinci.c +1 -2
index d6fb1ce..f75d844 100644
@@ -490,8 +490,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 
 	clk = devm_clk_get(dev, "gpio");
 	if (IS_ERR(clk)) {
-		printk(KERN_ERR "Error %ld getting gpio clock?\n",
-		       PTR_ERR(clk));
+		dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk));
 		return PTR_ERR(clk);
 	}
 	ret = clk_prepare_enable(clk);
Signature · 1 line
1.9.1
#9 lore raw

PATCH v2 3/3 gpio: davinci: Convert prinkt to dev_err

Quoted 3 lines · Keerthy

In case of devm_clk_get failure use dev_err instead of printk

Patch applied.

Yours,
Linus Walleij

author maintainer
#10 lore raw

v2 cover gpio: davinci: Add missing return checks

In reply to Keerthy
Quoted 8 lines · Keerthy

The patch series does a couple of important return handling which were missed earlier in the driver probe.

This is based on Suman's:

http://marc.info/?l=linux-arm-kernel&m=150034845427555&w=2
http://marc.info/?l=linux-arm-kernel&m=150034856627618&w=2

My bad! The series has no dependency on the above. I have split the device tree patches to keep it independent.

Quoted 14 lines

Changes in v2:

* Removed the device tree patch for to keep the series independent.

Keerthy (3):
gpio: davinci: Use devm_gpiochip_add_data in place of
gpiochip_add_data
gpio: davinci: Handle the return value of davinci_gpio_irq_setup
function
gpio: davinci: Convert prinkt to dev_err

 drivers/gpio/gpio-davinci.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
#11 lore raw

v2 cover gpio: davinci: Add missing return checks

Hi Keerthy,

Quoted 13 lines · Keerthy
Quoted 8 lines

The patch series does a couple of important return handling which were missed earlier in the driver probe.

This is based on Suman's:

http://marc.info/?l=linux-arm-kernel&m=150034845427555&w=2
http://marc.info/?l=linux-arm-kernel&m=150034856627618&w=2

My bad! The series has no dependency on the above. I have split the device tree patches to keep it independent.

The new patches looks clean. The davinci_gpio_irq_setup() function though could also do with couple more cleanups. Not all failure paths are doing the necessary cleanup (there are some non devres functions also called, but not cleaned up).

regards
Suman

Quoted 15 lines
Quoted 15 lines

Changes in v2:

* Removed the device tree patch for to keep the series independent.

Keerthy (3):
gpio: davinci: Use devm_gpiochip_add_data in place of
gpiochip_add_data
gpio: davinci: Handle the return value of davinci_gpio_irq_setup
function
gpio: davinci: Convert prinkt to dev_err

 drivers/gpio/gpio-davinci.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
author maintainer
#12 lore raw

v2 cover gpio: davinci: Add missing return checks

Quoted 13 lines · Suman Anna

Hi Keerthy,

Quoted 11 lines · Keerthy
Quoted 8 lines

The patch series does a couple of important return handling which were missed earlier in the driver probe.

This is based on Suman's:

http://marc.info/?l=linux-arm-kernel&m=150034845427555&w=2
http://marc.info/?l=linux-arm-kernel&m=150034856627618&w=2

Quoted 7 lines
Quoted 2 lines

My bad! The series has no dependency on the above. I have split the device tree patches to keep it independent.

The new patches looks clean. The davinci_gpio_irq_setup() function though could also do with couple more cleanups. Not all failure paths are doing the necessary cleanup (there are some non devres functions also called, but not cleaned up).

Linus,

Any comments on this series?

Regards,
Keerthy

Quoted 20 lines

regards
Suman

Quoted 15 lines
Quoted 15 lines

Changes in v2:

* Removed the device tree patch for to keep the series independent.

Keerthy (3):
gpio: davinci: Use devm_gpiochip_add_data in place of
gpiochip_add_data
gpio: davinci: Handle the return value of davinci_gpio_irq_setup
function
gpio: davinci: Convert prinkt to dev_err

 drivers/gpio/gpio-davinci.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)