hwmon: (scmi) Check channel config allocation
Subsystems (2)
Sudeep Holla
maintainerPATCH 1/2 hwmon: (scmi) Check channel config allocation
scmi_hwmon_add_chan_info() can fail to allocate a channel's config array. Ignoring that error leaves a channel with a NULL config pointer in the hwmon chip info, which hwmon dereferences while registering the device.
Check the helper's return value and abort probe on failure.
--- drivers/hwmon/scmi-hwmon.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/hwmon/scmi-hwmon.c +7 -5
@@ -228,8 +228,8 @@ static int scmi_thermal_sensor_register(struct device *dev,static int scmi_hwmon_probe (struct scmi_device *sdev) { -int i, idx;u16 nr_sensors; +int i, idx, ret;enum hwmon_sensor_types type;struct scmi_sensors *scmi_sensors;const struct scmi_sensor_info *sensor;
@@ -297,8 +297,12 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)if (!nr_count[type])continue ; -scmi_hwmon_add_chan_info (scmi_hwmon_chan, dev, nr_count[type], - type, hwmon_attributes[type]); + ret =scmi_hwmon_add_chan_info (scmi_hwmon_chan, dev, + nr_count[type], type, + hwmon_attributes[type]); +if (ret) +return ret; + *ptr_scmi_ci++ = scmi_hwmon_chan++; scmi_sensors->info[type] =
@@ -333,8 +337,6 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)return PTR_ERR (hwdev);for (i =0 ; i < nr_count_temp; i++) { -int ret; - sensor = *(scmi_sensors->info[hwmon_temp] + i);if (!sensor)continue ;
Signature · 1 line
2.43.0
Sudeep Holla
maintainerPATCH 2/2 hwmon: (scmi) Configure sensors before exposing channels
SCMI hwmon enables sensors with SENSOR_CONFIG_SET, but only after registering the hwmon device and only for temperature sensors. This leaves other sensor classes disabled on firmware that defaults sensors to off, and exposes temperature channels before they are ready.
Configure each supported sensor while building the channel list, before registering the hwmon device. Leave failed sensors out of the list so their channels remain hidden, while continuing with other sensors.
--- drivers/hwmon/scmi-hwmon.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
Depends/rebased on https://lore.kernel.org/all/[email protected]
drivers/hwmon/scmi-hwmon.c +6 -7
@@ -325,6 +325,12 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)case ENERGY : type = scmi_types[sensor->type]; idx = --nr_count[type]; + ret = sensor_ops->config_set (ph, sensor->id, sensor_config); +if (ret) { +dev_err (dev,"Error enabling sensor %s. err=%d\n" , + sensor->name, ret); +continue ; + } *(scmi_sensors->info[type] + idx) = sensor;break ; }
@@ -341,13 +347,6 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)if (!sensor)continue ; - ret = sensor_ops->config_set (ph, sensor->id, sensor_config); -if (ret) { -dev_err (dev,"Error enabling sensor %s. err=%d\n" , - sensor->name, ret); -continue ; - } -/* * Warn on any misconfiguration related to thermal zones but * bail out of probing only on memory errors.
Signature · 1 line
2.43.0
Re: [PATCH 2/2] hwmon: (scmi) Configure sensors before exposing channels
Quoted 9 lines · Sudeep Holla
SCMI hwmon enables sensors with
SENSOR_CONFIG_SET, but only after registering the hwmon device and only for temperature sensors. This leaves other sensor classes disabled on firmware that defaults sensors to off, and exposes temperature channels before they are ready.Configure each supported sensor while building the channel list, before registering the hwmon device. Leave failed sensors out of the list so their channels remain hidden, while continuing with other sensors.
Quoted 5 lines
Cc Marek Vasut <[email protected]>Reported-by Sashiko <[email protected]>Fixes 72804d1631b3 ("hwmon: (scmi) Enable sensors to assure they can be read")Signed-off-by Sudeep Holla <[email protected]>
Applied.
Thanks,
Guenter
Quoted 11 lines · Sudeep Holla
scmi_hwmon_add_chan_info()can fail to allocate a channel's config array. Ignoring that error leaves a channel with a NULL config pointer in the hwmon chip info, which hwmon dereferences while registering the device.Check the helper's return value and abort probe on failure.
Reported-by Sashiko <[email protected]>Fixes b23688aefb8b ("hwmon: add support for sensors exported via ARM SCMI")Signed-off-by Sudeep Holla <[email protected]>
Applied.
Thanks,
Guenter