Skip to content

Commit 5d55721

Browse files
tititiou36sre
authored andcommitted
power: supply: samsung-sdi-battery: Constify struct power_supply_vbat_ri_table
'struct power_supply_vbat_ri_table' are not modified in this driver. Constifying these structures moves some data to a read-only section, so increase overall security. In order to do it, some code also needs to be adjusted to this new const qualifier. On a x86_64, with allmodconfig: Before: ====== $ size drivers/power/supply/samsung-sdi-battery.o text data bss dec hex filename 955 7664 0 8619 21ab drivers/power/supply/samsung-sdi-battery.o After: ===== $ size drivers/power/supply/samsung-sdi-battery.o text data bss dec hex filename 4055 4584 0 8639 21bf drivers/power/supply/samsung-sdi-battery.o Signed-off-by: Christophe JAILLET <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/d01818abd880bf435d1106a9a6cc11a7a8a3e661.1719125040.git.christophe.jaillet@wanadoo.fr Signed-off-by: Sebastian Reichel <[email protected]>
1 parent db9cc84 commit 5d55721

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

drivers/power/supply/power_supply_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ EXPORT_SYMBOL_GPL(power_supply_temp2resist_simple);
10241024
int power_supply_vbat2ri(struct power_supply_battery_info *info,
10251025
int vbat_uv, bool charging)
10261026
{
1027-
struct power_supply_vbat_ri_table *vbat2ri;
1027+
const struct power_supply_vbat_ri_table *vbat2ri;
10281028
int table_len;
10291029
int i, high, low;
10301030

drivers/power/supply/samsung-sdi-battery.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct samsung_sdi_battery {
2525
* tables apply depending on whether we are charging or not.
2626
*/
2727

28-
static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb_l1m7flu[] = {
28+
static const struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb_l1m7flu[] = {
2929
{ .vbat_uv = 4240000, .ri_uohm = 160000 },
3030
{ .vbat_uv = 4210000, .ri_uohm = 179000 },
3131
{ .vbat_uv = 4180000, .ri_uohm = 183000 },
@@ -53,7 +53,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb_l1m7flu
5353
{ .vbat_uv = 3300000, .ri_uohm = 339000 },
5454
};
5555

56-
static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb_l1m7flu[] = {
56+
static const struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb_l1m7flu[] = {
5757
{ .vbat_uv = 4302000, .ri_uohm = 230000 },
5858
{ .vbat_uv = 4276000, .ri_uohm = 345000 },
5959
{ .vbat_uv = 4227000, .ri_uohm = 345000 },
@@ -73,7 +73,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb_l1m7flu[]
7373
{ .vbat_uv = 3590000, .ri_uohm = 164000 },
7474
};
7575

76-
static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb425161la[] = {
76+
static const struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb425161la[] = {
7777
{ .vbat_uv = 4240000, .ri_uohm = 160000 },
7878
{ .vbat_uv = 4210000, .ri_uohm = 179000 },
7979
{ .vbat_uv = 4180000, .ri_uohm = 183000 },
@@ -105,7 +105,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb425161la
105105
{ .vbat_uv = 3300000, .ri_uohm = 339000 },
106106
};
107107

108-
static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb425161la[] = {
108+
static const struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb425161la[] = {
109109
{ .vbat_uv = 4345000, .ri_uohm = 230000 },
110110
{ .vbat_uv = 4329000, .ri_uohm = 238000 },
111111
{ .vbat_uv = 4314000, .ri_uohm = 225000 },
@@ -182,7 +182,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb425161la[]
182182
{ .vbat_uv = 3590000, .ri_uohm = 164000 },
183183
};
184184

185-
static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb425161lu[] = {
185+
static const struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb425161lu[] = {
186186
{ .vbat_uv = 4240000, .ri_uohm = 160000 },
187187
{ .vbat_uv = 4210000, .ri_uohm = 179000 },
188188
{ .vbat_uv = 4180000, .ri_uohm = 183000 },
@@ -214,7 +214,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb425161lu
214214
{ .vbat_uv = 3300000, .ri_uohm = 339000 },
215215
};
216216

217-
static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb425161lu[] = {
217+
static const struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb425161lu[] = {
218218
{ .vbat_uv = 4346000, .ri_uohm = 293000 },
219219
{ .vbat_uv = 4336000, .ri_uohm = 290000 },
220220
{ .vbat_uv = 4315000, .ri_uohm = 274000 },
@@ -244,7 +244,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb425161lu[]
244244
{ .vbat_uv = 3590000, .ri_uohm = 164000 },
245245
};
246246

247-
static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb485159lu[] = {
247+
static const struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb485159lu[] = {
248248
{ .vbat_uv = 4240000, .ri_uohm = 160000 },
249249
{ .vbat_uv = 4210000, .ri_uohm = 179000 },
250250
{ .vbat_uv = 4180000, .ri_uohm = 183000 },
@@ -271,7 +271,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb485159lu
271271
{ .vbat_uv = 3300000, .ri_uohm = 339000 },
272272
};
273273

274-
static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb485159lu[] = {
274+
static const struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb485159lu[] = {
275275
{ .vbat_uv = 4302000, .ri_uohm = 200000 },
276276
{ .vbat_uv = 4258000, .ri_uohm = 206000 },
277277
{ .vbat_uv = 4200000, .ri_uohm = 231000 },
@@ -291,7 +291,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb485159lu[]
291291
{ .vbat_uv = 3590000, .ri_uohm = 164000 },
292292
};
293293

294-
static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb535151vu[] = {
294+
static const struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb535151vu[] = {
295295
{ .vbat_uv = 4071000, .ri_uohm = 158000 },
296296
{ .vbat_uv = 4019000, .ri_uohm = 187000 },
297297
{ .vbat_uv = 3951000, .ri_uohm = 191000 },
@@ -311,7 +311,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb535151vu
311311
{ .vbat_uv = 3280000, .ri_uohm = 250000 },
312312
};
313313

314-
static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb535151vu[] = {
314+
static const struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb535151vu[] = {
315315
{ .vbat_uv = 4190000, .ri_uohm = 214000 },
316316
{ .vbat_uv = 4159000, .ri_uohm = 252000 },
317317
{ .vbat_uv = 4121000, .ri_uohm = 245000 },
@@ -331,7 +331,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb535151vu[]
331331
{ .vbat_uv = 3510000, .ri_uohm = 228000 },
332332
};
333333

334-
static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb585157lu[] = {
334+
static const struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb585157lu[] = {
335335
{ .vbat_uv = 4194000, .ri_uohm = 121000 },
336336
{ .vbat_uv = 4169000, .ri_uohm = 188000 },
337337
{ .vbat_uv = 4136000, .ri_uohm = 173000 },
@@ -401,7 +401,7 @@ static struct power_supply_vbat_ri_table samsung_vbat2res_discharging_eb585157lu
401401
{ .vbat_uv = 3161000, .ri_uohm = 452000 },
402402
};
403403

404-
static struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb585157lu[] = {
404+
static const struct power_supply_vbat_ri_table samsung_vbat2res_charging_eb585157lu[] = {
405405
{ .vbat_uv = 4360000, .ri_uohm = 128000 },
406406
{ .vbat_uv = 4325000, .ri_uohm = 130000 },
407407
{ .vbat_uv = 4316000, .ri_uohm = 148000 },

include/linux/power_supply.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,9 @@ struct power_supply_battery_info {
755755
int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX];
756756
struct power_supply_resistance_temp_table *resist_table;
757757
int resist_table_size;
758-
struct power_supply_vbat_ri_table *vbat2ri_discharging;
758+
const struct power_supply_vbat_ri_table *vbat2ri_discharging;
759759
int vbat2ri_discharging_size;
760-
struct power_supply_vbat_ri_table *vbat2ri_charging;
760+
const struct power_supply_vbat_ri_table *vbat2ri_charging;
761761
int vbat2ri_charging_size;
762762
int bti_resistance_ohm;
763763
int bti_resistance_tolerance;

0 commit comments

Comments
 (0)