devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: gpio_keys: Cleanup devicetree parser
@ 2012-06-25 15:17 Alexandre Pereira da Silva
  2012-06-25 15:21 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Pereira da Silva @ 2012-06-25 15:17 UTC (permalink / raw)
  Cc: Alexandre Pereira da Silva, Dmitry Torokhov, Grant Likely,
	Rob Herring, Tobias Klauser, David Jander, Laxman Dewangan,
	linux-input, linux-kernel, devicetree-discuss

Fix sizeof in memset.
Cleanup dt properties extraction.
Use for_each macro.
Use of_match_ptr macro.

Signed-off-by: Alexandre Pereira da Silva <aletes.xgr@gmail.com>
---
 drivers/input/keyboard/gpio_keys.c |   30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 62bfce4..1ef15ae 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -548,22 +548,16 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
 	struct device_node *node, *pp;
 	int i;
 	struct gpio_keys_button *buttons;
-	u32 reg;
 
 	node = dev->of_node;
 	if (node == NULL)
 		return -ENODEV;
 
-	memset(pdata, 0, sizeof *pdata);
+	memset(pdata, 0, sizeof(*pdata));
 
 	pdata->rep = !!of_get_property(node, "autorepeat", NULL);
 
-	/* First count the subnodes */
-	pdata->nbuttons = 0;
-	pp = NULL;
-	while ((pp = of_get_next_child(node, pp)))
-		pdata->nbuttons++;
-
+	pdata->nbuttons = of_get_child_count(node);
 	if (pdata->nbuttons == 0)
 		return -ENODEV;
 
@@ -571,9 +565,8 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
 	if (!buttons)
 		return -ENOMEM;
 
-	pp = NULL;
 	i = 0;
-	while ((pp = of_get_next_child(node, pp))) {
+	for_each_child_of_node(node, pp) {
 		enum of_gpio_flags flags;
 
 		if (!of_find_property(pp, "gpios", NULL)) {
@@ -584,24 +577,21 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
 		buttons[i].gpio = of_get_gpio_flags(pp, 0, &flags);
 		buttons[i].active_low = flags & OF_GPIO_ACTIVE_LOW;
 
-		if (of_property_read_u32(pp, "linux,code", &reg)) {
+		if (of_property_read_u32(pp, "linux,code", &buttons[i].code)) {
 			dev_err(dev, "Button without keycode: 0x%x\n", buttons[i].gpio);
 			goto out_fail;
 		}
-		buttons[i].code = reg;
 
 		buttons[i].desc = of_get_property(pp, "label", NULL);
 
-		if (of_property_read_u32(pp, "linux,input-type", &reg) == 0)
-			buttons[i].type = reg;
-		else
+		if (of_property_read_u32(pp, "linux,input-type",
+			&buttons[i].type))
 			buttons[i].type = EV_KEY;
 
 		buttons[i].wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
 
-		if (of_property_read_u32(pp, "debounce-interval", &reg) == 0)
-			buttons[i].debounce_interval = reg;
-		else
+		if (of_property_read_u32(pp, "debounce-interval",
+			&buttons[i].debounce_interval))
 			buttons[i].debounce_interval = 5;
 
 		i++;
@@ -630,8 +620,6 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
 	return -ENODEV;
 }
 
-#define gpio_keys_of_match NULL
-
 #endif
 
 static void gpio_remove_key(struct gpio_button_data *bdata)
@@ -823,7 +811,7 @@ static struct platform_driver gpio_keys_device_driver = {
 		.name	= "gpio-keys",
 		.owner	= THIS_MODULE,
 		.pm	= &gpio_keys_pm_ops,
-		.of_match_table = gpio_keys_of_match,
+		.of_match_table = of_match_ptr(gpio_keys_of_match),
 	}
 };
 
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] input: gpio_keys: Cleanup devicetree parser
  2012-06-25 15:17 [PATCH] input: gpio_keys: Cleanup devicetree parser Alexandre Pereira da Silva
@ 2012-06-25 15:21 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2012-06-25 15:21 UTC (permalink / raw)
  To: Alexandre Pereira da Silva
  Cc: Dmitry Torokhov, Grant Likely, Tobias Klauser, David Jander,
	Laxman Dewangan, linux-input, linux-kernel, devicetree-discuss

On 06/25/2012 10:17 AM, Alexandre Pereira da Silva wrote:
> Fix sizeof in memset.
> Cleanup dt properties extraction.
> Use for_each macro.
> Use of_match_ptr macro.
> 
> Signed-off-by: Alexandre Pereira da Silva <aletes.xgr@gmail.com>

Acked-by: Rob Herring <rob.herring@calxeda.com>

> ---
>  drivers/input/keyboard/gpio_keys.c |   30 +++++++++---------------------
>  1 file changed, 9 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index 62bfce4..1ef15ae 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -548,22 +548,16 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
>  	struct device_node *node, *pp;
>  	int i;
>  	struct gpio_keys_button *buttons;
> -	u32 reg;
>  
>  	node = dev->of_node;
>  	if (node == NULL)
>  		return -ENODEV;
>  
> -	memset(pdata, 0, sizeof *pdata);
> +	memset(pdata, 0, sizeof(*pdata));
>  
>  	pdata->rep = !!of_get_property(node, "autorepeat", NULL);
>  
> -	/* First count the subnodes */
> -	pdata->nbuttons = 0;
> -	pp = NULL;
> -	while ((pp = of_get_next_child(node, pp)))
> -		pdata->nbuttons++;
> -
> +	pdata->nbuttons = of_get_child_count(node);
>  	if (pdata->nbuttons == 0)
>  		return -ENODEV;
>  
> @@ -571,9 +565,8 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
>  	if (!buttons)
>  		return -ENOMEM;
>  
> -	pp = NULL;
>  	i = 0;
> -	while ((pp = of_get_next_child(node, pp))) {
> +	for_each_child_of_node(node, pp) {
>  		enum of_gpio_flags flags;
>  
>  		if (!of_find_property(pp, "gpios", NULL)) {
> @@ -584,24 +577,21 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
>  		buttons[i].gpio = of_get_gpio_flags(pp, 0, &flags);
>  		buttons[i].active_low = flags & OF_GPIO_ACTIVE_LOW;
>  
> -		if (of_property_read_u32(pp, "linux,code", &reg)) {
> +		if (of_property_read_u32(pp, "linux,code", &buttons[i].code)) {
>  			dev_err(dev, "Button without keycode: 0x%x\n", buttons[i].gpio);
>  			goto out_fail;
>  		}
> -		buttons[i].code = reg;
>  
>  		buttons[i].desc = of_get_property(pp, "label", NULL);
>  
> -		if (of_property_read_u32(pp, "linux,input-type", &reg) == 0)
> -			buttons[i].type = reg;
> -		else
> +		if (of_property_read_u32(pp, "linux,input-type",
> +			&buttons[i].type))
>  			buttons[i].type = EV_KEY;
>  
>  		buttons[i].wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
>  
> -		if (of_property_read_u32(pp, "debounce-interval", &reg) == 0)
> -			buttons[i].debounce_interval = reg;
> -		else
> +		if (of_property_read_u32(pp, "debounce-interval",
> +			&buttons[i].debounce_interval))
>  			buttons[i].debounce_interval = 5;
>  
>  		i++;
> @@ -630,8 +620,6 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
>  	return -ENODEV;
>  }
>  
> -#define gpio_keys_of_match NULL
> -
>  #endif
>  
>  static void gpio_remove_key(struct gpio_button_data *bdata)
> @@ -823,7 +811,7 @@ static struct platform_driver gpio_keys_device_driver = {
>  		.name	= "gpio-keys",
>  		.owner	= THIS_MODULE,
>  		.pm	= &gpio_keys_pm_ops,
> -		.of_match_table = gpio_keys_of_match,
> +		.of_match_table = of_match_ptr(gpio_keys_of_match),
>  	}
>  };
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-25 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-25 15:17 [PATCH] input: gpio_keys: Cleanup devicetree parser Alexandre Pereira da Silva
2012-06-25 15:21 ` Rob Herring

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).