mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/4] hwmon: scmi: Driver improvements and fixes
@ 2025-08-05 11:18 Artyom Shimko
  2025-08-05 11:18 ` [PATCH v1 1/4] hwmon: scmi: Add default case with debug output Artyom Shimko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Artyom Shimko @ 2025-08-05 11:18 UTC (permalink / raw)
  To: linux-hwmon
  Cc: linux-kernel, sudeep.holla, cristian.marussi, jdelvare,
	guenter.roeck, Artem Shimko

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

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

-- 
2.43.0

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [PATCH v1 0/4] hwmon: scmi: Driver improvements and fixes
@ 2025-07-31 13:21 Artyom Shimko
  2025-07-31 13:38 ` Sudeep Holla
  0 siblings, 1 reply; 6+ messages in thread
From: Artyom Shimko @ 2025-07-31 13:21 UTC (permalink / raw)
  To: linux-hwmon
  Cc: linux-kernel, sudeep.holla, cristian.marussi, jdelvare, guenter.roeck


[-- Attachment #1.1: Type: text/plain, Size: 834 bytes --]

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

-- 
2.43.0

[-- Attachment #1.2: Type: text/html, Size: 931 bytes --]

[-- Attachment #2: 0001-hwmon-scmi-Add-default-case-with-debug-output.patch --]
[-- Type: text/x-patch, Size: 1509 bytes --]

From 34ddd8c2117c3fbfba9171f1906341912d135063 Mon Sep 17 00:00:00 2001
From: Artem Shimko <artyom.shimko@gmail.com>
Date: Thu, 31 Jul 2025 16:09:31 +0300
Subject: [PATCH v1 1/4] hwmon: scmi: Add default case with debug output

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


[-- Attachment #3: 0004-hwmon-scmi-Add-driver-version-and-patch-author.patch --]
[-- Type: text/x-patch, Size: 1618 bytes --]

From cbe176fd6280484fcf70ac0b73c370754dc6eed8 Mon Sep 17 00:00:00 2001
From: Artem Shimko <artyom.shimko@gmail.com>
Date: Thu, 31 Jul 2025 16:10:15 +0300
Subject: [PATCH v1 4/4] hwmon: scmi: Add driver version and patch author

Introduce DRIVER_VERSION macro to track driver revisions and add myself
as co-author to the module:
- Define DRIVER_VERSION "1.0" following standard versioning
- Add MODULE_VERSION for in-tree version tracking
- Include my signature as module co-author

This helps with:
- Debugging version-specific issues
- Proper attribution of contributions
- Compatibility checks

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

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index 081502418dfa..6b4b988d63c8 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -4,6 +4,7 @@
  *
  * Copyright (C) 2018-2021 ARM Ltd.
  * Sudeep Holla <sudeep.holla@arm.com>
+ * Patched by Artem Shimko <artyom.shimko@gmail.com>
  */
 
 #include <linux/hwmon.h>
@@ -13,6 +14,8 @@
 #include <linux/sysfs.h>
 #include <linux/thermal.h>
 
+#define DRIVER_VERSION "1.0"
+
 static const struct scmi_sensor_proto_ops *sensor_ops;
 
 struct scmi_sensors {
@@ -389,5 +392,7 @@ static struct scmi_driver scmi_hwmon_drv = {
 module_scmi_driver(scmi_hwmon_drv);
 
 MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
+MODULE_AUTHOR("Artem Shimko <artyom.shimko@gmail.com>");
 MODULE_DESCRIPTION("ARM SCMI HWMON interface driver");
 MODULE_LICENSE("GPL v2");
+MODULE_VERSION(DRIVER_VERSION);
-- 
2.43.0


[-- Attachment #4: 0000-cover-letter.patch --]
[-- Type: text/x-patch, Size: 1055 bytes --]

From cbe176fd6280484fcf70ac0b73c370754dc6eed8 Mon Sep 17 00:00:00 2001
From: Artem Shimko <artyom.shimko@gmail.com>
Date: Thu, 31 Jul 2025 16:14:43 +0300
Subject: [PATCH v1 0/4] hwmon: scmi: Driver improvements and fixes

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

-- 
2.43.0

[-- Attachment #5: 0002-hwmon-scmi-Remove-redundant-devm_kfree-call.patch --]
[-- Type: text/x-patch, Size: 1175 bytes --]

From 82d9921342af4ca7fb898b215d73642694549fd9 Mon Sep 17 00:00:00 2001
From: Artem Shimko <artyom.shimko@gmail.com>
Date: Thu, 31 Jul 2025 16:10:02 +0300
Subject: [PATCH v1 2/4] hwmon: scmi: Remove redundant devm_kfree call

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


[-- Attachment #6: 0003-hwmon-scmi-Enhance-error-reporting-with-dev_err_prob.patch --]
[-- Type: text/x-patch, Size: 4035 bytes --]

From dfa4c25ba0f4ce86d7082f078416a102a7ff91a1 Mon Sep 17 00:00:00 2001
From: Artem Shimko <artyom.shimko@gmail.com>
Date: Thu, 31 Jul 2025 16:10:10 +0300
Subject: [PATCH v1 3/4] hwmon: scmi: Enhance error reporting with
 dev_err_probe

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	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-05 11:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-05 11:18 [PATCH v1 0/4] hwmon: scmi: Driver improvements and fixes Artyom Shimko
2025-08-05 11:18 ` [PATCH v1 1/4] hwmon: scmi: Add default case with debug output Artyom Shimko
2025-08-05 11:18 ` [PATCH v1 2/4] hwmon: scmi: Remove redundant devm_kfree call Artyom Shimko
2025-08-05 11:18 ` [PATCH v1 3/4] hwmon: scmi: Enhance error reporting with dev_err_probe Artyom Shimko
  -- strict thread matches above, loose matches on Subject: below --
2025-07-31 13:21 [PATCH v1 0/4] hwmon: scmi: Driver improvements and fixes Artyom Shimko
2025-07-31 13:38 ` Sudeep Holla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®