[PATCH v2 3/5] gpiolib: gpio_request(): add error message

Antony Pavlov antonynpavlov at gmail.com
Fri Feb 1 13:09:39 EST 2013


On 1 February 2013 12:13, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj at jcrosoft.com> wrote:
> Nack the is need to handle by the caller not here

You want to get duplicated code? Ok, you will get in the "patch v3" series! :)))

>
> Best Regards,
> J.
>>
>> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
>> ---
>>  drivers/gpio/gpio.c |   29 ++++++++++++++++++++++-------
>>  1 file changed, 22 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio.c b/drivers/gpio/gpio.c
>> index 5876454..179fc7b 100644
>> --- a/drivers/gpio/gpio.c
>> +++ b/drivers/gpio/gpio.c
>> @@ -29,22 +29,37 @@ int gpio_request(unsigned gpio, const char *label)
>>       struct gpio_chip *chip = gi->chip;
>>       int ret;
>>
>> -     if (!gpio_is_valid(gpio))
>> -             return -EINVAL;
>> -     if (!chip)
>> -             return -EINVAL;
>> -     if (gi->requested)
>> -             return -EBUSY;
>> +     if (!gpio_is_valid(gpio)) {
>> +             ret = -EINVAL;
>> +             goto err;
>> +     }
>> +
>> +     if (!chip) {
>> +             ret = -EINVAL;
>> +             goto err;
>> +     }
>> +
>> +     if (gi->requested) {
>> +             ret = -EBUSY;
>> +             goto err;
>> +     }
>> +
>>       if (chip->ops->request) {
>>               ret = chip->ops->request(chip, gpio - chip->base);
>>               if (ret)
>> -                     return ret;
>> +                     goto err;
>>       }
>>
>>       gi->requested = true;
>>       gi->label = xstrdup(label);
>>
>>       return 0;
>> +
>> +err:
>> +     pr_err("can't request gpio %d as %s (%d)\n",
>> +             gpio, label, ret);
>> +
>> +     return ret;
>>  }
>>
>>  int gpio_request_input(unsigned gpio, const char *label)
>> --
>> 1.7.10.4
>>



-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list