greybus: lights: check return of get_channel_from_mode
Subsystems (3)
Rui Miguel Silva
maintainerPATCH v2 1/1 greybus: lights: check return of get_channel_from_mode
If channel for the given node is not found we return null from get_channel_from_mode. Make sure we validate the return pointer before using it in two of the missing places.
This was originally reported in [0]:
Found by Linux Verification Center (linuxtesting.org) with SVACE.
[0] https://lore.kernel.org/all/[email protected]
---
v1[1] -> v2:
GregKh:
- remove overkill WARN_ON and replace it for a dev_err
[1]: https://lore.kernel.org/all/[email protected]/
drivers/staging/greybus/light.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/staging/greybus/light.c +7 -1
@@ -147,6 +147,9 @@ static int __gb_lights_flash_brightness_set(struct gb_channel *channel) channel =get_channel_from_mode (channel->light,GB_CHANNEL_MODE_TORCH ); +if (!channel) +return -EINVAL ; +/* For not flash we need to convert brightness to intensity */ intensity = channel->intensity_uA.min + (channel->intensity_uA.step * channel->led->brightness);
@@ -549,7 +552,10 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) } channel_flash =get_channel_from_mode (light,GB_CHANNEL_MODE_FLASH ); -WARN_ON (!channel_flash); +if (!channel_flash) { +dev_err (dev,"failed to get flash channel from mode\n" ); +return -EINVAL ; + } fled = &channel_flash->fled;
Signature · 1 line
2.44.0
Greg Kroah-Hartman
maintainerQuoted 14 lines · Rui Miguel Silva
If channel for the given node is not found we return null from
get_channel_from_mode. Make sure we validate the return pointer before using it in two of the missing places.This was originally reported in [0]:
Found by Linux Verification Center (linuxtesting.org) with SVACE.[0] https://lore.kernel.org/all/[email protected]
Fixes 2870b52bae4c ("greybus: lights: add lights implementation")Reported-by Mikhail Lobanov <[email protected]>Suggested-by Mikhail Lobanov <[email protected]>Suggested-by Alex Elder <[email protected]>Signed-off-by Rui Miguel Silva <[email protected]>
Quoted 4 lines
---
v1[1] -> v2:
GregKh:
- remove overkillWARN_ONand replace it for adev_err
Thanks for the quick change, now queued up.
greg k-h