Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

staging: greybus: fix get_channel_from_mode() failure path

The get_channel_from_mode() function is supposed to return the channel
which matches the mode. But it has a bug where if it doesn't find a
matching channel then it returns the last channel. It should return
NULL instead.

Also remove an unnecessary NULL check on "channel".

Fixes: 2870b52bae4c ("greybus: lights: add lights implementation")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Link: https://lore.kernel.org/r/379c0cb4-39e0-4293-8a18-c7b1298e5420@moroto.mountain
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dan Carpenter and committed by
Greg Kroah-Hartman
34164202 4d44ea3a

+4 -4
+4 -4
drivers/staging/greybus/light.c
··· 100 100 static struct gb_channel *get_channel_from_mode(struct gb_light *light, 101 101 u32 mode) 102 102 { 103 - struct gb_channel *channel = NULL; 103 + struct gb_channel *channel; 104 104 int i; 105 105 106 106 for (i = 0; i < light->channels_count; i++) { 107 107 channel = &light->channels[i]; 108 - if (channel && channel->mode == mode) 109 - break; 108 + if (channel->mode == mode) 109 + return channel; 110 110 } 111 - return channel; 111 + return NULL; 112 112 } 113 113 114 114 static int __gb_lights_flash_intensity_set(struct gb_channel *channel,