Commit 72b6a2d6 authored by Alina Yu's avatar Alina Yu Committed by Mark Brown

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: default avatarAlina Yu <alina_yu@richtek.com>
Link: https://msgid.link/r/4ce8c4f16f1cf3aa4e5f36c0694dd3c5ccf3cd1c.1716870419.git.alina_yu@richtek.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 1613e604
...@@ -228,6 +228,11 @@ static const struct regulator_ops rtq2208_regulator_ldo_ops = { ...@@ -228,6 +228,11 @@ static const struct regulator_ops rtq2208_regulator_ldo_ops = {
.set_suspend_disable = rtq2208_set_suspend_disable, .set_suspend_disable = rtq2208_set_suspend_disable,
}; };
static struct of_regulator_match rtq2208_ldo_match[] = {
{.name = "ldo2", },
{.name = "ldo1", },
};
static unsigned int rtq2208_of_map_mode(unsigned int mode) static unsigned int rtq2208_of_map_mode(unsigned int mode)
{ {
switch (mode) { switch (mode) {
...@@ -322,8 +327,7 @@ static irqreturn_t rtq2208_irq_handler(int irqno, void *devid) ...@@ -322,8 +327,7 @@ static irqreturn_t rtq2208_irq_handler(int irqno, void *devid)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static int rtq2208_of_get_fixed_voltage(struct device *dev, static int rtq2208_of_get_ldo_dvs_ability(struct device *dev)
struct of_regulator_match *rtq2208_ldo_match, int n_fixed)
{ {
struct device_node *np; struct device_node *np;
struct of_regulator_match *match; struct of_regulator_match *match;
...@@ -338,14 +342,14 @@ static int rtq2208_of_get_fixed_voltage(struct device *dev, ...@@ -338,14 +342,14 @@ static int rtq2208_of_get_fixed_voltage(struct device *dev,
if (!np) if (!np)
np = dev->of_node; np = dev->of_node;
ret = of_regulator_match(dev, np, rtq2208_ldo_match, n_fixed); ret = of_regulator_match(dev, np, rtq2208_ldo_match, ARRAY_SIZE(rtq2208_ldo_match));
of_node_put(np); of_node_put(np);
if (ret < 0) if (ret < 0)
return ret; return ret;
for (i = 0; i < n_fixed; i++) { for (i = 0; i < ARRAY_SIZE(rtq2208_ldo_match); i++) {
match = rtq2208_ldo_match + i; match = rtq2208_ldo_match + i;
init_data = match->init_data; init_data = match->init_data;
rdesc = (struct rtq2208_regulator_desc *)match->driver_data; rdesc = (struct rtq2208_regulator_desc *)match->driver_data;
...@@ -388,8 +392,7 @@ static const struct linear_range rtq2208_vout_range[] = { ...@@ -388,8 +392,7 @@ static const struct linear_range rtq2208_vout_range[] = {
REGULATOR_LINEAR_RANGE(1310000, 181, 255, 10000), REGULATOR_LINEAR_RANGE(1310000, 181, 255, 10000),
}; };
static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, int mtp_sel, static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, int mtp_sel, int idx)
int idx, struct of_regulator_match *rtq2208_ldo_match, int *ldo_idx)
{ {
struct regulator_desc *desc; struct regulator_desc *desc;
static const struct { static const struct {
...@@ -461,8 +464,7 @@ static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, in ...@@ -461,8 +464,7 @@ static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, in
static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int *regulator_idx_table, static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int *regulator_idx_table,
struct rtq2208_regulator_desc *rdesc[RTQ2208_LDO_MAX], struct device *dev) struct rtq2208_regulator_desc *rdesc[RTQ2208_LDO_MAX], struct device *dev)
{ {
struct of_regulator_match rtq2208_ldo_match[2]; int mtp_sel, i, idx, ret;
int mtp_sel, ret, i, idx, ldo_idx = 0;
/* get mtp_sel0 or mtp_sel1 */ /* get mtp_sel0 or mtp_sel1 */
mtp_sel = device_property_read_bool(dev, "richtek,mtp-sel-high"); mtp_sel = device_property_read_bool(dev, "richtek,mtp-sel-high");
...@@ -474,7 +476,7 @@ static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int * ...@@ -474,7 +476,7 @@ static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int *
if (!rdesc[i]) if (!rdesc[i])
return -ENOMEM; return -ENOMEM;
rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx, rtq2208_ldo_match, &ldo_idx); rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx);
/* init ldo dvs ability */ /* init ldo dvs ability */
if (idx >= RTQ2208_LDO2) if (idx >= RTQ2208_LDO2)
...@@ -482,7 +484,7 @@ static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int * ...@@ -482,7 +484,7 @@ static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int *
} }
/* init ldo fixed_uV */ /* init ldo fixed_uV */
ret = rtq2208_of_get_fixed_voltage(dev, rtq2208_ldo_match, ldo_idx); ret = rtq2208_of_get_ldo_dvs_ability(dev);
if (ret) if (ret)
return dev_err_probe(dev, ret, "Failed to get ldo fixed_uV\n"); return dev_err_probe(dev, ret, "Failed to get ldo fixed_uV\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment