Skip to content

Commit 3120b5f

Browse files
t-8chsre
authored andcommitted
power: supply: core: mark attribute arrays as ro_after_init
The attribute arrays are only modified during the __init phase. To protect them against intentional or accidental modification, mark them as __ro_after_init. To make sure no modifications are introduced, also mark the return values of the accessors as const. Signed-off-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent cf70da2 commit 3120b5f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

drivers/power/supply/power_supply.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern int power_supply_property_is_writeable(struct power_supply *psy,
1818

1919
#ifdef CONFIG_SYSFS
2020

21-
extern void power_supply_init_attrs(void);
21+
extern void __init power_supply_init_attrs(void);
2222
extern int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env);
2323
extern const struct attribute_group *power_supply_attr_groups[];
2424

drivers/power/supply/power_supply_sysfs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static const char * const POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT[] = {
142142
[POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE] = "force-discharge",
143143
};
144144

145-
static struct power_supply_attr power_supply_attrs[] = {
145+
static struct power_supply_attr power_supply_attrs[] __ro_after_init = {
146146
/* Properties of type `int' */
147147
POWER_SUPPLY_ENUM_ATTR(STATUS),
148148
POWER_SUPPLY_ENUM_ATTR(CHARGE_TYPE),
@@ -225,9 +225,9 @@ static struct power_supply_attr power_supply_attrs[] = {
225225
#define POWER_SUPPLY_ATTR_CNT ARRAY_SIZE(power_supply_attrs)
226226

227227
static struct attribute *
228-
__power_supply_attrs[POWER_SUPPLY_ATTR_CNT + 1];
228+
__power_supply_attrs[POWER_SUPPLY_ATTR_CNT + 1] __ro_after_init;
229229

230-
static struct power_supply_attr *to_ps_attr(struct device_attribute *attr)
230+
static const struct power_supply_attr *to_ps_attr(struct device_attribute *attr)
231231
{
232232
return container_of(attr, struct power_supply_attr, dev_attr);
233233
}
@@ -273,7 +273,7 @@ static ssize_t power_supply_show_property(struct device *dev,
273273
char *buf) {
274274
ssize_t ret;
275275
struct power_supply *psy = dev_get_drvdata(dev);
276-
struct power_supply_attr *ps_attr = to_ps_attr(attr);
276+
const struct power_supply_attr *ps_attr = to_ps_attr(attr);
277277
enum power_supply_property psp = dev_attr_psp(attr);
278278
union power_supply_propval value;
279279

@@ -326,7 +326,7 @@ static ssize_t power_supply_store_property(struct device *dev,
326326
const char *buf, size_t count) {
327327
ssize_t ret;
328328
struct power_supply *psy = dev_get_drvdata(dev);
329-
struct power_supply_attr *ps_attr = to_ps_attr(attr);
329+
const struct power_supply_attr *ps_attr = to_ps_attr(attr);
330330
enum power_supply_property psp = dev_attr_psp(attr);
331331
union power_supply_propval value;
332332

@@ -401,7 +401,7 @@ const struct attribute_group *power_supply_attr_groups[] = {
401401
NULL
402402
};
403403

404-
void power_supply_init_attrs(void)
404+
void __init power_supply_init_attrs(void)
405405
{
406406
int i;
407407

0 commit comments

Comments
 (0)