Skip to contentSkip to conversation

gpio: mpc8xxx: Fixup setting gpio direction output

PATCH Superseded Axel Lin 3 participants 3 messages Feb 11, 2016 – Feb 19, 2016 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 gpio: mpc8xxx: Fixup setting gpio direction output

For devtype with specific gpio_dir_out implementation, current code looks wrong because below code sets both gc->direction_output and mpc8xxx_gc->direction_output to the same function.

gc->direction_output = devtype->gpio_dir_out ?: gc->direction_output; mpc8xxx_gc->direction_output = gc->direction_output;

Set mpc8xxx_gc->direction_output = gc->direction_output first to fix it. This way mpc8xxx_gc->direction_output actually calls the standard bgpio_dir_out() to update register.

Setting gc->direction_output to gc->direction_output looks strange. This patch also slightly changes the code for better readability.

Fixes commit 42178e2a1e42 ("drivers/gpio: Switch gpio-mpc8xxx to use gpio-generic")

---
Hi,
I don't have this h/w, please review and test if this patch works. Thank,
Axel

 drivers/gpio/gpio-mpc8xxx.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpio/gpio-mpc8xxx.c +7 -4
index ecdb27a..0ed279a 100644
@@ -344,11 +344,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 	 */
 	mpc8xxx_irq_chip.irq_set_type = devtype->irq_set_type;
 
-	gc->direction_output = devtype->gpio_dir_out ?: gc->direction_output;
-	gc->get = devtype->gpio_get ?: gc->get;
-	gc->to_irq = mpc8xxx_gpio_to_irq;
-
 	mpc8xxx_gc->direction_output = gc->direction_output;
+	if (devtype->gpio_dir_out)
+		gc->direction_output = devtype->gpio_dir_out;
+
+	if (devtype->gpio_get)
+		gc->get = devtype->gpio_get;
+
+	gc->to_irq = mpc8xxx_gpio_to_irq;
 
 	ret = gpiochip_add_data(gc, mpc8xxx_gc);
 	if (ret) {
Signature · 1 line
2.1.4
#1 lore raw
Quoted 11 lines · Axel Lin

For devtype with specific gpio_dir_out implementation, current code looks wrong because below code sets both gc->direction_output and mpc8xxx_gc->direction_output to the same function.

gc->direction_output = devtype->gpio_dir_out ?: gc->direction_output; mpc8xxx_gc->direction_output = gc->direction_output;

Set mpc8xxx_gc->direction_output = gc->direction_output first to fix it. This way mpc8xxx_gc->direction_output actually calls the standard bgpio_dir_out() to update register.

Quoted 5 lines

Setting gc->direction_output to gc->direction_output looks strange. This patch also slightly changes the code for better readability.

Fixes commit 42178e2a1e42 ("drivers/gpio: Switch gpio-mpc8xxx to use gpio-generic")

Liu please comment on this patch.

Yours,
Linus Walleij

#2 lore raw
In reply to Axel Lin

Hi, Axel,

Yes you are right.

Maybe we can make the change just like this:

+	mpc8xxx_gc->direction_output = gc->direction_output;
	gc->direction_output = devtype->gpio_dir_out ?: gc->direction_output;
	gc->get = devtype->gpio_get ?: gc->get;
	gc->to_irq = mpc8xxx_gpio_to_irq;

- mpc8xxx_gc->direction_output = gc->direction_output;

Best Regards,
Liu Gang
-----Original Message-----
---
Hi,
I don't have this h/w, please review and test if this patch works. Thank,
Axel

 drivers/gpio/gpio-mpc8xxx.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpio/gpio-mpc8xxx.c +7 -4
@@ -344,11 +344,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 	 */
 	mpc8xxx_irq_chip.irq_set_type = devtype->irq_set_type;
 
-	gc->direction_output = devtype->gpio_dir_out ?: gc->direction_output;
-	gc->get = devtype->gpio_get ?: gc->get;
-	gc->to_irq = mpc8xxx_gpio_to_irq;
-
 	mpc8xxx_gc->direction_output = gc->direction_output;
+	if (devtype->gpio_dir_out)
+		gc->direction_output = devtype->gpio_dir_out;
+
+	if (devtype->gpio_get)
+		gc->get = devtype->gpio_get;
+
+	gc->to_irq = mpc8xxx_gpio_to_irq;
 
 	ret = gpiochip_add_data(gc, mpc8xxx_gc);
 	if (ret) {

--
2.1.4