backlight: lm3630a: Use scoped iterator to simplify error handling
Subsystems (3)
PATCH 1/1 backlight: lm3630a: Use scoped iterator to simplify error handling
This avoids the need to manually call fwnode_handle_put() in error paths. Prevents potential memory leaks if future error paths forget the cleanup.
--- drivers/video/backlight/lm3630a_bl.c | 121 +++++++++++++-------------- 1 file changed, 56 insertions(+), 65 deletions(-)
drivers/video/backlight/lm3630a_bl.c +24 -26
@@ -16,29 +16,29 @@#include <linux/pwm.h> #include <linux/platform_data/lm3630a_bl.h> -#define REG_CTRL 0x00 -#define REG_BOOST 0x02 -#define REG_CONFIG 0x01 -#define REG_BRT_A 0x03 -#define REG_BRT_B 0x04 -#define REG_I_A 0x05 -#define REG_I_B 0x06 -#define REG_INT_STATUS 0x09 -#define REG_INT_EN 0x0A -#define REG_FAULT 0x0B -#define REG_PWM_OUTLOW 0x12 -#define REG_PWM_OUTHIGH 0x13 -#define REG_FILTER_STRENGTH 0x50 -#define REG_MAX 0x50 - -#define INT_DEBOUNCE_MSEC 10 - -#define LM3630A_BANK_0 0 -#define LM3630A_BANK_1 1 - -#define LM3630A_NUM_SINKS 2 -#define LM3630A_SINK_0 0 -#define LM3630A_SINK_1 1 +#define REG_CTRL 0x00 +#define REG_BOOST 0x02 +#define REG_CONFIG 0x01 +#define REG_BRT_A 0x03 +#define REG_BRT_B 0x04 +#define REG_I_A 0x05 +#define REG_I_B 0x06 +#define REG_INT_STATUS 0x09 +#define REG_INT_EN 0x0A +#define REG_FAULT 0x0B +#define REG_PWM_OUTLOW 0x12 +#define REG_PWM_OUTHIGH 0x13 +#define REG_FILTER_STRENGTH 0x50 +#define REG_MAX 0x50 + +#define INT_DEBOUNCE_MSEC 10 + +#define LM3630A_BANK_0 0 +#define LM3630A_BANK_1 1 + +#define LM3630A_NUM_SINKS 2 +#define LM3630A_SINK_0 0 +#define LM3630A_SINK_1 1
@@ -479,12 +473,10 @@ static int lm3630a_parse_node(struct lm3630a_chip *pchip, struct lm3630a_platform_data *pdata) {int ret = -ENODEV , seen_led_sources =0 ; -struct fwnode_handle *node; -device_for_each_child_node (pchip->dev, node) { +device_for_each_child_node_scoped (pchip->dev, node) { ret =lm3630a_parse_bank (pdata, node, &seen_led_sources);if (ret) { -fwnode_handle_put (node);return ret; } }
MODULE_DEVICE_TABLE(i2c, lm3630a_id);
static const struct of_device_id lm3630a_match_table[] = {
- { .compatible = "ti,lm3630a", },
- { },
+ {
+ .compatible = "ti,lm3630a",
+ },
+ {},
};
MODULE_DEVICE_TABLE(of, lm3630a_match_table);
Signature · 1 line
2.50.1
Jonathan Cameron
maintainerQuoted 4 lines · On Sat, 19 Jul 2025 01:21:02 -0300 Andre Luiz da Nobrega…
This avoids the need to manually call
fwnode_handle_put()in error paths. Prevents potential memory leaks if future error paths forget the cleanup.Signed-off-by Andre Luiz da Nobrega <[email protected]>
No idea why you sent this to linux-iio. Check MAINTAINERS for appropriate lists and maintainers to send it to.
Given it's in front of me, a few comments.
Quoted 48 lines
--- drivers/video/backlight/lm3630a_bl.c | 121 +++++++++++++-------------- 1 file changed, 56 insertions(+), 65 deletions(-)drivers/video/backlight/lm3630a_bl.c +13
-23@@ -16,29 +16,29 @@#include <linux/pwm.h> #include <linux/platform_data/lm3630a_bl.h> -#define REG_CTRL 0x00 -#define REG_BOOST 0x02 -#define REG_CONFIG 0x01 -#define REG_BRT_A 0x03 -#define REG_BRT_B 0x04 -#define REG_I_A 0x05 -#define REG_I_B 0x06 -#define REG_INT_STATUS 0x09 -#define REG_INT_EN 0x0A -#define REG_FAULT 0x0B -#define REG_PWM_OUTLOW 0x12 -#define REG_PWM_OUTHIGH 0x13 -#define REG_FILTER_STRENGTH 0x50 -#define REG_MAX 0x50 - -#define INT_DEBOUNCE_MSEC 10 - -#define LM3630A_BANK_0 0 -#define LM3630A_BANK_1 1 - -#define LM3630A_NUM_SINKS 2 -#define LM3630A_SINK_0 0 -#define LM3630A_SINK_1 1 +#define REG_CTRL 0x00 +#define REG_BOOST 0x02 +#define REG_CONFIG 0x01 +#define REG_BRT_A 0x03 +#define REG_BRT_B 0x04 +#define REG_I_A 0x05 +#define REG_I_B 0x06 +#define REG_INT_STATUS 0x09 +#define REG_INT_EN 0x0A +#define REG_FAULT 0x0B +#define REG_PWM_OUTLOW 0x12 +#define REG_PWM_OUTHIGH 0x13 +#define REG_FILTER_STRENGTH 0x50
drivers/video/backlight/lm3630a_bl.c line 41
Quoted 10 lines
drivers/video/backlight/lm3630a_bl.c +10
-0+#define REG_MAX 0x50 + +#define INT_DEBOUNCE_MSEC 10 + +#define LM3630A_BANK_0 0 +#define LM3630A_BANK_1 1 + +#define LM3630A_NUM_SINKS 2 +#define LM3630A_SINK_0 0 +#define LM3630A_SINK_1 1
Don't reformat this stuff in a patch doing anything other than that. It's noise that makes the patch hard to read.
Quoted 5 lines
drivers/video/backlight/lm3630a_bl.c +0
-0@@ -479,12 +473,10 @@ static int lm3630a_parse_node(struct lm3630a_chip *pchip, struct lm3630a_platform_data *pdata) {
drivers/video/backlight/lm3630a_bl.c static int lm3630a_parse_node(struct lm3630a_chip *pchip, · line 481
Quoted 10 lines
drivers/video/backlight/lm3630a_bl.c +1
-3int ret = -ENODEV , seen_led_sources =0 ; -struct fwnode_handle *node; -device_for_each_child_node (pchip->dev, node) { +device_for_each_child_node_scoped (pchip->dev, node) { ret =lm3630a_parse_bank (pdata, node, &seen_led_sources);if (ret) { -fwnode_handle_put (node);return ret; }
Drop {} to comply with standard kernel style.
Quoted 17 lines
drivers/video/backlight/lm3630a_bl.c +0
-0}
MODULE_DEVICE_TABLE(i2c, lm3630a_id);static const struct
of_device_idlm3630a_match_table[] = {drivers/video/backlight/lm3630a_bl.c +4
-2- { .compatible = "ti,lm3630a", }, - { }, + { + .compatible = "ti,lm3630a", + }, + {}, };MODULE_DEVICE_TABLE (of, lm3630a_match_table);