public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 5/6] gpiolib: consolidate GPIO lookups
Date: Wed, 9 Nov 2022 13:25:06 +0200	[thread overview]
Message-ID: <Y2uOEhib5dvIcobF@smile.fi.intel.com> (raw)
In-Reply-To: <20221031-gpiolib-swnode-v2-5-81f55af5fa0e@gmail.com>

On Tue, Nov 08, 2022 at 04:26:50PM -0800, Dmitry Torokhov wrote:
> Ensure that all paths to obtain/look up GPIOD from generic
> consumer-visible APIs go through the new gpiod_find_and_request()
> helper, so that we can easily extend it with support for new firmware
> mechanisms.
> 
> The only exception is OF-specific [devm_]gpiod_get_from_of_node() API
> that is still being used by a couple of drivers and will be removed as
> soon as patches converting them to use generic fwnode/device APIs are
> accepted.

...

> +static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
> +					      struct device *consumer,
> +					      const char *con_id,
> +					      unsigned int idx,
> +					      enum gpiod_flags *flags,
> +					      unsigned long *lookupflags)
>  {
> -	unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;

> -	struct gpio_desc *desc = ERR_PTR(-ENODEV);

Not sure why this is needed. Now I see that else branch has been changed,
but looking closer to it, we can drop it completely, while leaving this
line untouched, correct?

> -	int ret;
> +	struct gpio_desc *desc;
>  
> +	dev_dbg(consumer, "GPIO lookup for consumer %s in node '%pfw'\n",
> +		con_id, fwnode);
> +
> +	/* Using device tree? */
>  	if (is_of_node(fwnode)) {
> -		desc = gpiod_get_from_of_node(to_of_node(fwnode),
> -					      propname, index,
> -					      dflags,
> -					      label);
> -		return desc;
> +		dev_dbg(consumer, "using device tree for GPIO lookup\n");
> +		desc = of_find_gpio(to_of_node(fwnode),
> +				    con_id, idx, lookupflags);

At least con_id can be placed on the previous line.

>  	} else if (is_acpi_node(fwnode)) {
> -		desc = acpi_node_get_gpiod(fwnode, propname, index,
> -					   &lflags, &dflags);
> -		if (IS_ERR(desc))
> -			return desc;
> +		dev_dbg(consumer, "using ACPI for GPIO lookup\n");
> +		desc = acpi_find_gpio(fwnode, con_id, idx, flags, lookupflags);
>  	} else {
> -		return ERR_PTR(-EINVAL);
> +		desc = ERR_PTR(-ENOENT);
>  	}
>  
> -	/* Currently only ACPI takes this path */
> +	return desc;
> +}

...

> +	struct gpio_desc *desc = ERR_PTR(-ENOENT);
> +	unsigned long lookupflags;
> +	int ret;

> +	if (!IS_ERR_OR_NULL(fwnode))

I think this is superfluous check.

Now in the form of this series, you have only a single dev_dbg() that tries to
dereference it. Do we really need to have it there, since every branch has its
own dev_dbg() anyway?

> +		desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx,
> +					    &flags, &lookupflags);

> +

This blank line can be dropped after addressing above.

> +	if (gpiod_not_found(desc) && platform_lookup_allowed) {
> +		/*
> +		 * Either we are not using DT or ACPI, or their lookup did not
> +		 * return a result. In that case, use platform lookup as a
> +		 * fallback.
> +		 */
> +		dev_dbg(consumer, "using lookup tables for GPIO lookup\n");
> +		desc = gpiod_find(consumer, con_id, idx, &lookupflags);
> +	}
> +
> +	if (IS_ERR(desc)) {
> +		dev_dbg(consumer, "No GPIO consumer %s found\n", con_id);
> +		return desc;
> +	}

...

> +	return gpiod_find_and_request(NULL, fwnode, con_id, index, flags, label,
> +				      false);

One line?

...

> +	return gpiod_find_and_request(dev, fwnode, con_id, idx, flags, label,
> +				      true);

One line?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2022-11-09 11:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  0:26 [PATCH v2 0/6] Add support for software nodes to gpiolib Dmitry Torokhov
2022-11-09  0:26 ` [PATCH v2 1/6] gpiolib: of: change of_find_gpio() to accept device node Dmitry Torokhov
2022-11-09  0:26 ` [PATCH v2 2/6] gpiolib: acpi: change acpi_find_gpio() to accept firmware node Dmitry Torokhov
2022-11-09  0:26 ` [PATCH v2 3/6] gpiolib: acpi: teach acpi_find_gpio() to handle data-only nodes Dmitry Torokhov
2022-11-09  0:26 ` [PATCH v2 4/6] gpiolib: acpi: avoid leaking ACPI details into upper gpiolib layers Dmitry Torokhov
2022-11-09  0:26 ` [PATCH v2 5/6] gpiolib: consolidate GPIO lookups Dmitry Torokhov
2022-11-09 11:25   ` Andy Shevchenko [this message]
2022-11-09 19:00     ` Dmitry Torokhov
2022-11-10 13:42       ` Andy Shevchenko
2022-11-10 17:21         ` Dmitry Torokhov
2022-11-10 20:10           ` Andy Shevchenko
2022-11-09  0:26 ` [PATCH v2 6/6] gpiolib: add support for software nodes Dmitry Torokhov
2022-11-09 11:20   ` Andy Shevchenko
2022-11-09 19:08     ` Dmitry Torokhov
2022-11-10 13:48       ` Andy Shevchenko
2022-11-10 17:17         ` Dmitry Torokhov
2022-11-09 11:29 ` [PATCH v2 0/6] Add support for software nodes to gpiolib Andy Shevchenko
2022-11-09 19:32   ` Dmitry Torokhov
2022-11-10 14:16     ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2uOEhib5dvIcobF@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox