greybus: lights: check return of get_channel_from_mode
Subsystems (3)
PATCH 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]
--- drivers/staging/greybus/light.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/staging/greybus/light.c +5 -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,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;
Signature · 1 line
2.44.0
Greg Kroah-Hartman
maintainerQuoted 33 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]>--- drivers/staging/greybus/light.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/staging/greybus/light.c +3
-0@@ -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);
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 556
Quoted 6 lines
drivers/staging/greybus/light.c +2
-1@@ -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
Quoted 36 lines · Greg Kroah-Hartman
Quoted 35 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]>--- drivers/staging/greybus/light.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/staging/greybus/light.c +3
-0@@ -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) }
Quoted 7 lines
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 556
Quoted 4 lines
drivers/staging/greybus/light.c +2
-1channel_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
Quoted 4 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 43 lines · Alex Elder
Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 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]>--- drivers/staging/greybus/light.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/staging/greybus/light.c +3
-0@@ -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)Quoted 8 lines
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 556
Quoted 5 lines
drivers/staging/greybus/light.c +2
-1} 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.
Quoted 2 lines
Greg,
WARN_ON()doesn't normally crash the machine. That said, it's reasonable to remove theWARN_ON().
The huge majority of running Linux systems in the world run with panic-on-warn enabled, including the one in your pocket :(
Quoted 2 lines
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
Quoted 44 lines · Greg Kroah-Hartman
Quoted 43 lines · Alex Elder
Quoted 41 lines · Greg Kroah-Hartman
Quoted 32 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]>--- drivers/staging/greybus/light.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/staging/greybus/light.c +3
-0@@ -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);drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 555
Quoted 5 lines
drivers/staging/greybus/light.c +2
-1@@ -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.
Quoted 5 lines
Quoted 2 lines
Greg,
WARN_ON()doesn't normally crash the machine. That said, it's reasonable to remove theWARN_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
Quoted 8 lines
Quoted 2 lines
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
Hey Alex,
Quoted 45 lines · Alex Elder
Quoted 44 lines · Greg Kroah-Hartman
Quoted 43 lines · Alex Elder
Quoted 41 lines · Greg Kroah-Hartman
Quoted 32 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]>--- drivers/staging/greybus/light.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/staging/greybus/light.c +3
-0@@ -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);drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 555
Quoted 5 lines
drivers/staging/greybus/light.c +2
-1@@ -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.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Greg,
WARN_ON()doesn't normally crash the machine. That said, it's reasonable to remove theWARN_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 thanBUG_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
Quoted 11 lines
-Alex
Quoted 8 lines
Quoted 2 lines
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
Hi Greg,
Quoted 36 lines · Greg Kroah-Hartman
Quoted 35 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]>--- drivers/staging/greybus/light.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/staging/greybus/light.c +3
-0@@ -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) }
Quoted 7 lines
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 556
Quoted 4 lines
drivers/staging/greybus/light.c +2
-1channel_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
Quoted 3 lines
thanks,
greg k-h