lkml.org 
[lkml]   [2022]   [Oct]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 6/9] thermal/core: Protect hwmon accesses to thermal operations with thermal zone mutex
    Date
    In preparation to protecting access to thermal operations against thermal
    zone device removal, protect hwmon accesses to thermal zone operations
    with the thermal zone mutex. After acquiring the mutex, ensure that the
    thermal zone device is registered before proceeding.

    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    ---
    drivers/thermal/thermal_hwmon.c | 14 +++++++++++---
    1 file changed, 11 insertions(+), 3 deletions(-)

    diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
    index f53f4ceb6a5d..33bfbaed4236 100644
    --- a/drivers/thermal/thermal_hwmon.c
    +++ b/drivers/thermal/thermal_hwmon.c
    @@ -77,11 +77,19 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
    int temperature;
    int ret;

    + mutex_lock(&tz->lock);
    +
    + if (!device_is_registered(&tz->device)) {
    + ret = -ENODEV;
    + goto unlock;
    + }
    +
    ret = tz->ops->get_crit_temp(tz, &temperature);
    - if (ret)
    - return ret;

    - return sprintf(buf, "%d\n", temperature);
    +unlock:
    + mutex_unlock(&tz->lock);
    +
    + return ret ? ret : sprintf(buf, "%d\n", temperature);
    }


    --
    2.36.2
    \
     
     \ /
      Last update: 2022-10-17 15:11    [W:7.204 / U:0.024 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site