Skip to contentSkip to conversation

mux: gpio: Use bitmap API instead of direct assignment

PATCH In review Andy Shevchenko 3 participants 5 messages Mar 30, 2021 – Apr 2, 2021 Multiplexer

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 mux: gpio: Use bitmap API instead of direct assignment

Assigning bitmaps like it's done in the driver might be error prone. Fix this by using bitmap API.

---
v2: left blank line untouched (Peter)

 drivers/mux/gpio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mux/gpio.c +4 -2
index 02c1f2c014e8..d1b4aa923657 100644
@@ -7,6 +7,7 @@
  * Author: Peter Rosin <[email protected]>
  */
 
+#include <linux/bitmap.h>
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
@@ -23,8 +24,9 @@ static int mux_gpio_set(struct mux_control *mux, int state)
 {
 	struct mux_gpio *mux_gpio = mux_chip_priv(mux->chip);
 	DECLARE_BITMAP(values, BITS_PER_TYPE(state));
+	u32 value = state;
 
-	values[0] = state;
+	bitmap_from_arr32(values, &value, BITS_PER_TYPE(value));
 
 	gpiod_set_array_value_cansleep(mux_gpio->gpios->ndescs,
 				       mux_gpio->gpios->desc,
@@ -71,7 +73,7 @@ static int mux_gpio_probe(struct platform_device *pdev)
 		return ret;
 	}
 	WARN_ON(pins != mux_gpio->gpios->ndescs);
-	mux_chip->mux->states = 1 << pins;
+	mux_chip->mux->states = BIT(pins);
 
 	ret = device_property_read_u32(dev, "idle-state", (u32 *)&idle_state);
 	if (ret >= 0 && idle_state != MUX_IDLE_AS_IS) {
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 2/3 mux: gpio: Make it OF independent

Module doesn't use OF APIs anyhow, make it OF independent by replacing headers and dropping useless of_match_ptr() call.

---
v2: moved mod_devicetable before module (Peter)

 drivers/mux/gpio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mux/gpio.c +2 -2
index d1b4aa923657..92cc476c916e 100644
@@ -10,9 +10,9 @@
 #include <linux/bitmap.h>
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/mux/driver.h>
-#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 
@@ -98,7 +98,7 @@ static int mux_gpio_probe(struct platform_device *pdev)
 static struct platform_driver mux_gpio_driver = {
 	.driver = {
 		.name = "gpio-mux",
-		.of_match_table	= of_match_ptr(mux_gpio_dt_ids),
+		.of_match_table	= mux_gpio_dt_ids,
 	},
 	.probe = mux_gpio_probe,
 };
Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 3/3 mux: gpio: Simplify code by using dev_err_probe()

In reply to Andy Shevchenko

Use already prepared dev_err_probe() introduced by the commit a787e5400a1c ("driver core: add device probe log helper"). It simplifies EPROBE_DEFER handling.

---
v2: wrapped to 80 characters (Peter)

 drivers/mux/gpio.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/mux/gpio.c +3 -6
index 92cc476c916e..cc5f2c1861d4 100644
@@ -66,12 +66,9 @@ static int mux_gpio_probe(struct platform_device *pdev)
 	mux_chip->ops = &mux_gpio_ops;
 
 	mux_gpio->gpios = devm_gpiod_get_array(dev, "mux", GPIOD_OUT_LOW);
-	if (IS_ERR(mux_gpio->gpios)) {
-		ret = PTR_ERR(mux_gpio->gpios);
-		if (ret != -EPROBE_DEFER)
-			dev_err(dev, "failed to get gpios\n");
-		return ret;
-	}
+	if (IS_ERR(mux_gpio->gpios))
+		return dev_err_probe(dev, PTR_ERR(mux_gpio->gpios),
+				     "failed to get gpios\n");
 	WARN_ON(pins != mux_gpio->gpios->ndescs);
 	mux_chip->mux->states = BIT(pins);
 
Signature · 1 line
2.30.2
#3 lore raw
In reply to Andy Shevchenko

Hi Greg,

You can pick this series directly, right? I don't feel a compelling need to add the patches to -next before you take them since they are simple enough...

And drivers/mux is otherwise quiet, as usual.

Cheers,
Peter

Quoted 43 lines · Andy Shevchenko

Assigning bitmaps like it's done in the driver might be error prone. Fix this by using bitmap API.

---
v2: left blank line untouched (Peter)

 drivers/mux/gpio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mux/gpio.c +4 -2
index 02c1f2c014e8..d1b4aa923657 100644
@@ -7,6 +7,7 @@
  * Author: Peter Rosin <[email protected]>
  */
 
+#include <linux/bitmap.h>
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
@@ -23,8 +24,9 @@ static int mux_gpio_set(struct mux_control *mux, int state)
 {
 	struct mux_gpio *mux_gpio = mux_chip_priv(mux->chip);
 	DECLARE_BITMAP(values, BITS_PER_TYPE(state));
+	u32 value = state;
 
-	values[0] = state;
+	bitmap_from_arr32(values, &value, BITS_PER_TYPE(value));
 
 	gpiod_set_array_value_cansleep(mux_gpio->gpios->ndescs,
 				       mux_gpio->gpios->desc,
@@ -71,7 +73,7 @@ static int mux_gpio_probe(struct platform_device *pdev)
 		return ret;
 	}
 	WARN_ON(pins != mux_gpio->gpios->ndescs);
-	mux_chip->mux->states = 1 << pins;
+	mux_chip->mux->states = BIT(pins);
 
 	ret = device_property_read_u32(dev, "idle-state", (u32 *)&idle_state);
 	if (ret >= 0 && idle_state != MUX_IDLE_AS_IS) {
#4 lore raw
Quoted 4 lines · Peter Rosin

Hi Greg,

You can pick this series directly, right? I don't feel a compelling need to add the patches to -next before you take them since they are simple enough...

All now sucked in, thanks.

greg k-h