public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] greybus: Fix deref of NULL in __gb_lights_flash_brightness_set
@ 2024-03-01 19:04 Mikhail Lobanov
  2024-03-02  9:59 ` Dan Carpenter
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Mikhail Lobanov @ 2024-03-01 19:04 UTC (permalink / raw)
  To: Rui Miguel Silva
  Cc: Mikhail Lobanov, Greg Kroah-Hartman, greybus-dev, linux-staging,
	linux-kernel

Dereference of null pointer in the __gb_lights_flash_brightness_set function.
Assigning the channel the result of executing the get_channel_from_mode function
without checking for NULL may result in an error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 2870b52bae4c ("greybus: lights: add lights implementation")
Signed-off-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
---
 drivers/staging/greybus/light.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index 87d36948c610..929514350947 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -148,10 +148,15 @@ static int __gb_lights_flash_brightness_set(struct gb_channel *channel)
 						GB_CHANNEL_MODE_TORCH);
 
 	/* For not flash we need to convert brightness to intensity */
-	intensity = channel->intensity_uA.min +
+
+	if (channel) {
+		intensity = channel->intensity_uA.min +
 			(channel->intensity_uA.step * channel->led->brightness);
 
-	return __gb_lights_flash_intensity_set(channel, intensity);
+		return __gb_lights_flash_intensity_set(channel, intensity);
+	}
+
+	return 0;
 }
 #else
 static struct gb_channel *get_channel_from_cdev(struct led_classdev *cdev)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-03-06 15:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 19:04 [PATCH] greybus: Fix deref of NULL in __gb_lights_flash_brightness_set Mikhail Lobanov
2024-03-02  9:59 ` Dan Carpenter
2024-03-02 14:57   ` [greybus-dev] " Alex Elder
2024-03-02 15:21     ` Rui Miguel Silva
2024-03-02 15:23   ` Rui Miguel Silva
2024-03-04  6:29     ` Dan Carpenter
2024-03-02 15:18 ` Rui Miguel Silva
2024-03-02 15:31 ` [greybus-dev] " Alex Elder
2024-03-02 16:35   ` Rui Miguel Silva
2024-03-04 13:30     ` Alex Elder
2024-03-04 13:30   ` Alex Elder
2024-03-06  9:21 ` Rui Miguel Silva
2024-03-06 15:29   ` Михаил Лобанов

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox