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

Input: powermate - use guard notation when acquiring 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/20240904044902.1049017-1-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+2 -9
+2 -9
drivers/input/misc/powermate.c
··· 194 194 static void powermate_config_complete(struct urb *urb) 195 195 { 196 196 struct powermate_device *pm = urb->context; 197 - unsigned long flags; 198 197 199 198 if (urb->status) 200 199 printk(KERN_ERR "powermate: config urb returned %d\n", urb->status); 201 200 202 - spin_lock_irqsave(&pm->lock, flags); 201 + guard(spinlock_irqsave)(&pm->lock); 203 202 powermate_sync_state(pm); 204 - spin_unlock_irqrestore(&pm->lock, flags); 205 203 } 206 204 207 205 /* Set the LED up as described and begin the sync with the hardware if required */ 208 206 static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed, 209 207 int pulse_table, int pulse_asleep, int pulse_awake) 210 208 { 211 - unsigned long flags; 212 - 213 209 if (pulse_speed < 0) 214 210 pulse_speed = 0; 215 211 if (pulse_table < 0) ··· 218 222 pulse_asleep = !!pulse_asleep; 219 223 pulse_awake = !!pulse_awake; 220 224 221 - 222 - spin_lock_irqsave(&pm->lock, flags); 225 + guard(spinlock_irqsave)(&pm->lock); 223 226 224 227 /* mark state updates which are required */ 225 228 if (static_brightness != pm->static_brightness) { ··· 240 245 } 241 246 242 247 powermate_sync_state(pm); 243 - 244 - spin_unlock_irqrestore(&pm->lock, flags); 245 248 } 246 249 247 250 /* Callback from the Input layer when an event arrives from userspace to configure the LED */