thermal: core: Clean up thermal_list_lock locking
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 22 Mar 2023 19:34:12 +0000 (20:34 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 3 Apr 2023 18:40:21 +0000 (20:40 +0200)
Once thermal_list_lock has been acquired in
__thermal_cooling_device_register(), it is not necessary to drop it
and take it again until all of the thermal zones have been updated,
so change the code accordingly.

No expected functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/thermal/thermal_core.c

index 9cb0a78636e3a64b2a7b0ce3eca3b58fa76497db..94765b00839332ee81b7ab0fcd01c87744aceb6c 100644 (file)
@@ -826,8 +826,6 @@ static void bind_cdev(struct thermal_cooling_device *cdev)
        const struct thermal_zone_params *tzp;
        struct thermal_zone_device *pos = NULL;
 
-       mutex_lock(&thermal_list_lock);
-
        list_for_each_entry(pos, &thermal_tz_list, node) {
                if (!pos->tzp && !pos->ops->bind)
                        continue;
@@ -854,8 +852,6 @@ static void bind_cdev(struct thermal_cooling_device *cdev)
                               tzp->tbp[i].weight);
                }
        }
-
-       mutex_unlock(&thermal_list_lock);
 }
 
 /**
@@ -933,17 +929,17 @@ __thermal_cooling_device_register(struct device_node *np,
 
        /* Add 'this' new cdev to the global cdev list */
        mutex_lock(&thermal_list_lock);
+
        list_add(&cdev->node, &thermal_cdev_list);
-       mutex_unlock(&thermal_list_lock);
 
        /* Update binding information for 'this' new cdev */
        bind_cdev(cdev);
 
-       mutex_lock(&thermal_list_lock);
        list_for_each_entry(pos, &thermal_tz_list, node)
                if (atomic_cmpxchg(&pos->need_update, 1, 0))
                        thermal_zone_device_update(pos,
                                                   THERMAL_EVENT_UNSPECIFIED);
+
        mutex_unlock(&thermal_list_lock);
 
        return cdev;