Patchwork [U-Boot] gpio: pca953x: Use ARRAY_SIZE instead of reinventing it

login
register
mail settings
Submitter Axel Lin
Date June 22, 2013, 10:22 a.m.
Message ID <1371896568.12449.1.camel@phoenix>
Download mbox | patch
Permalink /patch/253411/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Axel Lin - June 22, 2013, 10:22 a.m.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/gpio/pca953x.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
Thierry Reding - June 22, 2013, 11:05 a.m.
On Sat, Jun 22, 2013 at 06:22:48PM +0800, Axel Lin wrote:
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/gpio/pca953x.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

Reviewed-by: Thierry Reding <thierry.reding@gmail.com>
Marek Vasut - June 22, 2013, 1:21 p.m.
Dear Axel Lin,

> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/gpio/pca953x.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
> index be13745..7371cd4 100644
> --- a/drivers/gpio/pca953x.c
> +++ b/drivers/gpio/pca953x.c
> @@ -47,9 +47,6 @@ struct pca953x_chip_ngpio {
>  static struct pca953x_chip_ngpio pca953x_chip_ngpios[] =
>      CONFIG_SYS_I2C_PCA953X_WIDTH;
> 
> -#define NUM_CHIP_GPIOS (sizeof(pca953x_chip_ngpios) / \
> -			sizeof(struct pca953x_chip_ngpio))
> -
>  /*
>   * Determine the number of GPIO pins supported. If we don't know we assume
>   * 8 pins.
> @@ -58,7 +55,7 @@ static int pca953x_ngpio(uint8_t chip)
>  {
>  	int i;
> 
> -	for (i = 0; i < NUM_CHIP_GPIOS; i++)
> +	for (i = 0; i < ARRAY_SIZE(pca953x_chip_ngpios); i++)
>  		if (pca953x_chip_ngpios[i].chip == chip)
>  			return pca953x_chip_ngpios[i].ngpio;

Absolutelly

Acked-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut
Tom Rini - Aug. 18, 2013, 9:49 p.m.
On Sat, Jun 22, 2013 at 06:22:48PM +0800, Axel Lin wrote:

> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> Reviewed-by: Thierry Reding <thierry.reding@gmail.com>
> Acked-by: Marek Vasut <marex@denx.de>
> 
> ---
> drivers/gpio/pca953x.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

Applied to u-boot/master, thanks!

Patch

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index be13745..7371cd4 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -47,9 +47,6 @@  struct pca953x_chip_ngpio {
 static struct pca953x_chip_ngpio pca953x_chip_ngpios[] =
     CONFIG_SYS_I2C_PCA953X_WIDTH;
 
-#define NUM_CHIP_GPIOS (sizeof(pca953x_chip_ngpios) / \
-			sizeof(struct pca953x_chip_ngpio))
-
 /*
  * Determine the number of GPIO pins supported. If we don't know we assume
  * 8 pins.
@@ -58,7 +55,7 @@  static int pca953x_ngpio(uint8_t chip)
 {
 	int i;
 
-	for (i = 0; i < NUM_CHIP_GPIOS; i++)
+	for (i = 0; i < ARRAY_SIZE(pca953x_chip_ngpios); i++)
 		if (pca953x_chip_ngpios[i].chip == chip)
 			return pca953x_chip_ngpios[i].ngpio;