Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 72b6a2d

Browse files
Alina Yubroonie
authored andcommitted
regulator: rtq2208: Fix invalid memory access when devm_of_regulator_put_matches is called
In this patch, a software bug has been fixed. rtq2208_ldo_match is no longer a local variable. It prevents invalid memory access when devm_of_regulator_put_matches is called. Signed-off-by: Alina Yu <alina_yu@richtek.com> Link: https://msgid.link/r/4ce8c4f16f1cf3aa4e5f36c0694dd3c5ccf3cd1c.1716870419.git.alina_yu@richtek.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1613e60 commit 72b6a2d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/regulator/rtq2208-regulator.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ static const struct regulator_ops rtq2208_regulator_ldo_ops = {
228228
.set_suspend_disable = rtq2208_set_suspend_disable,
229229
};
230230

231+
static struct of_regulator_match rtq2208_ldo_match[] = {
232+
{.name = "ldo2", },
233+
{.name = "ldo1", },
234+
};
235+
231236
static unsigned int rtq2208_of_map_mode(unsigned int mode)
232237
{
233238
switch (mode) {
@@ -322,8 +327,7 @@ static irqreturn_t rtq2208_irq_handler(int irqno, void *devid)
322327
return IRQ_HANDLED;
323328
}
324329

325-
static int rtq2208_of_get_fixed_voltage(struct device *dev,
326-
struct of_regulator_match *rtq2208_ldo_match, int n_fixed)
330+
static int rtq2208_of_get_ldo_dvs_ability(struct device *dev)
327331
{
328332
struct device_node *np;
329333
struct of_regulator_match *match;
@@ -338,14 +342,14 @@ static int rtq2208_of_get_fixed_voltage(struct device *dev,
338342
if (!np)
339343
np = dev->of_node;
340344

341-
ret = of_regulator_match(dev, np, rtq2208_ldo_match, n_fixed);
345+
ret = of_regulator_match(dev, np, rtq2208_ldo_match, ARRAY_SIZE(rtq2208_ldo_match));
342346

343347
of_node_put(np);
344348

345349
if (ret < 0)
346350
return ret;
347351

348-
for (i = 0; i < n_fixed; i++) {
352+
for (i = 0; i < ARRAY_SIZE(rtq2208_ldo_match); i++) {
349353
match = rtq2208_ldo_match + i;
350354
init_data = match->init_data;
351355
rdesc = (struct rtq2208_regulator_desc *)match->driver_data;
@@ -388,8 +392,7 @@ static const struct linear_range rtq2208_vout_range[] = {
388392
REGULATOR_LINEAR_RANGE(1310000, 181, 255, 10000),
389393
};
390394

391-
static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, int mtp_sel,
392-
int idx, struct of_regulator_match *rtq2208_ldo_match, int *ldo_idx)
395+
static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, int mtp_sel, int idx)
393396
{
394397
struct regulator_desc *desc;
395398
static const struct {
@@ -461,8 +464,7 @@ static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, in
461464
static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int *regulator_idx_table,
462465
struct rtq2208_regulator_desc *rdesc[RTQ2208_LDO_MAX], struct device *dev)
463466
{
464-
struct of_regulator_match rtq2208_ldo_match[2];
465-
int mtp_sel, ret, i, idx, ldo_idx = 0;
467+
int mtp_sel, i, idx, ret;
466468

467469
/* get mtp_sel0 or mtp_sel1 */
468470
mtp_sel = device_property_read_bool(dev, "richtek,mtp-sel-high");
@@ -474,15 +476,15 @@ static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int *
474476
if (!rdesc[i])
475477
return -ENOMEM;
476478

477-
rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx, rtq2208_ldo_match, &ldo_idx);
479+
rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx);
478480

479481
/* init ldo dvs ability */
480482
if (idx >= RTQ2208_LDO2)
481483
rtq2208_ldo_match[idx - RTQ2208_LDO2].desc = &rdesc[i]->desc;
482484
}
483485

484486
/* init ldo fixed_uV */
485-
ret = rtq2208_of_get_fixed_voltage(dev, rtq2208_ldo_match, ldo_idx);
487+
ret = rtq2208_of_get_ldo_dvs_ability(dev);
486488
if (ret)
487489
return dev_err_probe(dev, ret, "Failed to get ldo fixed_uV\n");
488490

0 commit comments

Comments
 (0)