mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
leds: leds-st1202: Fix NULL pointer access on race condition
st1202_dt_init() calls devm_led_classdev_register_ext() before the
internal data structures are properly set up, so the LEDs become visible
to user space while being partially initialized, leading to a window
where trying to access them causes a NULL pointer access.
Move devm_led_classdev_register_ext() from DT initialization
to the end of the probe function when DT and hardware are fully
initialized and ready to interact with user space.
Fixes: 259230378c ("leds: Add LED1202 I2C driver")
Signed-off-by: Manuel Fombuena <fombuena@outlook.com>
Link: https://lore.kernel.org/r/CWLP123MB54732771AC0CE5491B3C84DCC5C32@CWLP123MB5473.GBRP123.PROD.OUTLOOK.COM
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
committed by
Lee Jones
parent
2014c95afe
commit
c72e455b89
@@ -261,8 +261,6 @@ static int st1202_dt_init(struct st1202_chip *chip)
|
||||
int err, reg;
|
||||
|
||||
for_each_available_child_of_node_scoped(dev_of_node(dev), child) {
|
||||
struct led_init_data init_data = {};
|
||||
|
||||
err = of_property_read_u32(child, "reg", ®);
|
||||
if (err)
|
||||
return dev_err_probe(dev, err, "Invalid register\n");
|
||||
@@ -276,15 +274,6 @@ static int st1202_dt_init(struct st1202_chip *chip)
|
||||
led->led_cdev.pattern_set = st1202_led_pattern_set;
|
||||
led->led_cdev.pattern_clear = st1202_led_pattern_clear;
|
||||
led->led_cdev.default_trigger = "pattern";
|
||||
|
||||
init_data.fwnode = led->fwnode;
|
||||
init_data.devicename = "st1202";
|
||||
init_data.default_label = ":";
|
||||
|
||||
err = devm_led_classdev_register_ext(dev, &led->led_cdev, &init_data);
|
||||
if (err < 0)
|
||||
return dev_err_probe(dev, err, "Failed to register LED class device\n");
|
||||
|
||||
led->led_cdev.brightness_set = st1202_brightness_set;
|
||||
led->led_cdev.brightness_get = st1202_brightness_get;
|
||||
}
|
||||
@@ -368,6 +357,7 @@ static int st1202_probe(struct i2c_client *client)
|
||||
return ret;
|
||||
|
||||
for (int i = 0; i < ST1202_MAX_LEDS; i++) {
|
||||
struct led_init_data init_data = {};
|
||||
led = &chip->leds[i];
|
||||
led->chip = chip;
|
||||
led->led_num = i;
|
||||
@@ -384,6 +374,15 @@ static int st1202_probe(struct i2c_client *client)
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&client->dev, ret,
|
||||
"Failed to clear LED pattern\n");
|
||||
|
||||
init_data.fwnode = led->fwnode;
|
||||
init_data.devicename = "st1202";
|
||||
init_data.default_label = ":";
|
||||
|
||||
ret = devm_led_classdev_register_ext(&client->dev, &led->led_cdev, &init_data);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&client->dev, ret,
|
||||
"Failed to register LED class device\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user