]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: ac97bus: Use guard() for mutex locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 15:13:31 +0000 (17:13 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:54:28 +0000 (13:54 +0200)
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
sound/ac97/bus.c

index 47c6787158a777c1ffb6e042587c6796ec1bf30b..f4254703d29f75e69798b4986b9b2471d858cf7b 100644 (file)
@@ -241,10 +241,9 @@ static ssize_t cold_reset_store(struct device *dev,
 {
        struct ac97_controller *ac97_ctrl;
 
-       mutex_lock(&ac97_controllers_mutex);
+       guard(mutex)(&ac97_controllers_mutex);
        ac97_ctrl = to_ac97_controller(dev);
        ac97_ctrl->ops->reset(ac97_ctrl);
-       mutex_unlock(&ac97_controllers_mutex);
        return len;
 }
 static DEVICE_ATTR_WO(cold_reset);
@@ -258,10 +257,9 @@ static ssize_t warm_reset_store(struct device *dev,
        if (!dev)
                return -ENODEV;
 
-       mutex_lock(&ac97_controllers_mutex);
+       guard(mutex)(&ac97_controllers_mutex);
        ac97_ctrl = to_ac97_controller(dev);
        ac97_ctrl->ops->warm_reset(ac97_ctrl);
-       mutex_unlock(&ac97_controllers_mutex);
        return len;
 }
 static DEVICE_ATTR_WO(warm_reset);
@@ -284,10 +282,10 @@ static const struct attribute_group *ac97_adapter_groups[] = {
 
 static void ac97_del_adapter(struct ac97_controller *ac97_ctrl)
 {
-       mutex_lock(&ac97_controllers_mutex);
-       ac97_ctrl_codecs_unregister(ac97_ctrl);
-       list_del(&ac97_ctrl->controllers);
-       mutex_unlock(&ac97_controllers_mutex);
+       scoped_guard(mutex, &ac97_controllers_mutex) {
+               ac97_ctrl_codecs_unregister(ac97_ctrl);
+               list_del(&ac97_ctrl->controllers);
+       }
 
        device_unregister(&ac97_ctrl->adap);
 }
@@ -311,7 +309,7 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
 {
        int ret;
 
-       mutex_lock(&ac97_controllers_mutex);
+       guard(mutex)(&ac97_controllers_mutex);
        ret = idr_alloc(&ac97_adapter_idr, ac97_ctrl, 0, 0, GFP_KERNEL);
        ac97_ctrl->nr = ret;
        if (ret >= 0) {
@@ -322,13 +320,11 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
                if (ret)
                        put_device(&ac97_ctrl->adap);
        }
-       if (!ret)
+       if (!ret) {
                list_add(&ac97_ctrl->controllers, &ac97_controllers);
-       mutex_unlock(&ac97_controllers_mutex);
-
-       if (!ret)
                dev_dbg(&ac97_ctrl->adap, "adapter registered by %s\n",
                        dev_name(ac97_ctrl->parent));
+       }
        return ret;
 }