diff mbox series

[v1,5/5] pinctrl: armada-37xx: Replace custom code by gpiochip_count() call

Message ID 20220325200338.54270-5-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/5] gpiolib: Introduce gpiochip_count() helper | expand

Commit Message

Andy Shevchenko March 25, 2022, 8:03 p.m. UTC
Since we have generic function to count GPIO controller nodes
under given device, there is no need to open code it. Replace
custom code by gpiochip_count() call.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 24 +++++++++------------
 1 file changed, 10 insertions(+), 14 deletions(-)

Comments

Sergey Shtylyov March 26, 2022, 8:41 a.m. UTC | #1
Hello!

On 3/25/22 11:03 PM, Andy Shevchenko wrote:

> Since we have generic function to count GPIO controller nodes
> under given device, there is no need to open code it. Replace
> custom code by gpiochip_count() call.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 24 +++++++++------------
>  1 file changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
> index 08cad14042e2..ba94125f6566 100644
> --- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
> +++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
> @@ -728,22 +728,18 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev,
>  	struct gpio_irq_chip *girq = &gc->irq;
>  	struct device *dev = &pdev->dev;
>  	struct device_node *np;
> -	int ret = -ENODEV, i, nr_irq_parent;
> +	unsigned int nr_child_nodes, i;
> +	int ret;
>  
>  	/* Check if we have at least one gpio-controller child node */
> -	for_each_child_of_node(dev->of_node, np) {
> -		if (of_property_read_bool(np, "gpio-controller")) {
> -			ret = 0;
> -			break;
> -		}
> -	}
> -	if (ret)
> -		return dev_err_probe(dev, ret, "no gpio-controller child node\n");
> +	nr_child_nodes = gpiochip_count(dev);
> +	if (!nr_child_nodes)
> +		return dev_err_probe(dev, -ENODEV, "no gpio-controller child node\n");
>  
> -	nr_irq_parent = of_irq_count(np);
>  	spin_lock_init(&info->irq_lock);
>  
> -	if (!nr_irq_parent) {
> +	nr_child_nodes = of_irq_count(np);

   Mhm, 'np' is no longer assigned to at this point...

> +	if (!nr_child_nodes) {
>  		dev_err(dev, "invalid or no IRQ\n");
>  		return 0;
>  	}
[...]

MBR, Sergey
Andy Shevchenko March 27, 2022, 7:58 p.m. UTC | #2
On Sat, Mar 26, 2022 at 7:02 PM Sergey Shtylyov <s.shtylyov@omp.ru> wrote:
> On 3/25/22 11:03 PM, Andy Shevchenko wrote:
>
> > Since we have a generic function to count GPIO controller nodes
> > under a given device, there is no need to open-code it. Replace
> > custom code by gpiochip_count() call.

...

> > +     nr_child_nodes = of_irq_count(np);
>
>    Mhm, 'np' is no longer assigned to it at this point...

Good catch! We may retrieve it by calling

  np = to_of_node(device_get_named_child_node(dev, "gpio-controller"));

like it's done in the previous patch in the series.

--
With Best Regards,
Andy Shevchenko
diff mbox series

Patch

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 08cad14042e2..ba94125f6566 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -728,22 +728,18 @@  static int armada_37xx_irqchip_register(struct platform_device *pdev,
 	struct gpio_irq_chip *girq = &gc->irq;
 	struct device *dev = &pdev->dev;
 	struct device_node *np;
-	int ret = -ENODEV, i, nr_irq_parent;
+	unsigned int nr_child_nodes, i;
+	int ret;
 
 	/* Check if we have at least one gpio-controller child node */
-	for_each_child_of_node(dev->of_node, np) {
-		if (of_property_read_bool(np, "gpio-controller")) {
-			ret = 0;
-			break;
-		}
-	}
-	if (ret)
-		return dev_err_probe(dev, ret, "no gpio-controller child node\n");
+	nr_child_nodes = gpiochip_count(dev);
+	if (!nr_child_nodes)
+		return dev_err_probe(dev, -ENODEV, "no gpio-controller child node\n");
 
-	nr_irq_parent = of_irq_count(np);
 	spin_lock_init(&info->irq_lock);
 
-	if (!nr_irq_parent) {
+	nr_child_nodes = of_irq_count(np);
+	if (!nr_child_nodes) {
 		dev_err(dev, "invalid or no IRQ\n");
 		return 0;
 	}
@@ -766,11 +762,11 @@  static int armada_37xx_irqchip_register(struct platform_device *pdev,
 	 * controller. But we do not take advantage of this and use
 	 * the chained irq with all of them.
 	 */
-	girq->num_parents = nr_irq_parent;
-	girq->parents = devm_kcalloc(dev, nr_irq_parent, sizeof(*girq->parents), GFP_KERNEL);
+	girq->num_parents = nr_child_nodes;
+	girq->parents = devm_kcalloc(dev, nr_child_nodes, sizeof(*girq->parents), GFP_KERNEL);
 	if (!girq->parents)
 		return -ENOMEM;
-	for (i = 0; i < nr_irq_parent; i++) {
+	for (i = 0; i < nr_child_nodes; i++) {
 		int irq = irq_of_parse_and_map(np, i);
 
 		if (irq < 0)