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.

ALSA: ac97bus: Use guard() for mutex locks

Replace the manual mutex lock/unlock pairs with guard() for code
simplification.

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829151335.7342-18-tiwai@suse.de

+9 -13
+9 -13
sound/ac97/bus.c
··· 241 241 { 242 242 struct ac97_controller *ac97_ctrl; 243 243 244 - mutex_lock(&ac97_controllers_mutex); 244 + guard(mutex)(&ac97_controllers_mutex); 245 245 ac97_ctrl = to_ac97_controller(dev); 246 246 ac97_ctrl->ops->reset(ac97_ctrl); 247 - mutex_unlock(&ac97_controllers_mutex); 248 247 return len; 249 248 } 250 249 static DEVICE_ATTR_WO(cold_reset); ··· 257 258 if (!dev) 258 259 return -ENODEV; 259 260 260 - mutex_lock(&ac97_controllers_mutex); 261 + guard(mutex)(&ac97_controllers_mutex); 261 262 ac97_ctrl = to_ac97_controller(dev); 262 263 ac97_ctrl->ops->warm_reset(ac97_ctrl); 263 - mutex_unlock(&ac97_controllers_mutex); 264 264 return len; 265 265 } 266 266 static DEVICE_ATTR_WO(warm_reset); ··· 282 284 283 285 static void ac97_del_adapter(struct ac97_controller *ac97_ctrl) 284 286 { 285 - mutex_lock(&ac97_controllers_mutex); 286 - ac97_ctrl_codecs_unregister(ac97_ctrl); 287 - list_del(&ac97_ctrl->controllers); 288 - mutex_unlock(&ac97_controllers_mutex); 287 + scoped_guard(mutex, &ac97_controllers_mutex) { 288 + ac97_ctrl_codecs_unregister(ac97_ctrl); 289 + list_del(&ac97_ctrl->controllers); 290 + } 289 291 290 292 device_unregister(&ac97_ctrl->adap); 291 293 } ··· 309 311 { 310 312 int ret; 311 313 312 - mutex_lock(&ac97_controllers_mutex); 314 + guard(mutex)(&ac97_controllers_mutex); 313 315 ret = idr_alloc(&ac97_adapter_idr, ac97_ctrl, 0, 0, GFP_KERNEL); 314 316 ac97_ctrl->nr = ret; 315 317 if (ret >= 0) { ··· 320 322 if (ret) 321 323 put_device(&ac97_ctrl->adap); 322 324 } 323 - if (!ret) 325 + if (!ret) { 324 326 list_add(&ac97_ctrl->controllers, &ac97_controllers); 325 - mutex_unlock(&ac97_controllers_mutex); 326 - 327 - if (!ret) 328 327 dev_dbg(&ac97_ctrl->adap, "adapter registered by %s\n", 329 328 dev_name(ac97_ctrl->parent)); 329 + } 330 330 return ret; 331 331 } 332 332