* [PATCH] greybus: lights: check return of get_channel_from_mode
@ 2024-03-07 9:48 Rui Miguel Silva
2024-03-25 17:25 ` Greg Kroah-Hartman
0 siblings, 1 reply; 7+ messages in thread
From: Rui Miguel Silva @ 2024-03-07 9:48 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>
---
drivers/staging/greybus/light.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index c6bd86a5335a..6f10b9e2c053 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,8 @@ 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 (WARN_ON(!channel_flash))
+ return -EINVAL;
fled = &channel_flash->fled;
--
2.44.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] greybus: lights: check return of get_channel_from_mode 2024-03-07 9:48 [PATCH] greybus: lights: check return of get_channel_from_mode Rui Miguel Silva @ 2024-03-25 17:25 ` Greg Kroah-Hartman 2024-03-25 18:31 ` Alex Elder 2024-03-25 19:04 ` Rui Miguel Silva 0 siblings, 2 replies; 7+ messages in thread From: Greg Kroah-Hartman @ 2024-03-25 17:25 UTC (permalink / raw) To: Rui Miguel Silva Cc: greybus-dev, Mikhail Lobanov, linux-staging, Alex Elder, Rui Miguel Silva On Thu, Mar 07, 2024 at 09:48:13AM +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> > --- > drivers/staging/greybus/light.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c > index c6bd86a5335a..6f10b9e2c053 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,8 @@ 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 (WARN_ON(!channel_flash)) > + return -EINVAL; We should NOT crash machines just because of this, the WARN_ON() should be removed and just properly handle the error please. thanks, greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] greybus: lights: check return of get_channel_from_mode 2024-03-25 17:25 ` Greg Kroah-Hartman @ 2024-03-25 18:31 ` Alex Elder 2024-03-25 18:50 ` Greg Kroah-Hartman 2024-03-25 19:04 ` Rui Miguel Silva 1 sibling, 1 reply; 7+ messages in thread From: Alex Elder @ 2024-03-25 18:31 UTC (permalink / raw) To: Greg Kroah-Hartman, Rui Miguel Silva Cc: greybus-dev, Mikhail Lobanov, linux-staging, Rui Miguel Silva On 3/25/24 12:25 PM, Greg Kroah-Hartman wrote: > On Thu, Mar 07, 2024 at 09:48:13AM +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> >> --- >> drivers/staging/greybus/light.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c >> index c6bd86a5335a..6f10b9e2c053 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,8 @@ 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 (WARN_ON(!channel_flash)) >> + return -EINVAL; > > We should NOT crash machines just because of this, the WARN_ON() should > be removed and just properly handle the error please. Greg, WARN_ON() doesn't normally crash the machine. That said, it's reasonable to remove the WARN_ON(). I think the purpose of the warning is that this is a case that should "never happen," so if it does, it's making some noise. The only caller is gb_lights_light_register(), and it checks for an error and does "properly handle" the\ error (assuming any error meaning "light has no flash" is correct). Rui, please weigh in. -Alex > > thanks, > > greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] greybus: lights: check return of get_channel_from_mode 2024-03-25 18:31 ` Alex Elder @ 2024-03-25 18:50 ` Greg Kroah-Hartman 2024-03-25 18:55 ` Alex Elder 0 siblings, 1 reply; 7+ messages in thread From: Greg Kroah-Hartman @ 2024-03-25 18:50 UTC (permalink / raw) To: Alex Elder Cc: Rui Miguel Silva, greybus-dev, Mikhail Lobanov, linux-staging, Rui Miguel Silva On Mon, Mar 25, 2024 at 01:31:34PM -0500, Alex Elder wrote: > On 3/25/24 12:25 PM, Greg Kroah-Hartman wrote: > > On Thu, Mar 07, 2024 at 09:48:13AM +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> > > > --- > > > drivers/staging/greybus/light.c | 6 +++++- > > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c > > > index c6bd86a5335a..6f10b9e2c053 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,8 @@ 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 (WARN_ON(!channel_flash)) > > > + return -EINVAL; > > > > We should NOT crash machines just because of this, the WARN_ON() should > > be removed and just properly handle the error please. > > Greg, WARN_ON() doesn't normally crash the machine. That said, > it's reasonable to remove the WARN_ON(). The huge majority of running Linux systems in the world run with panic-on-warn enabled, including the one in your pocket :( > I think the purpose of the warning is that this is a case that > should "never happen," so if it does, it's making some noise. Making noise by rebooting the box is not good. thanks, greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] greybus: lights: check return of get_channel_from_mode 2024-03-25 18:50 ` Greg Kroah-Hartman @ 2024-03-25 18:55 ` Alex Elder 2024-03-25 19:08 ` Rui Miguel Silva 0 siblings, 1 reply; 7+ messages in thread From: Alex Elder @ 2024-03-25 18:55 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rui Miguel Silva, greybus-dev, Mikhail Lobanov, linux-staging, Rui Miguel Silva On 3/25/24 1:50 PM, Greg Kroah-Hartman wrote: > On Mon, Mar 25, 2024 at 01:31:34PM -0500, Alex Elder wrote: >> On 3/25/24 12:25 PM, Greg Kroah-Hartman wrote: >>> On Thu, Mar 07, 2024 at 09:48:13AM +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> >>>> --- >>>> drivers/staging/greybus/light.c | 6 +++++- >>>> 1 file changed, 5 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c >>>> index c6bd86a5335a..6f10b9e2c053 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,8 @@ 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 (WARN_ON(!channel_flash)) >>>> + return -EINVAL; >>> >>> We should NOT crash machines just because of this, the WARN_ON() should >>> be removed and just properly handle the error please. >> >> Greg, WARN_ON() doesn't normally crash the machine. That said, >> it's reasonable to remove the WARN_ON(). > > The huge majority of running Linux systems in the world run with > panic-on-warn enabled, including the one in your pocket :( I did not know that. Then WARN_ON() is no better than BUG_ON(). I'm still learning. Thank you. -Alex >> I think the purpose of the warning is that this is a case that >> should "never happen," so if it does, it's making some noise. > > Making noise by rebooting the box is not good. > > thanks, > > greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] greybus: lights: check return of get_channel_from_mode 2024-03-25 18:55 ` Alex Elder @ 2024-03-25 19:08 ` Rui Miguel Silva 0 siblings, 0 replies; 7+ messages in thread From: Rui Miguel Silva @ 2024-03-25 19:08 UTC (permalink / raw) To: Alex Elder, Greg Kroah-Hartman Cc: greybus-dev, Mikhail Lobanov, linux-staging Hey Alex, Alex Elder <elder@ieee.org> writes: > On 3/25/24 1:50 PM, Greg Kroah-Hartman wrote: >> On Mon, Mar 25, 2024 at 01:31:34PM -0500, Alex Elder wrote: >>> On 3/25/24 12:25 PM, Greg Kroah-Hartman wrote: >>>> On Thu, Mar 07, 2024 at 09:48:13AM +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> >>>>> --- >>>>> drivers/staging/greybus/light.c | 6 +++++- >>>>> 1 file changed, 5 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c >>>>> index c6bd86a5335a..6f10b9e2c053 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,8 @@ 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 (WARN_ON(!channel_flash)) >>>>> + return -EINVAL; >>>> >>>> We should NOT crash machines just because of this, the WARN_ON() should >>>> be removed and just properly handle the error please. >>> >>> Greg, WARN_ON() doesn't normally crash the machine. That said, >>> it's reasonable to remove the WARN_ON(). >> >> The huge majority of running Linux systems in the world run with >> panic-on-warn enabled, including the one in your pocket :( > > I did not know that. Then WARN_ON() is no better than BUG_ON(). > I'm still learning. Thank you. I also lost track of all this failure cascade options that normally take the all system down. Thanks anyway for the comments, Cheers, Rui > > -Alex > >>> I think the purpose of the warning is that this is a case that >>> should "never happen," so if it does, it's making some noise. >> >> Making noise by rebooting the box is not good. >> >> thanks, >> >> greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] greybus: lights: check return of get_channel_from_mode 2024-03-25 17:25 ` Greg Kroah-Hartman 2024-03-25 18:31 ` Alex Elder @ 2024-03-25 19:04 ` Rui Miguel Silva 1 sibling, 0 replies; 7+ messages in thread From: Rui Miguel Silva @ 2024-03-25 19:04 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: greybus-dev, Mikhail Lobanov, linux-staging, Alex Elder Hi Greg, Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes: > On Thu, Mar 07, 2024 at 09:48:13AM +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> >> --- >> drivers/staging/greybus/light.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c >> index c6bd86a5335a..6f10b9e2c053 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,8 @@ 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 (WARN_ON(!channel_flash)) >> + return -EINVAL; > > We should NOT crash machines just because of this, the WARN_ON() should > be removed and just properly handle the error please. Yeah, will move this to a less severe option (dev_err) to make some noise about this "this should never happen" issue. Cheers, Rui > thanks, > > greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-25 19:08 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-03-07 9:48 [PATCH] greybus: lights: check return of get_channel_from_mode Rui Miguel Silva 2024-03-25 17:25 ` Greg Kroah-Hartman 2024-03-25 18:31 ` Alex Elder 2024-03-25 18:50 ` Greg Kroah-Hartman 2024-03-25 18:55 ` Alex Elder 2024-03-25 19:08 ` Rui Miguel Silva 2024-03-25 19:04 ` Rui Miguel Silva
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox