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

Using guard notation 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.

Reviewed-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240904044244.1042174-8-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+24 -26
+24 -26
drivers/input/misc/drv260x.c
··· 537 537 static int drv260x_suspend(struct device *dev) 538 538 { 539 539 struct drv260x_data *haptics = dev_get_drvdata(dev); 540 - int ret = 0; 540 + int error; 541 541 542 - mutex_lock(&haptics->input_dev->mutex); 542 + guard(mutex)(&haptics->input_dev->mutex); 543 543 544 544 if (input_device_enabled(haptics->input_dev)) { 545 - ret = regmap_update_bits(haptics->regmap, 546 - DRV260X_MODE, 547 - DRV260X_STANDBY_MASK, 548 - DRV260X_STANDBY); 549 - if (ret) { 545 + error = regmap_update_bits(haptics->regmap, 546 + DRV260X_MODE, 547 + DRV260X_STANDBY_MASK, 548 + DRV260X_STANDBY); 549 + if (error) { 550 550 dev_err(dev, "Failed to set standby mode\n"); 551 - goto out; 551 + return error; 552 552 } 553 553 554 554 gpiod_set_value(haptics->enable_gpio, 0); 555 555 556 - ret = regulator_disable(haptics->regulator); 557 - if (ret) { 556 + error = regulator_disable(haptics->regulator); 557 + if (error) { 558 558 dev_err(dev, "Failed to disable regulator\n"); 559 559 regmap_update_bits(haptics->regmap, 560 560 DRV260X_MODE, 561 561 DRV260X_STANDBY_MASK, 0); 562 + return error; 562 563 } 563 564 } 564 - out: 565 - mutex_unlock(&haptics->input_dev->mutex); 566 - return ret; 565 + 566 + return 0; 567 567 } 568 568 569 569 static int drv260x_resume(struct device *dev) 570 570 { 571 571 struct drv260x_data *haptics = dev_get_drvdata(dev); 572 - int ret = 0; 572 + int error; 573 573 574 - mutex_lock(&haptics->input_dev->mutex); 574 + guard(mutex)(&haptics->input_dev->mutex); 575 575 576 576 if (input_device_enabled(haptics->input_dev)) { 577 - ret = regulator_enable(haptics->regulator); 578 - if (ret) { 577 + error = regulator_enable(haptics->regulator); 578 + if (error) { 579 579 dev_err(dev, "Failed to enable regulator\n"); 580 - goto out; 580 + return error; 581 581 } 582 582 583 - ret = regmap_update_bits(haptics->regmap, 584 - DRV260X_MODE, 585 - DRV260X_STANDBY_MASK, 0); 586 - if (ret) { 583 + error = regmap_update_bits(haptics->regmap, 584 + DRV260X_MODE, 585 + DRV260X_STANDBY_MASK, 0); 586 + if (error) { 587 587 dev_err(dev, "Failed to unset standby mode\n"); 588 588 regulator_disable(haptics->regulator); 589 - goto out; 589 + return error; 590 590 } 591 591 592 592 gpiod_set_value(haptics->enable_gpio, 1); 593 593 } 594 594 595 - out: 596 - mutex_unlock(&haptics->input_dev->mutex); 597 - return ret; 595 + return 0; 598 596 } 599 597 600 598 static DEFINE_SIMPLE_DEV_PM_OPS(drv260x_pm_ops, drv260x_suspend, drv260x_resume);