public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: lights: avoid NULL deref
@ 2026-01-08 10:37 Chaitanya Mishra
  2026-01-08 10:46 ` Greg KH
  2026-01-08 10:49 ` [PATCH v2] " Chaitanya Mishra
  0 siblings, 2 replies; 11+ messages in thread
From: Chaitanya Mishra @ 2026-01-08 10:37 UTC (permalink / raw)
  To: rmfrfs, johan, elder, gregkh
  Cc: greybus-dev, linux-staging, linux-kernel, chaitanyamishra.ai

gb_lights_light_config() stores channel_count before allocating the
channels array. If kcalloc() fails, gb_lights_release() iterates the
non-zero count and dereferences light->channels, which is NULL.

Allocate channels first and only then publish channels_count so the
cleanup path can't walk a NULL pointer.

Fixes: 2870b52bae4c ("greybus: lights: add lights implementation")
Signed-off-by: Chaitanya Mishra <chaitanyamishra.ai@gmail.com>
---
 drivers/staging/greybus/light.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index e509fdc715db..4c9ad9ea8827 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -1008,14 +1008,14 @@ static int gb_lights_light_config(struct gb_lights *glights, u8 id)
 	if (!strlen(conf.name))
 		return -EINVAL;
 
-	light->channels_count = conf.channel_count;
 	light->name = kstrndup(conf.name, NAMES_MAX, GFP_KERNEL);
 	if (!light->name)
 		return -ENOMEM;
-	light->channels = kcalloc(light->channels_count,
+	light->channels = kcalloc(conf.channel_count,
 				  sizeof(struct gb_channel), GFP_KERNEL);
 	if (!light->channels)
 		return -ENOMEM;
+	light->channels_count = conf.channel_count;
 
 	/* First we collect all the configurations for all channels */
 	for (i = 0; i < light->channels_count; i++) {
-- 
2.50.1 (Apple Git-155)


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

end of thread, other threads:[~2026-01-08 11:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-08 10:37 [PATCH] staging: greybus: lights: avoid NULL deref Chaitanya Mishra
2026-01-08 10:46 ` Greg KH
2026-01-08 10:49 ` [PATCH v2] " Chaitanya Mishra
2026-01-08 11:01   ` Greg KH
2026-01-08 11:03   ` Chaitanya Mishra
2026-01-08 11:17     ` Greg KH
2026-01-08 11:05   ` Rui Miguel Silva
2026-01-08 11:07   ` [PATCH v3] " Chaitanya Mishra
2026-01-08 11:09     ` Chaitanya Mishra
2026-01-08 11:18       ` Greg KH
2026-01-08 11:23     ` Chaitanya Mishra

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