mux: gpio: Use bitmap API instead of direct assignment
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 30 Mar 2021 19:33:23 +0000 (22:33 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 Apr 2021 14:28:53 +0000 (16:28 +0200)
Assigning bitmaps like it's done in the driver might be error prone.
Fix this by using bitmap API.

Acked-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20210330193325.68362-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mux/gpio.c

index 02c1f2c014e8bf9116df68b26fc08cca612669c1..d1b4aa9236574645fa0894254e1c45d4dd41bd27 100644 (file)
@@ -7,6 +7,7 @@
  * Author: Peter Rosin <peda@axentia.se>
  */
 
+#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) {