linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] hwmon: scmi: Driver improvements and fixes
@ 2025-08-05 12:43 a.shimko
  2025-08-05 12:43 ` [PATCH 1/3] hwmon: scmi: Add default case with debug output a.shimko
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: a.shimko @ 2025-08-05 12:43 UTC (permalink / raw)
  To: linux-hwmon
  Cc: a.shimko, linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck

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()

The changes maintain backward compatibility while improving:
- Debugging capabilities
- Error reporting clarity
- Code maintenance

ChangeLog:
  v1:
https://lore.kernel.org/linux-hwmon/20250805111840.6472-1-artyom.shimko@gmail.com/
  v2:
    * fix wrong cover letter and patches count in subjects

Artem Shimko (3):
  hwmon: scmi: Add default case with debug output
  hwmon: scmi: Remove redundant devm_kfree call
  hwmon: scmi: Enhance error reporting with dev_err_probe

 drivers/hwmon/scmi-hwmon.c | 45 +++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 13 deletions(-)

-- 
2.43.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] hwmon: scmi: Add default case with debug output
  2025-08-05 12:43 [PATCH v2 0/3] hwmon: scmi: Driver improvements and fixes a.shimko
@ 2025-08-05 12:43 ` a.shimko
  2025-08-05 13:10   ` Guenter Roeck
  2025-08-06 15:12   ` kernel test robot
  2025-08-05 12:43 ` [PATCH 2/3] hwmon: scmi: Remove redundant devm_kfree call a.shimko
  2025-08-05 12:43 ` [PATCH 3/3] hwmon: scmi: Enhance error reporting with dev_err_probe a.shimko
  2 siblings, 2 replies; 8+ messages in thread
From: a.shimko @ 2025-08-05 12:43 UTC (permalink / raw)
  To: linux-hwmon
  Cc: a.shimko, linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck

From: Artem Shimko <artyom.shimko@gmail.com>

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)"

Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
---
 drivers/hwmon/scmi-hwmon.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index 364199b332c0..a3b5b5c0ec25 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -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;
 		}
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] hwmon: scmi: Remove redundant devm_kfree call
  2025-08-05 12:43 [PATCH v2 0/3] hwmon: scmi: Driver improvements and fixes a.shimko
  2025-08-05 12:43 ` [PATCH 1/3] hwmon: scmi: Add default case with debug output a.shimko
@ 2025-08-05 12:43 ` a.shimko
  2025-08-05 13:13   ` Guenter Roeck
  2025-08-05 12:43 ` [PATCH 3/3] hwmon: scmi: Enhance error reporting with dev_err_probe a.shimko
  2 siblings, 1 reply; 8+ messages in thread
From: a.shimko @ 2025-08-05 12:43 UTC (permalink / raw)
  To: linux-hwmon
  Cc: a.shimko, linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck

From: Artem Shimko <artyom.shimko@gmail.com>

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

Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
---
 drivers/hwmon/scmi-hwmon.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index a3b5b5c0ec25..d03174922e65 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -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);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] hwmon: scmi: Enhance error reporting with dev_err_probe
  2025-08-05 12:43 [PATCH v2 0/3] hwmon: scmi: Driver improvements and fixes a.shimko
  2025-08-05 12:43 ` [PATCH 1/3] hwmon: scmi: Add default case with debug output a.shimko
  2025-08-05 12:43 ` [PATCH 2/3] hwmon: scmi: Remove redundant devm_kfree call a.shimko
@ 2025-08-05 12:43 ` a.shimko
  2025-08-05 13:20   ` Guenter Roeck
  2 siblings, 1 reply; 8+ messages in thread
From: a.shimko @ 2025-08-05 12:43 UTC (permalink / raw)
  To: linux-hwmon
  Cc: a.shimko, linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck

From: Artem Shimko <artyom.shimko@gmail.com>

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"

Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
---
 drivers/hwmon/scmi-hwmon.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index d03174922e65..081502418dfa 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] hwmon: scmi: Add default case with debug output
  2025-08-05 12:43 ` [PATCH 1/3] hwmon: scmi: Add default case with debug output a.shimko
@ 2025-08-05 13:10   ` Guenter Roeck
  2025-08-06 15:12   ` kernel test robot
  1 sibling, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2025-08-05 13:10 UTC (permalink / raw)
  To: a.shimko, linux-hwmon
  Cc: linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck

On 8/5/25 05:43, a.shimko wrote:
> From: Artem Shimko <artyom.shimko@gmail.com>
> 
> 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
> 

The code doesn't actually do that, and it would be pointless
and make the message useless.

> Debug output format:
> "Skipping unsupported sensor ID:%d Type:%d (%s)"
> 
> Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
> ---
>   drivers/hwmon/scmi-hwmon.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> index 364199b332c0..a3b5b5c0ec25 100644
> --- a/drivers/hwmon/scmi-hwmon.c
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -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;

			break;

>   	}
>   
>   	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;

			break;

>   		}
>   	}
>   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] hwmon: scmi: Remove redundant devm_kfree call
  2025-08-05 12:43 ` [PATCH 2/3] hwmon: scmi: Remove redundant devm_kfree call a.shimko
@ 2025-08-05 13:13   ` Guenter Roeck
  0 siblings, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2025-08-05 13:13 UTC (permalink / raw)
  To: a.shimko, linux-hwmon
  Cc: linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck

On 8/5/25 05:43, a.shimko wrote:
> From: Artem Shimko <artyom.shimko@gmail.com>
> 
> 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

The reason for calling devm_kfree() is to avoid holding the memory
unnecessarily until the driver deregisters. There is no double free since
the code calls devm_kfree(), not kfree().

The reasoning is wrong, and the patch does not add value.

Guenter

> 
> Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
> ---
>   drivers/hwmon/scmi-hwmon.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> index a3b5b5c0ec25..d03174922e65 100644
> --- a/drivers/hwmon/scmi-hwmon.c
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -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);
>   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] hwmon: scmi: Enhance error reporting with dev_err_probe
  2025-08-05 12:43 ` [PATCH 3/3] hwmon: scmi: Enhance error reporting with dev_err_probe a.shimko
@ 2025-08-05 13:20   ` Guenter Roeck
  0 siblings, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2025-08-05 13:20 UTC (permalink / raw)
  To: a.shimko, linux-hwmon
  Cc: linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck

On 8/5/25 05:43, a.shimko wrote:
> From: Artem Shimko <artyom.shimko@gmail.com>
> 
> 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"
> 
> Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
> ---
>   drivers/hwmon/scmi-hwmon.c | 35 ++++++++++++++++++++++++-----------
>   1 file changed, 24 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> index d03174922e65..081502418dfa 100644
> --- a/drivers/hwmon/scmi-hwmon.c
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -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");

-ENODEV is not supposed to log an error message.

>   
>   	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)) {

This never returns NULL, and AFAIS no other driver checks for it.
Why add this unnecessary check ?

> +		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");

It is not this driver's responsibility to validate sensor_ops.

>   
>   	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");

-ENOMEM is not supposed to log an error message.

>   
>   	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");

Same as above.

>   
>   	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");

Same as above.

>   
>   	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);

And again.

>   	}
>   
>   	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");
> +
And again.

>   			dev_warn(dev,
>   				 "Thermal zone misconfigured for %s. err=%d\n",
>   				 sensor->name, ret);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] hwmon: scmi: Add default case with debug output
  2025-08-05 12:43 ` [PATCH 1/3] hwmon: scmi: Add default case with debug output a.shimko
  2025-08-05 13:10   ` Guenter Roeck
@ 2025-08-06 15:12   ` kernel test robot
  1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2025-08-06 15:12 UTC (permalink / raw)
  To: a.shimko, linux-hwmon
  Cc: oe-kbuild-all, a.shimko, linux-kernel, sudeep.holla,
	cristian.marussi, jdelvare, guenter.roeck

Hi a.shimko,

kernel test robot noticed the following build errors:

[auto build test ERROR on groeck-staging/hwmon-next]
[also build test ERROR on linus/master v6.16 next-20250806]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/a-shimko/hwmon-scmi-Add-default-case-with-debug-output/20250806-122638
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20250805125003.12573-2-artyom.shimko%40gmail.com
patch subject: [PATCH 1/3] hwmon: scmi: Add default case with debug output
config: arc-randconfig-001-20250806 (https://download.01.org/0day-ci/archive/20250806/202508062201.bWDZGD03-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 12.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250806/202508062201.bWDZGD03-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508062201.bWDZGD03-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/hwmon/scmi-hwmon.c: In function 'scmi_hwmon_probe':
>> drivers/hwmon/scmi-hwmon.c:278:17: error: 'default' label not within a switch statement
     278 |                 default:
         |                 ^~~~~~~


vim +/default +278 drivers/hwmon/scmi-hwmon.c

   228	
   229	static int scmi_hwmon_probe(struct scmi_device *sdev)
   230	{
   231		int i, idx;
   232		u16 nr_sensors;
   233		enum hwmon_sensor_types type;
   234		struct scmi_sensors *scmi_sensors;
   235		const struct scmi_sensor_info *sensor;
   236		int nr_count[hwmon_max] = {0}, nr_types = 0, nr_count_temp = 0;
   237		const struct hwmon_chip_info *chip_info;
   238		struct device *hwdev, *dev = &sdev->dev;
   239		struct hwmon_channel_info *scmi_hwmon_chan;
   240		const struct hwmon_channel_info **ptr_scmi_ci;
   241		const struct scmi_handle *handle = sdev->handle;
   242		struct scmi_protocol_handle *ph;
   243	
   244		if (!handle)
   245			return -ENODEV;
   246	
   247		sensor_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_SENSOR, &ph);
   248		if (IS_ERR(sensor_ops))
   249			return PTR_ERR(sensor_ops);
   250	
   251		nr_sensors = sensor_ops->count_get(ph);
   252		if (!nr_sensors)
   253			return -EIO;
   254	
   255		scmi_sensors = devm_kzalloc(dev, sizeof(*scmi_sensors), GFP_KERNEL);
   256		if (!scmi_sensors)
   257			return -ENOMEM;
   258	
   259		scmi_sensors->ph = ph;
   260	
   261		for (i = 0; i < nr_sensors; i++) {
   262			sensor = sensor_ops->info_get(ph, i);
   263			if (!sensor)
   264				return -EINVAL;
   265	
   266			switch (sensor->type) {
   267			case TEMPERATURE_C:
   268			case VOLTAGE:
   269			case CURRENT:
   270			case POWER:
   271			case ENERGY:
   272				type = scmi_types[sensor->type];
   273				if (!nr_count[type])
   274					nr_types++;
   275				nr_count[type]++;
   276				break;
   277			}
 > 278			default:
   279				dev_dbg(dev, "Skipping unsupported sensor ID:%d Type:%d (%s)\n",
   280					i, sensor->type, sensor->name ? sensor->name : "unnamed");
   281				continue;
   282		}
   283	
   284		if (nr_count[hwmon_temp])
   285			nr_count_temp = nr_count[hwmon_temp];
   286	
   287		scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan),
   288					       GFP_KERNEL);
   289		if (!scmi_hwmon_chan)
   290			return -ENOMEM;
   291	
   292		ptr_scmi_ci = devm_kcalloc(dev, nr_types + 1, sizeof(*ptr_scmi_ci),
   293					   GFP_KERNEL);
   294		if (!ptr_scmi_ci)
   295			return -ENOMEM;
   296	
   297		scmi_chip_info.info = ptr_scmi_ci;
   298		chip_info = &scmi_chip_info;
   299	
   300		for (type = 0; type < hwmon_max; type++) {
   301			if (!nr_count[type])
   302				continue;
   303	
   304			scmi_hwmon_add_chan_info(scmi_hwmon_chan, dev, nr_count[type],
   305						 type, hwmon_attributes[type]);
   306			*ptr_scmi_ci++ = scmi_hwmon_chan++;
   307	
   308			scmi_sensors->info[type] =
   309				devm_kcalloc(dev, nr_count[type],
   310					     sizeof(*scmi_sensors->info), GFP_KERNEL);
   311			if (!scmi_sensors->info[type])
   312				return -ENOMEM;
   313		}
   314	
   315		for (i = nr_sensors - 1; i >= 0 ; i--) {
   316			sensor = sensor_ops->info_get(ph, i);
   317			if (!sensor)
   318				continue;
   319	
   320			switch (sensor->type) {
   321			case TEMPERATURE_C:
   322			case VOLTAGE:
   323			case CURRENT:
   324			case POWER:
   325			case ENERGY:
   326				type = scmi_types[sensor->type];
   327				idx = --nr_count[type];
   328				*(scmi_sensors->info[type] + idx) = sensor;
   329				break;
   330			default:
   331				dev_dbg(dev, "Skipping unsupported sensor ID:%d Type:%d (%s)\n",
   332					i, sensor->type, sensor->name ? sensor->name : "unnamed");
   333				continue;
   334			}
   335		}
   336	
   337		hwdev = devm_hwmon_device_register_with_info(dev, "scmi_sensors",
   338							     scmi_sensors, chip_info,
   339							     NULL);
   340		if (IS_ERR(hwdev))
   341			return PTR_ERR(hwdev);
   342	
   343		for (i = 0; i < nr_count_temp; i++) {
   344			int ret;
   345	
   346			sensor = *(scmi_sensors->info[hwmon_temp] + i);
   347			if (!sensor)
   348				continue;
   349	
   350			/*
   351			 * Warn on any misconfiguration related to thermal zones but
   352			 * bail out of probing only on memory errors.
   353			 */
   354			ret = scmi_thermal_sensor_register(dev, ph, sensor);
   355			if (ret) {
   356				if (ret == -ENOMEM)
   357					return ret;
   358				dev_warn(dev,
   359					 "Thermal zone misconfigured for %s. err=%d\n",
   360					 sensor->name, ret);
   361			}
   362		}
   363	
   364		return 0;
   365	}
   366	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-06 15:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 12:43 [PATCH v2 0/3] hwmon: scmi: Driver improvements and fixes a.shimko
2025-08-05 12:43 ` [PATCH 1/3] hwmon: scmi: Add default case with debug output a.shimko
2025-08-05 13:10   ` Guenter Roeck
2025-08-06 15:12   ` kernel test robot
2025-08-05 12:43 ` [PATCH 2/3] hwmon: scmi: Remove redundant devm_kfree call a.shimko
2025-08-05 13:13   ` Guenter Roeck
2025-08-05 12:43 ` [PATCH 3/3] hwmon: scmi: Enhance error reporting with dev_err_probe a.shimko
2025-08-05 13:20   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).