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

Configure Feed

Select the types of activity you want to include in your feed.

Input: adp5588-keys - use guard notation when acquiring mutexes

This makes the code more compact and error handling more robust.

Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Link: https://lore.kernel.org/r/20240826-adp5588_gpio_support-v11-1-3e5ac2bd31b7@analog.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+17 -32
+17 -32
drivers/input/keyboard/adp5588-keys.c
··· 221 221 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 222 222 int val; 223 223 224 - mutex_lock(&kpad->gpio_lock); 224 + guard(mutex)(&kpad->gpio_lock); 225 225 226 226 if (kpad->dir[bank] & bit) 227 227 val = kpad->dat_out[bank]; 228 228 else 229 229 val = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank); 230 - 231 - mutex_unlock(&kpad->gpio_lock); 232 230 233 231 return !!(val & bit); 234 232 } ··· 238 240 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 239 241 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 240 242 241 - mutex_lock(&kpad->gpio_lock); 243 + guard(mutex)(&kpad->gpio_lock); 242 244 243 245 if (val) 244 246 kpad->dat_out[bank] |= bit; ··· 246 248 kpad->dat_out[bank] &= ~bit; 247 249 248 250 adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, kpad->dat_out[bank]); 249 - 250 - mutex_unlock(&kpad->gpio_lock); 251 251 } 252 252 253 253 static int adp5588_gpio_set_config(struct gpio_chip *chip, unsigned int off, ··· 255 259 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 256 260 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 257 261 bool pull_disable; 258 - int ret; 259 262 260 263 switch (pinconf_to_config_param(config)) { 261 264 case PIN_CONFIG_BIAS_PULL_UP: ··· 267 272 return -ENOTSUPP; 268 273 } 269 274 270 - mutex_lock(&kpad->gpio_lock); 275 + guard(mutex)(&kpad->gpio_lock); 271 276 272 277 if (pull_disable) 273 278 kpad->pull_dis[bank] |= bit; 274 279 else 275 280 kpad->pull_dis[bank] &= bit; 276 281 277 - ret = adp5588_write(kpad->client, GPIO_PULL1 + bank, 278 - kpad->pull_dis[bank]); 279 - 280 - mutex_unlock(&kpad->gpio_lock); 281 - 282 - return ret; 282 + return adp5588_write(kpad->client, GPIO_PULL1 + bank, 283 + kpad->pull_dis[bank]); 283 284 } 284 285 285 286 static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned int off) ··· 283 292 struct adp5588_kpad *kpad = gpiochip_get_data(chip); 284 293 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 285 294 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 286 - int ret; 287 295 288 - mutex_lock(&kpad->gpio_lock); 296 + guard(mutex)(&kpad->gpio_lock); 289 297 290 298 kpad->dir[bank] &= ~bit; 291 - ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 292 - 293 - mutex_unlock(&kpad->gpio_lock); 294 - 295 - return ret; 299 + return adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 296 300 } 297 301 298 302 static int adp5588_gpio_direction_output(struct gpio_chip *chip, ··· 296 310 struct adp5588_kpad *kpad = gpiochip_get_data(chip); 297 311 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 298 312 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 299 - int ret; 313 + int error; 300 314 301 - mutex_lock(&kpad->gpio_lock); 315 + guard(mutex)(&kpad->gpio_lock); 302 316 303 317 kpad->dir[bank] |= bit; 304 318 ··· 307 321 else 308 322 kpad->dat_out[bank] &= ~bit; 309 323 310 - ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, 311 - kpad->dat_out[bank]); 312 - if (ret) 313 - goto out_unlock; 324 + error = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, 325 + kpad->dat_out[bank]); 326 + if (error) 327 + return error; 314 328 315 - ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 329 + error = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 330 + if (error) 331 + return error; 316 332 317 - out_unlock: 318 - mutex_unlock(&kpad->gpio_lock); 319 - 320 - return ret; 333 + return 0; 321 334 } 322 335 323 336 static int adp5588_build_gpiomap(struct adp5588_kpad *kpad)