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: imx_keypad - use guard notation when acquiring mutex

This makes the code more compact and error handling more robust
by ensuring that mutexes are released in all code paths when control
leaves critical section.

Link: https://lore.kernel.org/r/20240825051627.2848495-7-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+11 -16
+11 -16
drivers/input/keyboard/imx_keypad.c
··· 521 521 struct input_dev *input_dev = kbd->input_dev; 522 522 unsigned short reg_val = readw(kbd->mmio_base + KPSR); 523 523 524 - /* imx kbd can wake up system even clock is disabled */ 525 - mutex_lock(&input_dev->mutex); 526 - 527 - if (input_device_enabled(input_dev)) 528 - clk_disable_unprepare(kbd->clk); 529 - 530 - mutex_unlock(&input_dev->mutex); 524 + scoped_guard(mutex, &input_dev->mutex) { 525 + /* imx kbd can wake up system even clock is disabled */ 526 + if (input_device_enabled(input_dev)) 527 + clk_disable_unprepare(kbd->clk); 528 + } 531 529 532 530 if (device_may_wakeup(&pdev->dev)) { 533 531 if (reg_val & KBD_STAT_KPKD) ··· 545 547 struct platform_device *pdev = to_platform_device(dev); 546 548 struct imx_keypad *kbd = platform_get_drvdata(pdev); 547 549 struct input_dev *input_dev = kbd->input_dev; 548 - int ret = 0; 550 + int error; 549 551 550 552 if (device_may_wakeup(&pdev->dev)) 551 553 disable_irq_wake(kbd->irq); 552 554 553 - mutex_lock(&input_dev->mutex); 555 + guard(mutex)(&input_dev->mutex); 554 556 555 557 if (input_device_enabled(input_dev)) { 556 - ret = clk_prepare_enable(kbd->clk); 557 - if (ret) 558 - goto err_clk; 558 + error = clk_prepare_enable(kbd->clk); 559 + if (error) 560 + return error; 559 561 } 560 562 561 - err_clk: 562 - mutex_unlock(&input_dev->mutex); 563 - 564 - return ret; 563 + return 0; 565 564 } 566 565 567 566 static const struct dev_pm_ops imx_kbd_pm_ops = {