linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: fix a missing check of return value of lp55xx_read
@ 2018-12-26  4:18 Kangjie Lu
  2018-12-28 16:52 ` Jacek Anaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Kangjie Lu @ 2018-12-26  4:18 UTC (permalink / raw)
  To: kjlu; +Cc: pakki001, Jacek Anaszewski, Pavel Machek, linux-leds,
	linux-kernel

When lp55xx_read() fails, "status" is an uninitialized variable and thus
may contain random value; using it leads to undefined behaviors.

The fix inserts a check for the return value of lp55xx_read: if it
fails, returns with its error code.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/leds/leds-lp5523.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index a2e74feee2b2..fd64df5a57a5 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -318,7 +318,9 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip)
 
 	/* Let the programs run for couple of ms and check the engine status */
 	usleep_range(3000, 6000);
-	lp55xx_read(chip, LP5523_REG_STATUS, &status);
+	ret = lp55xx_read(chip, LP5523_REG_STATUS, &status);
+	if (ret)
+		return ret;
 	status &= LP5523_ENG_STATUS_MASK;
 
 	if (status != LP5523_ENG_STATUS_MASK) {
-- 
2.17.2 (Apple Git-113)

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

* Re: [PATCH] leds: fix a missing check of return value of lp55xx_read
  2018-12-26  4:18 [PATCH] leds: fix a missing check of return value of lp55xx_read Kangjie Lu
@ 2018-12-28 16:52 ` Jacek Anaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Jacek Anaszewski @ 2018-12-28 16:52 UTC (permalink / raw)
  To: Kangjie Lu; +Cc: pakki001, Pavel Machek, linux-leds, linux-kernel

Hi Kangjie,

Thank you for the patch.

On 12/26/18 5:18 AM, Kangjie Lu wrote:
> When lp55xx_read() fails, "status" is an uninitialized variable and thus
> may contain random value; using it leads to undefined behaviors.
> 
> The fix inserts a check for the return value of lp55xx_read: if it
> fails, returns with its error code.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>   drivers/leds/leds-lp5523.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
> index a2e74feee2b2..fd64df5a57a5 100644
> --- a/drivers/leds/leds-lp5523.c
> +++ b/drivers/leds/leds-lp5523.c
> @@ -318,7 +318,9 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip)
>   
>   	/* Let the programs run for couple of ms and check the engine status */
>   	usleep_range(3000, 6000);
> -	lp55xx_read(chip, LP5523_REG_STATUS, &status);
> +	ret = lp55xx_read(chip, LP5523_REG_STATUS, &status);
> +	if (ret)
> +		return ret;
>   	status &= LP5523_ENG_STATUS_MASK;
>   
>   	if (status != LP5523_ENG_STATUS_MASK) {
> 

Applied to fixes-for-4.21 branch of linux-leds.git.

-- 
Best regards,
Jacek Anaszewski

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

end of thread, other threads:[~2018-12-28 16:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-26  4:18 [PATCH] leds: fix a missing check of return value of lp55xx_read Kangjie Lu
2018-12-28 16:52 ` Jacek Anaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).