diff mbox

leds: mt6323: Fix an off by one bug in probe

Message ID 20170323104049.GC20154@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter March 23, 2017, 10:40 a.m. UTC
It should be ">= MT6323_MAX_LEDS" instead of ">".  Also "reg" is a u32
so it can't be negative and we can remove the test for negative values.

Fixes: 216ec6cc4c19 ("leds: Add LED support for MT6323 PMIC")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Pavel Machek March 23, 2017, 11:16 a.m. UTC | #1
On Thu 2017-03-23 13:40:49, Dan Carpenter wrote:
> It should be ">= MT6323_MAX_LEDS" instead of ">".  Also "reg" is a u32
> so it can't be negative and we can remove the test for negative values.
> 
> Fixes: 216ec6cc4c19 ("leds: Add LED support for MT6323 PMIC")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Pavel Machek <pavel@ucw.cz>


> diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
> index 48081bccbea5..8893c74e9a1f 100644
> --- a/drivers/leds/leds-mt6323.c
> +++ b/drivers/leds/leds-mt6323.c
> @@ -417,7 +417,7 @@ static int mt6323_led_probe(struct platform_device *pdev)
>  			goto put_child_node;
>  		}
>  
> -		if (reg < 0 || reg > MT6323_MAX_LEDS || leds->led[reg]) {
> +		if (reg >= MT6323_MAX_LEDS || leds->led[reg]) {
>  			dev_err(dev, "Invalid led reg %u\n", reg);
>  			ret = -EINVAL;
>  			goto put_child_node;
Jacek Anaszewski March 23, 2017, 7:37 p.m. UTC | #2
On 03/23/2017 12:16 PM, Pavel Machek wrote:
> On Thu 2017-03-23 13:40:49, Dan Carpenter wrote:
>> It should be ">= MT6323_MAX_LEDS" instead of ">".  Also "reg" is a u32
>> so it can't be negative and we can remove the test for negative values.
>>
>> Fixes: 216ec6cc4c19 ("leds: Add LED support for MT6323 PMIC")
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Acked-by: Pavel Machek <pavel@ucw.cz>

Applied, thanks.
diff mbox

Patch

diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
index 48081bccbea5..8893c74e9a1f 100644
--- a/drivers/leds/leds-mt6323.c
+++ b/drivers/leds/leds-mt6323.c
@@ -417,7 +417,7 @@  static int mt6323_led_probe(struct platform_device *pdev)
 			goto put_child_node;
 		}
 
-		if (reg < 0 || reg > MT6323_MAX_LEDS || leds->led[reg]) {
+		if (reg >= MT6323_MAX_LEDS || leds->led[reg]) {
 			dev_err(dev, "Invalid led reg %u\n", reg);
 			ret = -EINVAL;
 			goto put_child_node;