Re: [PATCH 2/2] power: supply: Add Spreadtrum SC27XX fuel gauge unit driver

From: Baolin Wang
Date: Wed Sep 19 2018 - 20:40:51 EST


Hi,

On 20 September 2018 at 08:36, Sebastian Reichel
<sebastian.reichel@xxxxxxxxxxxxx> wrote:
> Hi,
>
> On Mon, Sep 17, 2018 at 12:01:51PM +0800, Baolin Wang wrote:
> [...]
>> >> +static int sc27xx_fgu_parse_dt(struct sc27xx_fgu_data *data,
>> >> + struct device_node *np)
>> >> +{
>> >> + const __be32 *list;
>> >> + int i, len, size, ret;
>> >> +
>> >> + ret = of_property_read_u32(np, "reg", &data->base);
>> >> + if (ret) {
>> >> + dev_err(data->dev, "failed to get fgu address\n");
>> >> + return ret;
>> >> + }
>> >> +
>> >> + data->gpiod = devm_gpiod_get_optional(data->dev, "bat-detect", GPIOD_IN);
>> >> + if (IS_ERR(data->gpiod)) {
>> >> + dev_err(data->dev, "failed to get battery detection GPIO\n");
>> >> + return PTR_ERR(data->gpiod);
>> >> + }
>> >
>> > According to the binding (and the remaining code!) this gpio is not
>> > optional.
>>
>> Yes, they are not optional. If we can not get the detection GPIO, we
>> will return errors. So am I missing something else?
>>
>> Thanks for your comments.
>
> devm_gpiod_get_optional => devm_gpiod_get
>
> The _optional variant will return NULL if the GPIO is not specified in DT.
> The variant without _optional will return an error instead.

Ah, you are definitely correct. I missed _optional and thanks for
pointing this out.

--
Baolin Wang
Best Regards