Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: latch: use value returning setters

struct gpio_chip now has additional variants of the set(_multiple)
driver callbacks that return an integer to indicate success or failure.
Convert the driver to using them.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/20250220-gpio-set-retval-v2-13-bc4cfd38dae3@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

+19 -14
+19 -14
drivers/gpio/gpio-latch.c
··· 73 73 return GPIO_LINE_DIRECTION_OUT; 74 74 } 75 75 76 - static void gpio_latch_set_unlocked(struct gpio_latch_priv *priv, 77 - int (*set)(struct gpio_desc *desc, int value), 78 - unsigned int offset, bool val) 76 + static int gpio_latch_set_unlocked(struct gpio_latch_priv *priv, 77 + int (*set)(struct gpio_desc *desc, int value), 78 + unsigned int offset, bool val) 79 79 { 80 - int latch = offset / priv->n_latched_gpios; 81 - int i; 80 + int latch = offset / priv->n_latched_gpios, i, ret; 82 81 83 82 assign_bit(offset, priv->shadow, val); 84 83 85 - for (i = 0; i < priv->n_latched_gpios; i++) 86 - set(priv->latched_gpios->desc[i], 87 - test_bit(latch * priv->n_latched_gpios + i, priv->shadow)); 84 + for (i = 0; i < priv->n_latched_gpios; i++) { 85 + ret = set(priv->latched_gpios->desc[i], 86 + test_bit(latch * priv->n_latched_gpios + i, 87 + priv->shadow)); 88 + if (ret) 89 + return ret; 90 + } 88 91 89 92 ndelay(priv->setup_duration_ns); 90 93 set(priv->clk_gpios->desc[latch], 1); 91 94 ndelay(priv->clock_duration_ns); 92 95 set(priv->clk_gpios->desc[latch], 0); 96 + 97 + return 0; 93 98 } 94 99 95 - static void gpio_latch_set(struct gpio_chip *gc, unsigned int offset, int val) 100 + static int gpio_latch_set(struct gpio_chip *gc, unsigned int offset, int val) 96 101 { 97 102 struct gpio_latch_priv *priv = gpiochip_get_data(gc); 98 103 99 104 guard(spinlock_irqsave)(&priv->spinlock); 100 105 101 - gpio_latch_set_unlocked(priv, gpiod_set_value, offset, val); 106 + return gpio_latch_set_unlocked(priv, gpiod_set_value, offset, val); 102 107 } 103 108 104 - static void gpio_latch_set_can_sleep(struct gpio_chip *gc, unsigned int offset, int val) 109 + static int gpio_latch_set_can_sleep(struct gpio_chip *gc, unsigned int offset, int val) 105 110 { 106 111 struct gpio_latch_priv *priv = gpiochip_get_data(gc); 107 112 108 113 guard(mutex)(&priv->mutex); 109 114 110 - gpio_latch_set_unlocked(priv, gpiod_set_value_cansleep, offset, val); 115 + return gpio_latch_set_unlocked(priv, gpiod_set_value_cansleep, offset, val); 111 116 } 112 117 113 118 static bool gpio_latch_can_sleep(struct gpio_latch_priv *priv, unsigned int n_latches) ··· 166 161 167 162 if (gpio_latch_can_sleep(priv, n_latches)) { 168 163 priv->gc.can_sleep = true; 169 - priv->gc.set = gpio_latch_set_can_sleep; 164 + priv->gc.set_rv = gpio_latch_set_can_sleep; 170 165 mutex_init(&priv->mutex); 171 166 } else { 172 167 priv->gc.can_sleep = false; 173 - priv->gc.set = gpio_latch_set; 168 + priv->gc.set_rv = gpio_latch_set; 174 169 spin_lock_init(&priv->spinlock); 175 170 } 176 171