linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH RESEND 5/6 v10] gpio: Add device tree support to block GPIO API
Date: Mon, 17 Dec 2012 15:51:53 +0000	[thread overview]
Message-ID: <20121217155153.GD16561@e106331-lin.cambridge.arm.com> (raw)
In-Reply-To: <1355495185-24220-6-git-send-email-stigge@antcom.de>

Hi,

I have a few comments on the parsing code.

On Fri, Dec 14, 2012 at 02:26:24PM +0000, Roland Stigge wrote:
> This patch adds device tree support to the block GPIO API.
> 
> Signed-off-by: Roland Stigge <stigge@antcom.de>
> 
> ---
>  Documentation/devicetree/bindings/gpio/gpio-block.txt |   36 +++++++
>  drivers/gpio/Makefile                                 |    1 
>  drivers/gpio/gpioblock-of.c                           |   84 ++++++++++++++++++
>  3 files changed, 121 insertions(+)
> 
> --- /dev/null
> +++ linux-2.6/Documentation/devicetree/bindings/gpio/gpio-block.txt
> @@ -0,0 +1,36 @@
> +Block GPIO definition
> +=====================
> +
> +This binding specifies arbitrary blocks of gpios, combining gpios from one or
> +more GPIO controllers together, to form a word for r/w access.
> +
> +Required property:
> +- compatible: must be "linux,gpio-block"
> +
> +Required subnodes:
> +- the name will be the registered name of the block
> +- property "gpios" is a list of gpios for the respective block
> +
> +Example:
> +
> +        blockgpio {
> +                compatible = "linux,gpio-block";
> +
> +                block0 {
> +                        gpios = <&gpio 3 0 0>,
> +                                <&gpio 3 1 0>;
> +                };
> +                block1 {
> +                        gpios = <&gpio 4 1 0>,
> +                                <&gpio 4 3 0>,
> +                                <&gpio 4 2 0>,
> +                                <&gpio 4 4 0>,
> +                                <&gpio 4 5 0>,
> +                                <&gpio 4 6 0>,
> +                                <&gpio 4 7 0>,
> +                                <&gpio 4 8 0>,
> +                                <&gpio 4 9 0>,
> +                                <&gpio 4 10 0>,
> +                                <&gpio 4 19 0>;
> +                };
> +        };
> --- linux-2.6.orig/drivers/gpio/Makefile
> +++ linux-2.6/drivers/gpio/Makefile
> @@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO)	+= -DDEBUG
>  
>  obj-$(CONFIG_GPIOLIB)		+= gpiolib.o devres.o
>  obj-$(CONFIG_OF_GPIO)		+= gpiolib-of.o
> +obj-$(CONFIG_OF_GPIO)		+= gpioblock-of.o
>  
>  # Device drivers. Generally keep list sorted alphabetically
>  obj-$(CONFIG_GPIO_GENERIC)	+= gpio-generic.o
> --- /dev/null
> +++ linux-2.6/drivers/gpio/gpioblock-of.c
> @@ -0,0 +1,84 @@
> +/*
> + * OF implementation for Block GPIO
> + *
> + * Copyright (C) 2012 Roland Stigge <stigge@antcom.de>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/gpio.h>
> +#include <linux/of.h>
> +#include <linux/of_gpio.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/err.h>
> +
> +static int __devinit gpioblock_of_probe(struct platform_device *pdev)
> +{
> +	struct device_node *block;
> +	unsigned *gpios;
> +	int ngpio;
> +	int ret;
> +	struct gpio_block *gb;
> +
> +	for_each_available_child_of_node(pdev->dev.of_node, block) {
> +		int i;
> +
> +		ngpio = of_gpio_count(block);
> +		gpios = kzalloc(ngpio * sizeof(*gpios), GFP_KERNEL);

What if the block node is malformed? ngpio might be -ENOENT or -EINVAL.

> +		if (!gpios)
> +			return -ENOMEM;
> +		for (i = 0; i < ngpio; i++) {
> +			ret = of_get_gpio(block, i);
> +			if (ret < 0)
> +				return ret; /* expect -EPROBE_DEFER */
> +			gpios[i] = ret;
> +		}
> +		gb = gpio_block_create(gpios, ngpio, block->name);
> +		if (IS_ERR(gb)) {
> +			dev_err(&pdev->dev,
> +				"Error creating GPIO block from device tree\n");
> +			return PTR_ERR(gb);

Won't this leak the memory for the gpios object we kzalloc'd earlier?

> +		}
> +		ret = gpio_block_register(gb);
> +		if (ret < 0) {
> +			gpio_block_free(gb);
> +			return ret;

Same here.

> +		}
> +		kfree(gpios);
> +		dev_info(&pdev->dev, "Registered gpio block %s: %d gpios\n",
> +			 block->name, ngpio);

Any of the returns in this block will leave the block node's refcount
incremented.

> +	}
> +	return 0;
> +}
> +
> +#ifdef CONFIG_OF
> +static struct of_device_id gpioblock_of_match[] __devinitdata = {
> +	{ .compatible = "linux,gpio-block", },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, gpioblock_of_match);
> +#endif
> +
> +static struct platform_driver gpioblock_of_driver = {
> +	.driver	= {
> +		.name = "gpio-block",
> +		.owner = THIS_MODULE,
> +		.of_match_table = of_match_ptr(gpioblock_of_match),
> +
> +	},
> +	.probe	= gpioblock_of_probe,
> +};
> +
> +module_platform_driver(gpioblock_of_driver);
> +
> +MODULE_DESCRIPTION("GPIO Block driver");
> +MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:gpioblock-of");
> 

Thanks,
Mark.

  reply	other threads:[~2012-12-17 15:51 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14 14:26 [PATCH RESEND 0/6 v10] gpio: Add block GPIO Roland Stigge
2012-12-14 14:26 ` [PATCH RESEND 1/6 v10] gpio: Add a block GPIO API to gpiolib Roland Stigge
2012-12-14 14:26 ` [PATCH RESEND 2/6 v10] gpio: Add sysfs support to block GPIO API Roland Stigge
2012-12-14 14:26 ` [PATCH RESEND 3/6 v10] gpio: Add userland device interface to block GPIO Roland Stigge
2012-12-14 14:26 ` [PATCH RESEND 4/6 v10] gpiolib: Fix default attributes for class Roland Stigge
2012-12-14 14:26 ` [PATCH RESEND 5/6 v10] gpio: Add device tree support to block GPIO API Roland Stigge
2012-12-17 15:51   ` Mark Rutland [this message]
2012-12-18 14:30     ` Roland Stigge
2012-12-18 16:35       ` Mark Rutland
2012-12-14 14:26 ` [PATCH RESEND 6/6 v10] gpio: Add block gpio to several gpio drivers Roland Stigge
2012-12-14 17:58 ` [PATCH RESEND 0/6 v10] gpio: Add block GPIO Wolfgang Grandegger
2012-12-14 23:49   ` Roland Stigge
2012-12-15 10:51     ` Russell King - ARM Linux
2012-12-17 11:37     ` Wolfgang Grandegger
2012-12-17 11:51       ` Wolfgang Grandegger
2012-12-17 12:10         ` Russell King - ARM Linux
2012-12-17 14:57           ` Wolfgang Grandegger
2012-12-17 13:32         ` Roland Stigge
2012-12-17 13:51           ` Roland Stigge
2012-12-17 16:28             ` Wolfgang Grandegger
2012-12-17 17:15               ` Roland Stigge
2012-12-17 17:37                 ` Wolfgang Grandegger
2012-12-17 18:02                   ` Roland Stigge
2012-12-17 19:47                     ` Wolfgang Grandegger
2012-12-17 21:33                       ` Roland Stigge
2012-12-18  6:51                         ` Wolfgang Grandegger
2012-12-18  5:55                       ` Jean-Christophe PLAGNIOL-VILLARD
2012-12-18  6:58                         ` Wolfgang Grandegger
2012-12-18  7:54                           ` Jean-Christophe PLAGNIOL-VILLARD

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=20121217155153.GD16561@e106331-lin.cambridge.arm.com \
    --to=mark.rutland@arm.com \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).