[PATCH] power: supply: sysfs: Constify pointer passed to dev_attr_psp()

Krzysztof Kozlowski posted 1 patch 2 months, 2 weeks ago
drivers/power/supply/power_supply_sysfs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] power: supply: sysfs: Constify pointer passed to dev_attr_psp()
Posted by Krzysztof Kozlowski 2 months, 2 weeks ago
Memory pointer by pointer passed to dev_attr_psp() is not modified, so
with help of container_of_const() (preferred than container_of()) can be
made pointer to const for code safety.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/power/supply/power_supply_sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index 198405f7126f..dd3a48d72d2b 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -235,12 +235,12 @@ static struct power_supply_attr power_supply_attrs[] __ro_after_init = {
 static struct attribute *
 __power_supply_attrs[POWER_SUPPLY_ATTR_CNT + 1] __ro_after_init;
 
-static const struct power_supply_attr *to_ps_attr(struct device_attribute *attr)
+static const struct power_supply_attr *to_ps_attr(const struct device_attribute *attr)
 {
-	return container_of(attr, struct power_supply_attr, dev_attr);
+	return container_of_const(attr, struct power_supply_attr, dev_attr);
 }
 
-static enum power_supply_property dev_attr_psp(struct device_attribute *attr)
+static enum power_supply_property dev_attr_psp(const struct device_attribute *attr)
 {
 	return  to_ps_attr(attr) - power_supply_attrs;
 }
-- 
2.48.1
Re: [PATCH] power: supply: sysfs: Constify pointer passed to dev_attr_psp()
Posted by Sebastian Reichel 3 weeks, 6 days ago
On Wed, 26 Nov 2025 18:19:00 +0100, Krzysztof Kozlowski wrote:
> Memory pointer by pointer passed to dev_attr_psp() is not modified, so
> with help of container_of_const() (preferred than container_of()) can be
> made pointer to const for code safety.
> 
> 

Applied, thanks!

[1/1] power: supply: sysfs: Constify pointer passed to dev_attr_psp()
      commit: 2c7e46e1318d4fbf514f454d5a746a1b76d06ebe

Best regards,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>