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

Input: lpc32xx-keys - 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-11-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+9 -9
+9 -9
drivers/input/keyboard/lpc32xx-keys.c
··· 262 262 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev); 263 263 struct input_dev *input = kscandat->input; 264 264 265 - mutex_lock(&input->mutex); 265 + guard(mutex)(&input->mutex); 266 266 267 267 if (input_device_enabled(input)) { 268 268 /* Clear IRQ and disable clock */ ··· 270 270 clk_disable_unprepare(kscandat->clk); 271 271 } 272 272 273 - mutex_unlock(&input->mutex); 274 273 return 0; 275 274 } 276 275 ··· 278 279 struct platform_device *pdev = to_platform_device(dev); 279 280 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev); 280 281 struct input_dev *input = kscandat->input; 281 - int retval = 0; 282 + int error; 282 283 283 - mutex_lock(&input->mutex); 284 + guard(mutex)(&input->mutex); 284 285 285 286 if (input_device_enabled(input)) { 286 287 /* Enable clock and clear IRQ */ 287 - retval = clk_prepare_enable(kscandat->clk); 288 - if (retval == 0) 289 - writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); 288 + error = clk_prepare_enable(kscandat->clk); 289 + if (error) 290 + return error; 291 + 292 + writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); 290 293 } 291 294 292 - mutex_unlock(&input->mutex); 293 - return retval; 295 + return 0; 294 296 } 295 297 296 298 static DEFINE_SIMPLE_DEV_PM_OPS(lpc32xx_kscan_pm_ops, lpc32xx_kscan_suspend,