Re: [PATCH] leds: lp55xx: Fix check for invalid channel number

From: Michal Vokáč
Date: Thu Oct 10 2024 - 04:12:27 EST


On 10. 10. 24 8:00, kernel test robot wrote:

vim +1130 drivers/leds/leds-lp55xx-common.c

1111
1112 static int lp55xx_parse_common_child(struct device_node *np,
1113 struct lp55xx_led_config *cfg,
1114 int led_number, int *chan_nr)
1115 {
1116 int ret;
1117
1118 of_property_read_string(np, "chan-name",
1119 &cfg[led_number].name);
1120 of_property_read_u8(np, "led-cur",
1121 &cfg[led_number].led_current);
1122 of_property_read_u8(np, "max-cur",
1123 &cfg[led_number].max_current);
1124
1125 ret = of_property_read_u32(np, "reg", chan_nr);
1126 if (ret)
1127 return ret;
1128
1129 if (*chan_nr < 0 || *chan_nr >= cfg->max_channel) {
1130 dev_err(dev, "Use channel numbers between 0 and %d\n",

Ahh, rookie mistake. Of course the dev is not available here. I feel dumb
as I think I at least compile tested this..

Anyway, the comparison is wrong and I still think it is not nice to
the user/DT developer to quietly fail here. I suggest to remove this
check here completely and keep the one in the lp55xx_init_led().

Michal

1131 cfg->max_channel - 1);
1132 return -EINVAL;
1133 }
1134
1135 return 0;
1136 }
1137