]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
power: supply: sysfs: Constify pointer passed to dev_attr_psp()
authorKrzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Wed, 26 Nov 2025 17:19:00 +0000 (18:19 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 12 Jan 2026 01:52:31 +0000 (02:52 +0100)
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>
Link: https://patch.msgid.link/20251126171859.72465-2-krzysztof.kozlowski@oss.qualcomm.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply_sysfs.c

index 198405f7126f96a57a549cd1ecb9b71089b9c3d0..dd3a48d72d2b18c0580b926ca34667474781eb61 100644 (file)
@@ -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;
 }