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: st-keyscan - 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-17-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+10 -9
+10 -9
drivers/input/keyboard/st-keyscan.c
··· 216 216 struct st_keyscan *keypad = platform_get_drvdata(pdev); 217 217 struct input_dev *input = keypad->input_dev; 218 218 219 - mutex_lock(&input->mutex); 219 + guard(mutex)(&input->mutex); 220 220 221 221 if (device_may_wakeup(dev)) 222 222 enable_irq_wake(keypad->irq); 223 223 else if (input_device_enabled(input)) 224 224 keyscan_stop(keypad); 225 225 226 - mutex_unlock(&input->mutex); 227 226 return 0; 228 227 } 229 228 ··· 231 232 struct platform_device *pdev = to_platform_device(dev); 232 233 struct st_keyscan *keypad = platform_get_drvdata(pdev); 233 234 struct input_dev *input = keypad->input_dev; 234 - int retval = 0; 235 + int error; 235 236 236 - mutex_lock(&input->mutex); 237 + guard(mutex)(&input->mutex); 237 238 238 - if (device_may_wakeup(dev)) 239 + if (device_may_wakeup(dev)) { 239 240 disable_irq_wake(keypad->irq); 240 - else if (input_device_enabled(input)) 241 - retval = keyscan_start(keypad); 241 + } else if (input_device_enabled(input)) { 242 + error = keyscan_start(keypad); 243 + if (error) 244 + return error; 245 + } 242 246 243 - mutex_unlock(&input->mutex); 244 - return retval; 247 + return 0; 245 248 } 246 249 247 250 static DEFINE_SIMPLE_DEV_PM_OPS(keyscan_dev_pm_ops,