From 0e352343c2e371ad618d8850f542e9ca230e3aa6 Mon Sep 17 00:00:00 2001 From: David Lin Date: Mon, 22 Aug 2016 15:51:11 -0700 Subject: 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 Reviewed-by: Rui Miguel Silva Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/light.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/staging/greybus/light.c') diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c index a57d59339bd6..85bf5559f6fb 100644 --- a/drivers/staging/greybus/light.c +++ b/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) size++; if (channel->flags & GB_LIGHT_CHANNEL_FADER) - size++; + size += 2; if (!size) return 0; /* 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) return -ENOMEM; channel->attr_group = kcalloc(1, sizeof(*channel->attr_group), -- cgit v1.2.3