diff mbox

gpiolib: don't compare an unsigned for >= 0

Message ID 1439913752-26634-1-git-send-email-dirk.behme@gmail.com
State New
Headers show

Commit Message

Dirk Behme Aug. 18, 2015, 4:02 p.m. UTC
The parameter offset is an unsigned, so it makes no sense to compare
it for >= 0. Fix the compiler warning regarding this by removing this
comparison.

As the macro GPIO_OFFSET_VALID is only used at this single place, simplify
the code by dropping the macro completely and dropping the invert, too.

No functional change.

Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
---
 drivers/gpio/gpiolib.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Dirk Behme Aug. 30, 2015, 5:13 a.m. UTC | #1
On 18.08.2015 18:02, Dirk Behme wrote:
> The parameter offset is an unsigned, so it makes no sense to compare
> it for >= 0. Fix the compiler warning regarding this by removing this
> comparison.
>
> As the macro GPIO_OFFSET_VALID is only used at this single place, simplify
> the code by dropping the macro completely and dropping the invert, too.
>
> No functional change.
>
> Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
> ---
>   drivers/gpio/gpiolib.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index bf4bd1d..9841b05 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -47,8 +47,6 @@
>    */
>   DEFINE_SPINLOCK(gpio_lock);
>
> -#define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset < chip->ngpio)
> -
>   static DEFINE_MUTEX(gpio_lookup_lock);
>   static LIST_HEAD(gpio_lookup_list);
>   LIST_HEAD(gpio_chips);
> @@ -914,7 +912,7 @@ const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset)
>   {
>   	struct gpio_desc *desc;
>
> -	if (!GPIO_OFFSET_VALID(chip, offset))
> +	if (offset >= chip->ngpio)
>   		return NULL;
>
>   	desc = &chip->desc[offset];


What do you think about this? Could this be applied?

Best regards

Dirk

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexandre Courbot Aug. 31, 2015, 4:44 a.m. UTC | #2
On Sun, Aug 30, 2015 at 2:13 PM, Dirk Behme <dirk.behme@gmail.com> wrote:
> On 18.08.2015 18:02, Dirk Behme wrote:
>>
>> The parameter offset is an unsigned, so it makes no sense to compare
>> it for >= 0. Fix the compiler warning regarding this by removing this
>> comparison.
>>
>> As the macro GPIO_OFFSET_VALID is only used at this single place, simplify
>> the code by dropping the macro completely and dropping the invert, too.
>>
>> No functional change.
>>
>> Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
>> ---
>>   drivers/gpio/gpiolib.c | 4 +---
>>   1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
>> index bf4bd1d..9841b05 100644
>> --- a/drivers/gpio/gpiolib.c
>> +++ b/drivers/gpio/gpiolib.c
>> @@ -47,8 +47,6 @@
>>    */
>>   DEFINE_SPINLOCK(gpio_lock);
>>
>> -#define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset <
>> chip->ngpio)
>> -
>>   static DEFINE_MUTEX(gpio_lookup_lock);
>>   static LIST_HEAD(gpio_lookup_list);
>>   LIST_HEAD(gpio_chips);
>> @@ -914,7 +912,7 @@ const char *gpiochip_is_requested(struct gpio_chip
>> *chip, unsigned offset)
>>   {
>>         struct gpio_desc *desc;
>>
>> -       if (!GPIO_OFFSET_VALID(chip, offset))
>> +       if (offset >= chip->ngpio)
>>                 return NULL;
>>
>>         desc = &chip->desc[offset];
>
>
>
> What do you think about this? Could this be applied?

Looks good to me.

Acked-by: Alexandre Courbot <acourbot@nvidia.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dirk Behme Sept. 23, 2015, 9:41 a.m. UTC | #3
On 31.08.2015 06:44, Alexandre Courbot wrote:
> On Sun, Aug 30, 2015 at 2:13 PM, Dirk Behme <dirk.behme@gmail.com> wrote:
>> On 18.08.2015 18:02, Dirk Behme wrote:
>>>
>>> The parameter offset is an unsigned, so it makes no sense to compare
>>> it for >= 0. Fix the compiler warning regarding this by removing this
>>> comparison.
>>>
>>> As the macro GPIO_OFFSET_VALID is only used at this single place, simplify
>>> the code by dropping the macro completely and dropping the invert, too.
>>>
>>> No functional change.
>>>
>>> Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
>>> ---
>>>    drivers/gpio/gpiolib.c | 4 +---
>>>    1 file changed, 1 insertion(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
>>> index bf4bd1d..9841b05 100644
>>> --- a/drivers/gpio/gpiolib.c
>>> +++ b/drivers/gpio/gpiolib.c
>>> @@ -47,8 +47,6 @@
>>>     */
>>>    DEFINE_SPINLOCK(gpio_lock);
>>>
>>> -#define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset <
>>> chip->ngpio)
>>> -
>>>    static DEFINE_MUTEX(gpio_lookup_lock);
>>>    static LIST_HEAD(gpio_lookup_list);
>>>    LIST_HEAD(gpio_chips);
>>> @@ -914,7 +912,7 @@ const char *gpiochip_is_requested(struct gpio_chip
>>> *chip, unsigned offset)
>>>    {
>>>          struct gpio_desc *desc;
>>>
>>> -       if (!GPIO_OFFSET_VALID(chip, offset))
>>> +       if (offset >= chip->ngpio)
>>>                  return NULL;
>>>
>>>          desc = &chip->desc[offset];
>>
>>
>>
>> What do you think about this? Could this be applied?
>
> Looks good to me.
>
> Acked-by: Alexandre Courbot <acourbot@nvidia.com>


Ping, could this be applied, then?

Best regards

Dirk

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Oct. 2, 2015, 8:57 a.m. UTC | #4
On Tue, Aug 18, 2015 at 9:02 AM, Dirk Behme <dirk.behme@gmail.com> wrote:

> The parameter offset is an unsigned, so it makes no sense to compare
> it for >= 0. Fix the compiler warning regarding this by removing this
> comparison.
>
> As the macro GPIO_OFFSET_VALID is only used at this single place, simplify
> the code by dropping the macro completely and dropping the invert, too.
>
> No functional change.
>
> Signed-off-by: Dirk Behme <dirk.behme@gmail.com>

Patch applied with Alexandre's ACK.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bf4bd1d..9841b05 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -47,8 +47,6 @@ 
  */
 DEFINE_SPINLOCK(gpio_lock);
 
-#define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset < chip->ngpio)
-
 static DEFINE_MUTEX(gpio_lookup_lock);
 static LIST_HEAD(gpio_lookup_list);
 LIST_HEAD(gpio_chips);
@@ -914,7 +912,7 @@  const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset)
 {
 	struct gpio_desc *desc;
 
-	if (!GPIO_OFFSET_VALID(chip, offset))
+	if (offset >= chip->ngpio)
 		return NULL;
 
 	desc = &chip->desc[offset];