diff options
author | Dan Carpenter <dan.carpenter@linaro.org> | 2024-03-04 10:04:48 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-03-05 13:59:36 +0000 |
commit | 34164202a5827f60a203ca9acaf2d9f7d432aac8 (patch) | |
tree | cc027910dfa741e89d112494d043a85e623f319f /drivers/staging | |
parent | 4d44ea3a61c20faedc042874489c2758ae5daca0 (diff) | |
download | linux-34164202a5827f60a203ca9acaf2d9f7d432aac8.tar.gz |
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>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/greybus/light.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c index 87d36948c6106..c6bd86a5335ab 100644 --- a/drivers/staging/greybus/light.c +++ b/drivers/staging/greybus/light.c @@ -100,15 +100,15 @@ static struct led_classdev *get_channel_cdev(struct gb_channel *channel) static struct gb_channel *get_channel_from_mode(struct gb_light *light, u32 mode) { - struct gb_channel *channel = NULL; + struct gb_channel *channel; int i; for (i = 0; i < light->channels_count; i++) { channel = &light->channels[i]; - if (channel && channel->mode == mode) - break; + if (channel->mode == mode) + return channel; } - return channel; + return NULL; } static int __gb_lights_flash_intensity_set(struct gb_channel *channel, |