thermal: Drop redundant and confusing device_is_registered() checks
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 8 Dec 2023 19:19:03 +0000 (20:19 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 12 Dec 2023 12:00:28 +0000 (13:00 +0100)
Multiple places in the thermal subsystem (most importantly, sysfs
attribute callback functions) check if the given thermal zone device is
still registered in order to return early in case the device_del() in
thermal_zone_device_unregister() has run already.

However, after thermal_zone_device_unregister() has been made wait for
all of the zone-related activity to complete before returning, it is
not necessary to do that any more, because all of the code holding a
reference to the thermal zone device object will be waited for even if
it does not do anything special to enforce this.

Accordingly, drop all of the device_is_registered() checks that are now
redundant and get rid of the zone locking that is not necessary any more
after dropping them.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-and-tested-by: Lukasz Luba <lukasz.luba@arm.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
drivers/thermal/thermal_core.c
drivers/thermal/thermal_helpers.c
drivers/thermal/thermal_hwmon.c
drivers/thermal/thermal_sysfs.c

index 70a294d121872500b4c6bbe26830e0baf35b1b7a..2cf6caff6784b076ef3a35e730084e3b1a567b44 100644 (file)
@@ -203,9 +203,6 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *tz,
        mutex_lock(&thermal_governor_lock);
        mutex_lock(&tz->lock);
 
-       if (!device_is_registered(&tz->device))
-               goto exit;
-
        gov = __find_governor(strim(policy));
        if (!gov)
                goto exit;
@@ -471,12 +468,6 @@ static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
                return ret;
        }
 
-       if (!device_is_registered(&tz->device)) {
-               mutex_unlock(&tz->lock);
-
-               return -ENODEV;
-       }
-
        if (tz->ops->change_mode)
                ret = tz->ops->change_mode(tz, mode);
 
index 69e8ea4aa908bdb33f093315a867e22efae9070a..d0afb623e475b21c632d1c3f8c61c73ed956312d 100644 (file)
@@ -139,10 +139,7 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
                goto unlock;
        }
 
-       if (device_is_registered(&tz->device))
-               ret = __thermal_zone_get_temp(tz, temp);
-       else
-               ret = -ENODEV;
+       ret = __thermal_zone_get_temp(tz, temp);
 
 unlock:
        mutex_unlock(&tz->lock);
index c3ae44659b8170fa10a656ede02f5e5407dc0e0f..252116f1e53541541037ec8766ecc2b44eee4c75 100644 (file)
@@ -80,10 +80,7 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
 
        mutex_lock(&tz->lock);
 
-       if (device_is_registered(&tz->device))
-               ret = tz->ops->get_crit_temp(tz, &temperature);
-       else
-               ret = -ENODEV;
+       ret = tz->ops->get_crit_temp(tz, &temperature);
 
        mutex_unlock(&tz->lock);
 
index 9e3d8fa01eea48aabe2894a9d2d9a3c2d76c8116..f52af8a3b4b523263ffc2add0ed0397bd85eb4aa 100644 (file)
@@ -83,24 +83,12 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
                     char *buf)
 {
        struct thermal_zone_device *tz = to_thermal_zone(dev);
-       enum thermal_trip_type type;
        int trip_id;
 
        if (sscanf(attr->attr.name, "trip_point_%d_type", &trip_id) != 1)
                return -EINVAL;
 
-       mutex_lock(&tz->lock);
-
-       if (!device_is_registered(dev)) {
-               mutex_unlock(&tz->lock);
-               return -ENODEV;
-       }
-
-       type = tz->trips[trip_id].type;
-
-       mutex_unlock(&tz->lock);
-
-       switch (type) {
+       switch (tz->trips[trip_id].type) {
        case THERMAL_TRIP_CRITICAL:
                return sprintf(buf, "critical\n");
        case THERMAL_TRIP_HOT:
@@ -132,11 +120,6 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
 
        mutex_lock(&tz->lock);
 
-       if (!device_is_registered(dev)) {
-               ret = -ENODEV;
-               goto unlock;
-       }
-
        trip = &tz->trips[trip_id];
 
        if (temp != trip->temperature) {
@@ -162,23 +145,12 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
                     char *buf)
 {
        struct thermal_zone_device *tz = to_thermal_zone(dev);
-       int trip_id, temp;
+       int trip_id;
 
        if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
                return -EINVAL;
 
-       mutex_lock(&tz->lock);
-
-       if (!device_is_registered(dev)) {
-               mutex_unlock(&tz->lock);
-               return -ENODEV;
-       }
-
-       temp = tz->trips[trip_id].temperature;
-
-       mutex_unlock(&tz->lock);
-
-       return sprintf(buf, "%d\n", temp);
+       return sprintf(buf, "%d\n", tz->trips[trip_id].temperature);
 }
 
 static ssize_t
@@ -199,11 +171,6 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
 
        mutex_lock(&tz->lock);
 
-       if (!device_is_registered(dev)) {
-               ret = -ENODEV;
-               goto unlock;
-       }
-
        trip = &tz->trips[trip_id];
 
        if (hyst != trip->hysteresis) {
@@ -229,23 +196,12 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
                     char *buf)
 {
        struct thermal_zone_device *tz = to_thermal_zone(dev);
-       int trip_id, hyst;
+       int trip_id;
 
        if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
                return -EINVAL;
 
-       mutex_lock(&tz->lock);
-
-       if (!device_is_registered(dev)) {
-               mutex_unlock(&tz->lock);
-               return -ENODEV;
-       }
-
-       hyst = tz->trips[trip_id].hysteresis;
-
-       mutex_unlock(&tz->lock);
-
-       return sprintf(buf, "%d\n", hyst);
+       return sprintf(buf, "%d\n", tz->trips[trip_id].hysteresis);
 }
 
 static ssize_t
@@ -294,11 +250,6 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
 
        mutex_lock(&tz->lock);
 
-       if (!device_is_registered(dev)) {
-               ret = -ENODEV;
-               goto unlock;
-       }
-
        if (!tz->ops->set_emul_temp)
                tz->emul_temperature = temperature;
        else
@@ -307,7 +258,6 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
        if (!ret)
                __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
 
-unlock:
        mutex_unlock(&tz->lock);
 
        return ret ? ret : count;