Эх сурвалжийг харах

greybus: light: fix incorrect led attribute files allocation

Fix incorrect attribute size when the channel supports fader, as well as
fixing the issue that the attribute list is not null terminated.

Testing Done:
 - Verified by setting brightness and color on red/green/blue leds
   of the device class test board.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
David Lin 9 жил өмнө
parent
commit
0e352343c2

+ 3 - 2
drivers/staging/greybus/light.c

@@ -293,13 +293,14 @@ static int channel_attr_groups_set(struct gb_channel *channel,
 	if (channel->flags & GB_LIGHT_CHANNEL_MULTICOLOR)
 	if (channel->flags & GB_LIGHT_CHANNEL_MULTICOLOR)
 		size++;
 		size++;
 	if (channel->flags & GB_LIGHT_CHANNEL_FADER)
 	if (channel->flags & GB_LIGHT_CHANNEL_FADER)
-		size++;
+		size += 2;
 
 
 	if (!size)
 	if (!size)
 		return 0;
 		return 0;
 
 
 	/* Set attributes based in the channel flags */
 	/* Set attributes based in the channel flags */
-	channel->attrs = kcalloc(size, sizeof(**channel->attrs), GFP_KERNEL);
+	channel->attrs = kcalloc(size + 1, sizeof(**channel->attrs),
+				 GFP_KERNEL);
 	if (!channel->attrs)
 	if (!channel->attrs)
 		return -ENOMEM;
 		return -ENOMEM;
 	channel->attr_group = kcalloc(1, sizeof(*channel->attr_group),
 	channel->attr_group = kcalloc(1, sizeof(*channel->attr_group),