mux: gpio: Use bitmap API instead of direct assignment
PATCH 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.
--- drivers/mux/gpio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/mux/gpio.c +4 -3
@@ -6,7 +6,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 +23,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 +72,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
PATCH 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.
--- drivers/mux/gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mux/gpio.c +2 -2
@@ -10,8 +10,8 @@#include <linux/err.h> #include <linux/gpio/consumer.h> #include <linux/module.h> +#include <linux/mod_devicetable.h> #include <linux/mux/driver.h> -#include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/property.h>
@@ -97,7 +97,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
Re: [PATCH v1 2/3] mux: gpio: Make it OF independent
Hi!
Quoted 13 lines · Andy Shevchenko
Module doesn't use OF APIs anyhow, make it OF independent by replacing headers and dropping useless
of_match_ptr()call.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mux/gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/mux/gpio.c +0
-0
drivers/mux/gpio.c line 13
Quoted 4 lines
drivers/mux/gpio.c +1
-0@@ -10,8 +10,8 @@#include <linux/err.h> #include <linux/gpio/consumer.h> #include <linux/module.h> +#include <linux/mod_devicetable.h>
mod_devicetable.h sorts before module.h. With that changed,
Cheers,
Peter
Quoted 15 lines
drivers/mux/gpio.c +1
-2#include <linux/mux/driver.h> -#include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/property.h> @@ -97,7 +97,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, };
PATCH 3/3 mux: gpio: Simplify code by using dev_err_probe()
In reply to Andy ShevchenkoUse already prepared dev_err_probe() introduced by the commit a787e5400a1c ("driver core: add device probe log helper"). It simplifies EPROBE_DEFER handling.
--- drivers/mux/gpio.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/mux/gpio.c +2 -6
@@ -65,12 +65,8 @@ 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
Re: [PATCH v1 3/3] mux: gpio: Simplify code by using dev_err_probe()
Hi!
Quoted 15 lines · Andy Shevchenko
Use already prepared
dev_err_probe()introduced by the commita787e5400a1c("driver core: add device probe log helper"). It simplifiesEPROBE_DEFERhandling.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mux/gpio.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/mux/gpio.c +0
-0@@ -65,12 +65,8 @@ static int mux_gpio_probe(struct platform_device *pdev) mux_chip->ops = &mux_gpio_ops;
drivers/mux/gpio.c static int mux_gpio_probe(struct platform_device *pdev) · line 69
Quoted 10 lines
drivers/mux/gpio.c +2
-6mux_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" );
Please break this line, keeping it as one line does not significantly increase readability. I know many people think long lines are super nice, but I'm not sold and am stubbornly sticking to 80 cols. I'd rater have room for one more window instead of wasting loads of screen on mostly short lines and a long one here and there. Sorry to be a pest, but coding-style.rst agrees with me:
"The preferred limit on the length of a single line is 80 columns."
So, with that changed,
Cheers,
Peter
Quoted 4 lines
drivers/mux/gpio.c +0
-0WARN_ON (pins != mux_gpio->gpios->ndescs); mux_chip->mux->states =BIT (pins);
Quoted 2 lines · Andy Shevchenko
Assigning bitmaps like it's done in the driver might be error prone. Fix this by using bitmap API.
Peter, are you okay with the patches?
Should I reroute them to Greg?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi!
Quoted 2 lines · Andy Shevchenko
Assigning bitmaps like it's done in the driver might be error prone. Fix this by using bitmap API.
A bit strongly worded perhaps, since the size of a mux chip with anywhere near 31 inputs and 2^31 possible selections is a bit ridiculous. Please send a photo of that HW if someone is producing one :-)
But there's always the someone-borrows-code-factor, so I guess it's fine as-is.
Quoted 10 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mux/gpio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/mux/gpio.c +0
-0
drivers/mux/gpio.c line 9
Quoted 4 lines
drivers/mux/gpio.c +0
-1@@ -6,7 +6,7 @@* * Author: Peter Rosin <[email protected]> */ -
Nit, please keep the empty line here. With that,
And please send directly to Greg, that would be excellent, thanks!
Cheers,
Peter
Quoted 25 lines
drivers/mux/gpio.c +4
-2+#include <linux/bitmap.h> #include <linux/err.h> #include <linux/gpio/consumer.h> #include <linux/module.h> @@ -23,8 +23,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 +72,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 ) {