* [PATCH v2] greybus: lights: check return of get_channel_from_mode
@ 2024-03-25 22:09 Rui Miguel Silva
2024-03-26 8:27 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Rui Miguel Silva @ 2024-03-25 22:09 UTC (permalink / raw)
To: Greg Kroah-Hartman, greybus-dev
Cc: Mikhail Lobanov, linux-staging, Alex Elder, 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/20240301190425.120605-1-m.lobanov@rosalinux.ru
Fixes: 2870b52bae4c ("greybus: lights: add lights implementation")
Reported-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
Suggested-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
Suggested-by: Alex Elder <elder@ieee.org>
Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
v1[1] -> v2:
GregKh:
- remove overkill WARN_ON and replace it for a dev_err
[1]: https://lore.kernel.org/all/20240307094838.688281-1-rmfrfs@gmail.com/
drivers/staging/greybus/light.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index c6bd86a5335a..9999f8401699 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -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;
--
2.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] greybus: lights: check return of get_channel_from_mode
2024-03-25 22:09 [PATCH v2] greybus: lights: check return of get_channel_from_mode Rui Miguel Silva
@ 2024-03-26 8:27 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2024-03-26 8:27 UTC (permalink / raw)
To: Rui Miguel Silva; +Cc: greybus-dev, Mikhail Lobanov, linux-staging, Alex Elder
On Mon, Mar 25, 2024 at 10:09:55PM +0000, Rui Miguel Silva wrote:
> 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/20240301190425.120605-1-m.lobanov@rosalinux.ru
>
> Fixes: 2870b52bae4c ("greybus: lights: add lights implementation")
> Reported-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
> Suggested-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
> Suggested-by: Alex Elder <elder@ieee.org>
> Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com>
> ---
> v1[1] -> v2:
> GregKh:
> - remove overkill WARN_ON and replace it for a dev_err
Thanks for the quick change, now queued up.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-26 8:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-25 22:09 [PATCH v2] greybus: lights: check return of get_channel_from_mode Rui Miguel Silva
2024-03-26 8:27 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox