hwmon: scmi: Driver improvements and fixes
Subsystems (2)
cover hwmon: scmi: Driver improvements and fixes
From: Artem Shimko <[email protected]>
This patch series introduces several improvements to the SCMI HWMON driver:
1. Better handling of unsupported sensor types with debug logging
2. Fixes redundant resource management in thermal registration
3. Enhanced error reporting using dev_err_probe()
4. Added version tracking and proper contributor attribution
The changes maintain backward compatibility while improving:
- Debugging capabilities
- Error reporting clarity
- Code maintenance
- Contributor tracking
Artem Shimko (4):
hwmon: scmi: Add default case with debug output
hwmon: scmi: Remove redundant devm_kfree call
hwmon: scmi: Enhance error reporting with dev_err_probe
hwmon: scmi: Add driver version and patch author
drivers/hwmon/scmi-hwmon.c | 50 ++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 hwmon: scmi: Add default case with debug output
From: Artem Shimko <[email protected]>
Improve handling of unsupported sensor types:
- Add default case in sensor type switch statement
- Log skipped sensors with debug information including:
* Sensor ID
* Sensor type
* Sensor name (if available)
- Use rate-limited dev_dbg for safety
Debug output format:
"Skipping unsupported sensor ID:%d Type:%d (%s)"
--- drivers/hwmon/scmi-hwmon.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/hwmon/scmi-hwmon.c +8 -0
@@ -275,6 +275,10 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) nr_count[type]++;break ; } +default : +dev_dbg (dev,"Skipping unsupported sensor ID:%d Type:%d (%s)\n" , + i, sensor->type, sensor->name ? sensor->name :"unnamed" ); +continue ; }if (nr_count[hwmon_temp])
@@ -323,6 +327,10 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) idx = --nr_count[type]; *(scmi_sensors->info[type] + idx) = sensor;break ; +default : +dev_dbg (dev,"Skipping unsupported sensor ID:%d Type:%d (%s)\n" , + i, sensor->type, sensor->name ? sensor->name :"unnamed" ); +continue ; } }
Signature · 1 line
2.43.0
PATCH 2/4 hwmon: scmi: Remove redundant devm_kfree call
In reply to Artyom ShimkoFrom: Artem Shimko <[email protected]>
Fix potential resource management issue by:
- Removing unnecessary devm_kfree() call in error path
- Relying on devres automatic cleanup
- Preserving all error handling logic
Rationale:
- Memory was allocated with devm_kzalloc()
- devm_ thermal registration manages its own resources
- Double-free could occur during probe failure
--- drivers/hwmon/scmi-hwmon.c | 2 -- 1 file changed, 2 deletions(-)
drivers/hwmon/scmi-hwmon.c +0 -2
@@ -211,8 +211,6 @@ static int scmi_thermal_sensor_register(struct device *dev, tzd =devm_thermal_of_zone_register (dev, th_sensor->info->id, th_sensor, &scmi_hwmon_thermal_ops);if (IS_ERR (tzd)) { -devm_kfree (dev, th_sensor); -if (PTR_ERR (tzd) != -ENODEV )return PTR_ERR (tzd);
Signature · 1 line
2.43.0
PATCH 3/4 hwmon: scmi: Enhance error reporting with dev_err_probe
In reply to Artyom ShimkoFrom: Artem Shimko <[email protected]>
Replace error returns with dev_err_probe() throughout driver:
- Add descriptive error messages for all failure cases
- Include relevant context (sensor IDs, types etc)
- Standardize error reporting format
Improved messages include:
- "No valid sensor info for index %d"
- "Failed to allocate channel info array"
- "SCMI protocol ops not initialized"
--- drivers/hwmon/scmi-hwmon.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
drivers/hwmon/scmi-hwmon.c +24 -11
@@ -240,26 +240,36 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)struct scmi_protocol_handle *ph;if (!handle) -return -ENODEV ; +return dev_err_probe (dev, -ENODEV ,"SCMI device handle is NULL\n" ); sensor_ops = handle->devm_protocol_get (sdev,SCMI_PROTOCOL_SENSOR , &ph); -if (IS_ERR (sensor_ops)) -return PTR_ERR (sensor_ops); +if (IS_ERR_OR_NULL (sensor_ops)) { +if (IS_ERR (sensor_ops)) +return dev_err_probe (dev,PTR_ERR (sensor_ops), +"SCMI sensor protocol acquisition failed\n" ); +return dev_err_probe (dev, -EPROTO , +"SCMI sensor protocol ops structure unexpectedly NULL\n" ); + } + +if (!sensor_ops->info_get || !sensor_ops->count_get) +return dev_err_probe (dev, -ENOENT , +"SCMI sensor protocol operations are not initialized\n" ); nr_sensors = sensor_ops->count_get (ph);if (!nr_sensors) -return -EIO ; +return dev_err_probe (dev, -EIO ,"No sensors found\n" ); scmi_sensors =devm_kzalloc (dev,sizeof (*scmi_sensors),GFP_KERNEL );if (!scmi_sensors) -return -ENOMEM ; +return dev_err_probe (dev, -ENOMEM ,"Failed to allocate scmi_sensors structure\n" ); scmi_sensors->ph = ph;for (i =0 ; i < nr_sensors; i++) { sensor = sensor_ops->info_get (ph, i);if (!sensor) -return -EINVAL ; +return dev_err_probe (dev, -EINVAL , +"Failed to get sensor info for sensor %d\n" , i);switch (sensor->type) {case TEMPERATURE_C :
@@ -285,12 +295,12 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) scmi_hwmon_chan =devm_kcalloc (dev, nr_types,sizeof (*scmi_hwmon_chan),GFP_KERNEL );if (!scmi_hwmon_chan) -return -ENOMEM ; +return dev_err_probe (dev, -ENOMEM ,"Failed to allocate channel info array\n" ); ptr_scmi_ci =devm_kcalloc (dev, nr_types +1 ,sizeof (*ptr_scmi_ci),GFP_KERNEL );if (!ptr_scmi_ci) -return -ENOMEM ; +return dev_err_probe (dev, -ENOMEM ,"Failed to allocate channel info pointers\n" ); scmi_chip_info.info = ptr_scmi_ci; chip_info = &scmi_chip_info;
@@ -307,7 +317,8 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)devm_kcalloc (dev, nr_count[type],sizeof (*scmi_sensors->info),GFP_KERNEL );if (!scmi_sensors->info[type]) -return -ENOMEM ; +return dev_err_probe (dev, -ENOMEM , +"Failed to allocate sensor info for type %d\n" , type); }for (i = nr_sensors -1 ; i >=0 ; i--) {
@@ -336,7 +347,7 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) scmi_sensors, chip_info, NULL);if (IS_ERR (hwdev)) -return PTR_ERR (hwdev); +return dev_err_probe (dev,PTR_ERR (hwdev),"Failed to register hwmon device\n" );for (i =0 ; i < nr_count_temp; i++) {int ret;
@@ -352,7 +363,9 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) ret =scmi_thermal_sensor_register (dev, ph, sensor);if (ret) {if (ret == -ENOMEM ) -return ret; +return dev_err_probe (dev, ret, +"Failed to allocate memory for thermal zone\n" ); +dev_warn (dev,"Thermal zone misconfigured for %s. err=%d\n" , sensor->name, ret);
Signature · 1 line
2.43.0