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: da7280 - use guard notation when acquiring mutex and spinlock

Using guard notation makes the code more compact and error handling
more robust by ensuring that locks 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-6-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+12 -14
+12 -14
drivers/input/misc/da7280.c
··· 1263 1263 { 1264 1264 struct da7280_haptic *haptics = dev_get_drvdata(dev); 1265 1265 1266 - mutex_lock(&haptics->input_dev->mutex); 1266 + guard(mutex)(&haptics->input_dev->mutex); 1267 1267 1268 1268 /* 1269 1269 * Make sure no new requests will be submitted while device is 1270 1270 * suspended. 1271 1271 */ 1272 - spin_lock_irq(&haptics->input_dev->event_lock); 1273 - haptics->suspended = true; 1274 - spin_unlock_irq(&haptics->input_dev->event_lock); 1272 + scoped_guard(spinlock_irq, &haptics->input_dev->event_lock) { 1273 + haptics->suspended = true; 1274 + } 1275 1275 1276 1276 da7280_haptic_stop(haptics); 1277 - 1278 - mutex_unlock(&haptics->input_dev->mutex); 1279 1277 1280 1278 return 0; 1281 1279 } ··· 1281 1283 static int da7280_resume(struct device *dev) 1282 1284 { 1283 1285 struct da7280_haptic *haptics = dev_get_drvdata(dev); 1284 - int retval; 1286 + int error; 1285 1287 1286 - mutex_lock(&haptics->input_dev->mutex); 1288 + guard(mutex)(&haptics->input_dev->mutex); 1287 1289 1288 - retval = da7280_haptic_start(haptics); 1289 - if (!retval) { 1290 - spin_lock_irq(&haptics->input_dev->event_lock); 1290 + error = da7280_haptic_start(haptics); 1291 + if (error) 1292 + return error; 1293 + 1294 + scoped_guard(spinlock_irq, &haptics->input_dev->event_lock) { 1291 1295 haptics->suspended = false; 1292 - spin_unlock_irq(&haptics->input_dev->event_lock); 1293 1296 } 1294 1297 1295 - mutex_unlock(&haptics->input_dev->mutex); 1296 - return retval; 1298 + return 0; 1297 1299 } 1298 1300 1299 1301 #ifdef CONFIG_OF