Skip to content

Commit e9be771

Browse files
tititiou36broonie
authored andcommitted
regulator: qcom_spmi: Constify struct spmi_voltage_range
'struct spmi_voltage_range' are only modified at runtime to compile a field, n_voltages, that could be computed at compile time. So, simplify spmi_calculate_num_voltages() and compute n_voltages at compile time within the SPMI_VOLTAGE_RANGE macro. Constifying these structures moves some data to a read-only section, so increase overall security. On a x86_64, with allmodconfig: Before: ====== text data bss dec hex filename 85437 26776 512 112725 1b855 drivers/regulator/qcom_spmi-regulator.o After: ===== text data bss dec hex filename 86857 24760 512 112129 1b601 drivers/regulator/qcom_spmi-regulator.o Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Link: https://patch.msgid.link/ef2a4b6df61e19470ddf6cbd1f3ca1ce88a3c1a0.1747570556.git.christophe.jaillet@wanadoo.fr Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 9cfdd77 commit e9be771

File tree

1 file changed

+32
-37
lines changed

1 file changed

+32
-37
lines changed

drivers/regulator/qcom_spmi-regulator.c

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ struct spmi_voltage_range {
400400
* so that range[i].set_point_max_uV < range[i+1].set_point_min_uV.
401401
*/
402402
struct spmi_voltage_set_points {
403-
struct spmi_voltage_range *range;
403+
const struct spmi_voltage_range *range;
404404
int count;
405405
unsigned n_voltages;
406406
};
@@ -474,6 +474,9 @@ struct spmi_regulator_data {
474474
.set_point_max_uV = _set_point_max_uV, \
475475
.step_uV = _step_uV, \
476476
.range_sel = _range_sel, \
477+
.n_voltages = (_set_point_max_uV != 0) ? \
478+
((_set_point_max_uV - _set_point_min_uV) / _step_uV) + 1 : \
479+
0, \
477480
}
478481

479482
#define DEFINE_SPMI_SET_POINTS(name) \
@@ -489,110 +492,110 @@ struct spmi_voltage_set_points name##_set_points = { \
489492
* increasing and unique. The set_voltage callback functions expect these
490493
* properties to hold.
491494
*/
492-
static struct spmi_voltage_range pldo_ranges[] = {
495+
static const struct spmi_voltage_range pldo_ranges[] = {
493496
SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500),
494497
SPMI_VOLTAGE_RANGE(3, 1500000, 1550000, 3075000, 3075000, 25000),
495498
SPMI_VOLTAGE_RANGE(4, 1750000, 3100000, 4900000, 4900000, 50000),
496499
};
497500

498-
static struct spmi_voltage_range nldo1_ranges[] = {
501+
static const struct spmi_voltage_range nldo1_ranges[] = {
499502
SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500),
500503
};
501504

502-
static struct spmi_voltage_range nldo2_ranges[] = {
505+
static const struct spmi_voltage_range nldo2_ranges[] = {
503506
SPMI_VOLTAGE_RANGE(0, 375000, 0, 0, 1537500, 12500),
504507
SPMI_VOLTAGE_RANGE(1, 375000, 375000, 768750, 768750, 6250),
505508
SPMI_VOLTAGE_RANGE(2, 750000, 775000, 1537500, 1537500, 12500),
506509
};
507510

508-
static struct spmi_voltage_range nldo3_ranges[] = {
511+
static const struct spmi_voltage_range nldo3_ranges[] = {
509512
SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500),
510513
SPMI_VOLTAGE_RANGE(1, 375000, 0, 0, 1537500, 12500),
511514
SPMI_VOLTAGE_RANGE(2, 750000, 0, 0, 1537500, 12500),
512515
};
513516

514-
static struct spmi_voltage_range ln_ldo_ranges[] = {
517+
static const struct spmi_voltage_range ln_ldo_ranges[] = {
515518
SPMI_VOLTAGE_RANGE(1, 690000, 690000, 1110000, 1110000, 60000),
516519
SPMI_VOLTAGE_RANGE(0, 1380000, 1380000, 2220000, 2220000, 120000),
517520
};
518521

519-
static struct spmi_voltage_range smps_ranges[] = {
522+
static const struct spmi_voltage_range smps_ranges[] = {
520523
SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500),
521524
SPMI_VOLTAGE_RANGE(1, 1550000, 1575000, 3125000, 3125000, 25000),
522525
};
523526

524-
static struct spmi_voltage_range ftsmps_ranges[] = {
527+
static const struct spmi_voltage_range ftsmps_ranges[] = {
525528
SPMI_VOLTAGE_RANGE(0, 0, 350000, 1275000, 1275000, 5000),
526529
SPMI_VOLTAGE_RANGE(1, 0, 1280000, 2040000, 2040000, 10000),
527530
};
528531

529-
static struct spmi_voltage_range ftsmps2p5_ranges[] = {
532+
static const struct spmi_voltage_range ftsmps2p5_ranges[] = {
530533
SPMI_VOLTAGE_RANGE(0, 80000, 350000, 1355000, 1355000, 5000),
531534
SPMI_VOLTAGE_RANGE(1, 160000, 1360000, 2200000, 2200000, 10000),
532535
};
533536

534-
static struct spmi_voltage_range ftsmps426_ranges[] = {
537+
static const struct spmi_voltage_range ftsmps426_ranges[] = {
535538
SPMI_VOLTAGE_RANGE(0, 0, 320000, 1352000, 1352000, 4000),
536539
};
537540

538-
static struct spmi_voltage_range boost_ranges[] = {
541+
static const struct spmi_voltage_range boost_ranges[] = {
539542
SPMI_VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 5550000, 50000),
540543
};
541544

542-
static struct spmi_voltage_range boost_byp_ranges[] = {
545+
static const struct spmi_voltage_range boost_byp_ranges[] = {
543546
SPMI_VOLTAGE_RANGE(0, 2500000, 2500000, 5200000, 5650000, 50000),
544547
};
545548

546-
static struct spmi_voltage_range ult_lo_smps_ranges[] = {
549+
static const struct spmi_voltage_range ult_lo_smps_ranges[] = {
547550
SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500),
548551
SPMI_VOLTAGE_RANGE(1, 750000, 0, 0, 1525000, 25000),
549552
};
550553

551-
static struct spmi_voltage_range ult_ho_smps_ranges[] = {
554+
static const struct spmi_voltage_range ult_ho_smps_ranges[] = {
552555
SPMI_VOLTAGE_RANGE(0, 1550000, 1550000, 2325000, 2325000, 25000),
553556
};
554557

555-
static struct spmi_voltage_range ult_nldo_ranges[] = {
558+
static const struct spmi_voltage_range ult_nldo_ranges[] = {
556559
SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500),
557560
};
558561

559-
static struct spmi_voltage_range ult_pldo_ranges[] = {
562+
static const struct spmi_voltage_range ult_pldo_ranges[] = {
560563
SPMI_VOLTAGE_RANGE(0, 1750000, 1750000, 3337500, 3337500, 12500),
561564
};
562565

563-
static struct spmi_voltage_range pldo660_ranges[] = {
566+
static const struct spmi_voltage_range pldo660_ranges[] = {
564567
SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 3544000, 3544000, 8000),
565568
};
566569

567-
static struct spmi_voltage_range nldo660_ranges[] = {
570+
static const struct spmi_voltage_range nldo660_ranges[] = {
568571
SPMI_VOLTAGE_RANGE(0, 320000, 320000, 1304000, 1304000, 8000),
569572
};
570573

571-
static struct spmi_voltage_range ht_lvpldo_ranges[] = {
574+
static const struct spmi_voltage_range ht_lvpldo_ranges[] = {
572575
SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 2000000, 2000000, 8000),
573576
};
574577

575-
static struct spmi_voltage_range ht_nldo_ranges[] = {
578+
static const struct spmi_voltage_range ht_nldo_ranges[] = {
576579
SPMI_VOLTAGE_RANGE(0, 312000, 312000, 1304000, 1304000, 8000),
577580
};
578581

579-
static struct spmi_voltage_range hfs430_ranges[] = {
582+
static const struct spmi_voltage_range hfs430_ranges[] = {
580583
SPMI_VOLTAGE_RANGE(0, 320000, 320000, 2040000, 2040000, 8000),
581584
};
582585

583-
static struct spmi_voltage_range ht_p150_ranges[] = {
586+
static const struct spmi_voltage_range ht_p150_ranges[] = {
584587
SPMI_VOLTAGE_RANGE(0, 1616000, 1616000, 3304000, 3304000, 8000),
585588
};
586589

587-
static struct spmi_voltage_range ht_p600_ranges[] = {
590+
static const struct spmi_voltage_range ht_p600_ranges[] = {
588591
SPMI_VOLTAGE_RANGE(0, 1704000, 1704000, 1896000, 1896000, 8000),
589592
};
590593

591-
static struct spmi_voltage_range nldo_510_ranges[] = {
594+
static const struct spmi_voltage_range nldo_510_ranges[] = {
592595
SPMI_VOLTAGE_RANGE(0, 320000, 320000, 1304000, 1304000, 8000),
593596
};
594597

595-
static struct spmi_voltage_range ftsmps510_ranges[] = {
598+
static const struct spmi_voltage_range ftsmps510_ranges[] = {
596599
SPMI_VOLTAGE_RANGE(0, 300000, 300000, 1372000, 1372000, 4000),
597600
};
598601

@@ -1676,18 +1679,10 @@ static const struct spmi_regulator_mapping supported_regulators[] = {
16761679

16771680
static void spmi_calculate_num_voltages(struct spmi_voltage_set_points *points)
16781681
{
1679-
unsigned int n;
1680-
struct spmi_voltage_range *range = points->range;
1681-
1682-
for (; range < points->range + points->count; range++) {
1683-
n = 0;
1684-
if (range->set_point_max_uV) {
1685-
n = range->set_point_max_uV - range->set_point_min_uV;
1686-
n = (n / range->step_uV) + 1;
1687-
}
1688-
range->n_voltages = n;
1689-
points->n_voltages += n;
1690-
}
1682+
const struct spmi_voltage_range *range = points->range;
1683+
1684+
for (; range < points->range + points->count; range++)
1685+
points->n_voltages += range->n_voltages;
16911686
}
16921687

16931688
static int spmi_regulator_match(struct spmi_regulator *vreg, u16 force_type)

0 commit comments

Comments
 (0)