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: ad7879 - use guard notation when acquiring mutexes

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

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+15 -31
+15 -31
drivers/input/touchscreen/ad7879.c
··· 305 305 { 306 306 struct ad7879 *ts = dev_get_drvdata(dev); 307 307 308 - mutex_lock(&ts->input->mutex); 308 + guard(mutex)(&ts->input->mutex); 309 309 310 310 if (!ts->suspended && !ts->disabled && input_device_enabled(ts->input)) 311 311 __ad7879_disable(ts); 312 312 313 313 ts->suspended = true; 314 - 315 - mutex_unlock(&ts->input->mutex); 316 314 317 315 return 0; 318 316 } ··· 319 321 { 320 322 struct ad7879 *ts = dev_get_drvdata(dev); 321 323 322 - mutex_lock(&ts->input->mutex); 324 + guard(mutex)(&ts->input->mutex); 323 325 324 326 if (ts->suspended && !ts->disabled && input_device_enabled(ts->input)) 325 327 __ad7879_enable(ts); 326 328 327 329 ts->suspended = false; 328 - 329 - mutex_unlock(&ts->input->mutex); 330 330 331 331 return 0; 332 332 } ··· 334 338 335 339 static void ad7879_toggle(struct ad7879 *ts, bool disable) 336 340 { 337 - mutex_lock(&ts->input->mutex); 341 + guard(mutex)(&ts->input->mutex); 338 342 339 343 if (!ts->suspended && input_device_enabled(ts->input)) { 340 344 ··· 348 352 } 349 353 350 354 ts->disabled = disable; 351 - 352 - mutex_unlock(&ts->input->mutex); 353 355 } 354 356 355 357 static ssize_t ad7879_disable_show(struct device *dev, ··· 397 403 unsigned gpio) 398 404 { 399 405 struct ad7879 *ts = gpiochip_get_data(chip); 400 - int err; 401 406 402 - mutex_lock(&ts->mutex); 407 + guard(mutex)(&ts->mutex); 408 + 403 409 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; 404 - err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 405 - mutex_unlock(&ts->mutex); 406 - 407 - return err; 410 + return ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 408 411 } 409 412 410 413 static int ad7879_gpio_direction_output(struct gpio_chip *chip, 411 414 unsigned gpio, int level) 412 415 { 413 416 struct ad7879 *ts = gpiochip_get_data(chip); 414 - int err; 415 417 416 - mutex_lock(&ts->mutex); 418 + guard(mutex)(&ts->mutex); 419 + 417 420 ts->cmd_crtl2 &= ~AD7879_GPIODIR; 418 421 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL; 419 422 if (level) ··· 418 427 else 419 428 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; 420 429 421 - err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 422 - mutex_unlock(&ts->mutex); 423 - 424 - return err; 430 + return ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 425 431 } 426 432 427 - static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 433 + static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned int gpio) 428 434 { 429 435 struct ad7879 *ts = gpiochip_get_data(chip); 430 436 u16 val; 431 437 432 - mutex_lock(&ts->mutex); 433 - val = ad7879_read(ts, AD7879_REG_CTRL2); 434 - mutex_unlock(&ts->mutex); 438 + guard(mutex)(&ts->mutex); 435 439 440 + val = ad7879_read(ts, AD7879_REG_CTRL2); 436 441 return !!(val & AD7879_GPIO_DATA); 437 442 } 438 443 ··· 436 449 int value) 437 450 { 438 451 struct ad7879 *ts = gpiochip_get_data(chip); 439 - int ret; 440 452 441 - mutex_lock(&ts->mutex); 453 + guard(mutex)(&ts->mutex); 454 + 442 455 if (value) 443 456 ts->cmd_crtl2 |= AD7879_GPIO_DATA; 444 457 else 445 458 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; 446 459 447 - ret = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 448 - mutex_unlock(&ts->mutex); 449 - 450 - return ret; 460 + return ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 451 461 } 452 462 453 463 static int ad7879_gpio_add(struct ad7879 *ts)