leds: spi-byte: Initialize device node before access
Subsystems (2)
PATCH RESEND 1/1 leds: spi-byte: Initialize device node before access
Commit 7f9ab862e05c ("leds: spi-byte: Call of_node_put() on error path") was merged in 6.11 and then backported to stable trees through 5.10. It relocates the line that initializes the variable 'child' to a later point in spi_byte_probe().
Versions < 6.9 do not have commit ccc35ff2fd29 ("leds: spi-byte: Use devm_led_classdev_register_ext()"), which removes a line that reads a property from 'child' before its new initialization point. Consequently, spi_byte_probe() reads from an uninitialized device node in stable kernels 6.6-5.10.
Initialize 'child' before it is first accessed.
---
As an alternative to moving the initialization of 'child' up, Fedor Pchelkin proposed [1] backporting the change that removes the intermediate access.
[1] https://lore.kernel.org/stable/[email protected]/
--- drivers/leds/leds-spi-byte.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-spi-byte.c +1 -1
@@ -96,6 +96,7 @@ static int spi_byte_probe(struct spi_device *spi)if (!led)return -ENOMEM ; + child =of_get_next_available_child (dev_of_node (dev),NULL );of_property_read_string (child,"label" , &name);strscpy (led->name, name,sizeof (led->name)); led->spi = spi;
@@ -106,7 +107,6 @@ static int spi_byte_probe(struct spi_device *spi) led->ldev.max_brightness = led->cdef->max_value - led->cdef->off_value; led->ldev.brightness_set_blocking = spi_byte_brightness_set_blocking; - child =of_get_next_available_child (dev_of_node (dev),NULL ); state =of_get_property (child,"default-state" ,NULL );if (state) {if (!strcmp (state,"on" )) {
Signature · 1 line
2.52.0.351.gbe84eed79e-goog
Quoted 10 lines · Tiffany Yang
Commit
7f9ab862e05c("leds: spi-byte: Callof_node_put()on error path") was merged in 6.11 and then backported to stable trees through 5.10. It relocates the line that initializes the variable 'child' to a later point inspi_byte_probe().Versions < 6.9 do not have commit
ccc35ff2fd29("leds: spi-byte: Usedevm_led_classdev_register_ext()"), which removes a line that reads a property from 'child' before its new initialization point. Consequently,spi_byte_probe()reads from an uninitialized device node in stable kernels 6.6-5.10.
I'm wondering if in long term the easier maintenance will be with that patch also being backported rather than this being applied.
Quoted 1 line
Initialize 'child' before it is first accessed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Tiffany Yang
Commit
7f9ab862e05c("leds: spi-byte: Callof_node_put()on error path") was merged in 6.11 and then backported to stable trees through 5.10. It relocates the line that initializes the variable 'child' to a later point inspi_byte_probe().
Quoted 8 lines
Quoted 5 lines
Versions < 6.9 do not have commit
ccc35ff2fd29("leds: spi-byte: Usedevm_led_classdev_register_ext()"), which removes a line that reads a property from 'child' before its new initialization point. Consequently,spi_byte_probe()reads from an uninitialized device node in stable kernels 6.6-5.10.I'm wondering if in long term the easier maintenance will be with that patch also being backported rather than this being applied.
I agree, that might be simplest.
thanks,
greg k-h
Lee Jones
maintainerQuoted 6 lines · Andy Shevchenko
Quoted 5 lines · Tiffany Yang
Commit
7f9ab862e05c("leds: spi-byte: Callof_node_put()on error path") was merged in 6.11 and then backported to stable trees through 5.10. It relocates the line that initializes the variable 'child' to a later point inspi_byte_probe().
Quoted 8 lines
Quoted 5 lines
Versions < 6.9 do not have commit
ccc35ff2fd29("leds: spi-byte: Usedevm_led_classdev_register_ext()"), which removes a line that reads a property from 'child' before its new initialization point. Consequently,spi_byte_probe()reads from an uninitialized device node in stable kernels 6.6-5.10.I'm wondering if in long term the easier maintenance will be with that patch also being backported rather than this being applied.
Works for me.
Signature · 1 line
Lee Jones [李琼斯]
Quoted 12 lines · Lee Jones
Quoted 10 lines · Andy Shevchenko
Quoted 1 line · Tiffany Yang
Commit
7f9ab862e05c("leds: spi-byte: Callof_node_put()on errorpath")
Quoted 7 lines
was merged in 6.11 and then backported to stable trees through 5.10. It relocates the line that initializes the variable 'child' to a later point in
spi_byte_probe().Versions < 6.9 do not have commit
ccc35ff2fd29("leds: spi-byte: Usedevm_led_classdev_register_ext()"), which removes a line that reads a property from 'child' before its new initialization point.
Quoted 8 lines
Quoted 6 lines
Consequently,
Quoted 2 lines
spi_byte_probe()reads from an uninitialized device node in stable kernels 6.6-5.10.I'm wondering if in long term the easier maintenance will be with that patch also being backported rather than this being applied.
Works for me.
Makes sense to me too! Thanks everyone for taking a look, and thanks to Fedor for originally suggesting this :)
Signature · 1 line
Tiffany Y. Yang