Skip to content

Commit 12c4d55

Browse files
krzkgregkh
authored andcommitted
leds: flash: leds-qcom-flash: Fix registry access after re-bind
commit fab15f5 upstream. Driver in probe() updates each of 'reg_field' with 'reg_base': for (i = 0; i < REG_MAX_COUNT; i++) regs[i].reg += reg_base; 'reg_field' array (under variable 'regs' above) is statically allocated, thus each re-bind would add another 'reg_base' leading to bogus register addresses. Constify the local 'reg_field' array and duplicate it in probe to solve this. Fixes: 96a2e24 ("leds: flash: Add driver to support flash LED module in QCOM PMICs") Cc: stable@vger.kernel.org Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Reviewed-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com> Link: https://lore.kernel.org/r/20250529063335.8785-2-krzysztof.kozlowski@linaro.org Signed-off-by: Lee Jones <lee@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f3a2d06 commit 12c4d55

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/leds/flash/leds-qcom-flash.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ enum {
117117
REG_MAX_COUNT,
118118
};
119119

120-
static struct reg_field mvflash_3ch_regs[REG_MAX_COUNT] = {
120+
static const struct reg_field mvflash_3ch_regs[REG_MAX_COUNT] = {
121121
REG_FIELD(0x08, 0, 7), /* status1 */
122122
REG_FIELD(0x09, 0, 7), /* status2 */
123123
REG_FIELD(0x0a, 0, 7), /* status3 */
@@ -132,7 +132,7 @@ static struct reg_field mvflash_3ch_regs[REG_MAX_COUNT] = {
132132
REG_FIELD(0x58, 0, 2), /* therm_thrsh3 */
133133
};
134134

135-
static struct reg_field mvflash_4ch_regs[REG_MAX_COUNT] = {
135+
static const struct reg_field mvflash_4ch_regs[REG_MAX_COUNT] = {
136136
REG_FIELD(0x06, 0, 7), /* status1 */
137137
REG_FIELD(0x07, 0, 6), /* status2 */
138138
REG_FIELD(0x09, 0, 7), /* status3 */
@@ -855,11 +855,17 @@ static int qcom_flash_led_probe(struct platform_device *pdev)
855855
if (val == FLASH_SUBTYPE_3CH_PM8150_VAL || val == FLASH_SUBTYPE_3CH_PMI8998_VAL) {
856856
flash_data->hw_type = QCOM_MVFLASH_3CH;
857857
flash_data->max_channels = 3;
858-
regs = mvflash_3ch_regs;
858+
regs = devm_kmemdup(dev, mvflash_3ch_regs, sizeof(mvflash_3ch_regs),
859+
GFP_KERNEL);
860+
if (!regs)
861+
return -ENOMEM;
859862
} else if (val == FLASH_SUBTYPE_4CH_VAL) {
860863
flash_data->hw_type = QCOM_MVFLASH_4CH;
861864
flash_data->max_channels = 4;
862-
regs = mvflash_4ch_regs;
865+
regs = devm_kmemdup(dev, mvflash_4ch_regs, sizeof(mvflash_4ch_regs),
866+
GFP_KERNEL);
867+
if (!regs)
868+
return -ENOMEM;
863869

864870
rc = regmap_read(regmap, reg_base + FLASH_REVISION_REG, &val);
865871
if (rc < 0) {
@@ -881,6 +887,7 @@ static int qcom_flash_led_probe(struct platform_device *pdev)
881887
dev_err(dev, "Failed to allocate regmap field, rc=%d\n", rc);
882888
return rc;
883889
}
890+
devm_kfree(dev, regs); /* devm_regmap_field_bulk_alloc() makes copies */
884891

885892
platform_set_drvdata(pdev, flash_data);
886893
mutex_init(&flash_data->lock);

0 commit comments

Comments
 (0)