Skip to content

Commit 883730c

Browse files
tititiou36sre
authored andcommitted
power: supply: wm831x: Constify struct chg_map and some arrays
'struct chg_map' is not modified in this driver. Constifying these structures moves some data to a read-only section, so increase overall security. While at it, also constify a few other arrays. On a x86_64, with allmodconfig, as an example: Before: ====== text data bss dec hex filename 14263 1744 0 16007 3e87 drivers/power/supply/wm831x_power.o After: ===== text data bss dec hex filename 14695 1288 0 15983 3e6f drivers/power/supply/wm831x_power.o Signed-off-by: Christophe JAILLET <[email protected]> Link: https://lore.kernel.org/r/0edde57b691db7f920d121fdbd5ebc3fb24f30f1.1743787625.git.christophe.jaillet@wanadoo.fr Signed-off-by: Sebastian Reichel <[email protected]>
1 parent afe5301 commit 883730c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/power/supply/wm831x_power.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static int wm831x_wall_get_prop(struct power_supply *psy,
8989
return ret;
9090
}
9191

92-
static enum power_supply_property wm831x_wall_props[] = {
92+
static const enum power_supply_property wm831x_wall_props[] = {
9393
POWER_SUPPLY_PROP_ONLINE,
9494
POWER_SUPPLY_PROP_VOLTAGE_NOW,
9595
};
@@ -120,7 +120,7 @@ static int wm831x_usb_get_prop(struct power_supply *psy,
120120
return ret;
121121
}
122122

123-
static enum power_supply_property wm831x_usb_props[] = {
123+
static const enum power_supply_property wm831x_usb_props[] = {
124124
POWER_SUPPLY_PROP_ONLINE,
125125
POWER_SUPPLY_PROP_VOLTAGE_NOW,
126126
};
@@ -171,21 +171,21 @@ struct chg_map {
171171
int reg_val;
172172
};
173173

174-
static struct chg_map trickle_ilims[] = {
174+
static const struct chg_map trickle_ilims[] = {
175175
{ 50, 0 << WM831X_CHG_TRKL_ILIM_SHIFT },
176176
{ 100, 1 << WM831X_CHG_TRKL_ILIM_SHIFT },
177177
{ 150, 2 << WM831X_CHG_TRKL_ILIM_SHIFT },
178178
{ 200, 3 << WM831X_CHG_TRKL_ILIM_SHIFT },
179179
};
180180

181-
static struct chg_map vsels[] = {
181+
static const struct chg_map vsels[] = {
182182
{ 4050, 0 << WM831X_CHG_VSEL_SHIFT },
183183
{ 4100, 1 << WM831X_CHG_VSEL_SHIFT },
184184
{ 4150, 2 << WM831X_CHG_VSEL_SHIFT },
185185
{ 4200, 3 << WM831X_CHG_VSEL_SHIFT },
186186
};
187187

188-
static struct chg_map fast_ilims[] = {
188+
static const struct chg_map fast_ilims[] = {
189189
{ 0, 0 << WM831X_CHG_FAST_ILIM_SHIFT },
190190
{ 50, 1 << WM831X_CHG_FAST_ILIM_SHIFT },
191191
{ 100, 2 << WM831X_CHG_FAST_ILIM_SHIFT },
@@ -204,7 +204,7 @@ static struct chg_map fast_ilims[] = {
204204
{ 1000, 15 << WM831X_CHG_FAST_ILIM_SHIFT },
205205
};
206206

207-
static struct chg_map eoc_iterms[] = {
207+
static const struct chg_map eoc_iterms[] = {
208208
{ 20, 0 << WM831X_CHG_ITERM_SHIFT },
209209
{ 30, 1 << WM831X_CHG_ITERM_SHIFT },
210210
{ 40, 2 << WM831X_CHG_ITERM_SHIFT },
@@ -215,7 +215,7 @@ static struct chg_map eoc_iterms[] = {
215215
{ 90, 7 << WM831X_CHG_ITERM_SHIFT },
216216
};
217217

218-
static struct chg_map chg_times[] = {
218+
static const struct chg_map chg_times[] = {
219219
{ 60, 0 << WM831X_CHG_TIME_SHIFT },
220220
{ 90, 1 << WM831X_CHG_TIME_SHIFT },
221221
{ 120, 2 << WM831X_CHG_TIME_SHIFT },
@@ -235,7 +235,7 @@ static struct chg_map chg_times[] = {
235235
};
236236

237237
static void wm831x_battery_apply_config(struct wm831x *wm831x,
238-
struct chg_map *map, int count, int val,
238+
const struct chg_map *map, int count, int val,
239239
int *reg, const char *name,
240240
const char *units)
241241
{
@@ -462,15 +462,15 @@ static int wm831x_bat_get_prop(struct power_supply *psy,
462462
return ret;
463463
}
464464

465-
static enum power_supply_property wm831x_bat_props[] = {
465+
static const enum power_supply_property wm831x_bat_props[] = {
466466
POWER_SUPPLY_PROP_STATUS,
467467
POWER_SUPPLY_PROP_ONLINE,
468468
POWER_SUPPLY_PROP_VOLTAGE_NOW,
469469
POWER_SUPPLY_PROP_HEALTH,
470470
POWER_SUPPLY_PROP_CHARGE_TYPE,
471471
};
472472

473-
static const char *wm831x_bat_irqs[] = {
473+
static const char * const wm831x_bat_irqs[] = {
474474
"BATT HOT",
475475
"BATT COLD",
476476
"BATT FAIL",

0 commit comments

Comments
 (0)