Skip to contentSkip to conversation

gpio: gpio-imx-scu: Use ARRAY_SIZE for array length

PATCH In review [email protected] 3 participants 3 messages Aug 10, 2023 – Aug 11, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 gpio: gpio-imx-scu: Use ARRAY_SIZE for array length

From: Rajeshwar R Shinde <[email protected]>

Use of macro ARRAY_SIZE to calculate array size minimizes the redundant code and improves code reusability. This fixes warnings reported by Coccinelle:
drivers/gpio/gpio-imx-scu.c:106:32-33: WARNING: Use ARRAY_SIZE

---
v1->v2
ARRAY_SIZE calculates array length, so changed gc->ngpio = ARRAY_SIZE(scu_rsrc_arr)/sizeof(unsigned int) to gc->ngpio = ARRAY_SIZE(scu_rsrc_arr)

v2->v3
added linux/kernel.h containing ARRAY_SIZE definition

---
 drivers/gpio/gpio-imx-scu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpio/gpio-imx-scu.c +2 -1
index e190bde5397d..13baf465aedf 100644
@@ -6,6 +6,7 @@
  * to control the PIN resources on SCU domain.
  */
 
+#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/gpio/driver.h>
 #include <linux/platform_device.h>
@@ -103,7 +104,7 @@ static int imx_scu_gpio_probe(struct platform_device *pdev)
 	gc = &priv->chip;
 	gc->base = -1;
 	gc->parent = dev;
-	gc->ngpio = sizeof(scu_rsrc_arr)/sizeof(unsigned int);
+	gc->ngpio = ARRAY_SIZE(scu_rsrc_arr);
 	gc->label = dev_name(dev);
 	gc->get = imx_scu_gpio_get;
 	gc->set = imx_scu_gpio_set;
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 7 lines · On Thu, Aug 10, 2023 at 4:06 PM <[email protected]> wrote:

From: Rajeshwar R Shinde <[email protected]>

Use of macro ARRAY_SIZE to calculate array size minimizes the redundant code and improves code reusability. This fixes warnings reported by Coccinelle:
drivers/gpio/gpio-imx-scu.c:106:32-33: WARNING: Use ARRAY_SIZE

Yes and this makes code more robust against type changes.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to [email protected]
Quoted 44 lines · On Thu, Aug 10, 2023 at 3:06 PM <[email protected]> wrote:

From: Rajeshwar R Shinde <[email protected]>

Use of macro ARRAY_SIZE to calculate array size minimizes the redundant code and improves code reusability. This fixes warnings reported by Coccinelle:
drivers/gpio/gpio-imx-scu.c:106:32-33: WARNING: Use ARRAY_SIZE

---
v1->v2
ARRAY_SIZE calculates array length, so changed gc->ngpio = ARRAY_SIZE(scu_rsrc_arr)/sizeof(unsigned int) to gc->ngpio = ARRAY_SIZE(scu_rsrc_arr)

v2->v3
added linux/kernel.h containing ARRAY_SIZE definition

---
 drivers/gpio/gpio-imx-scu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpio/gpio-imx-scu.c +2 -2
index e190bde5397d..13baf465aedf 100644
@@ -6,6 +6,7 @@
  * to control the PIN resources on SCU domain.
  */
 
+#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/gpio/driver.h>
 #include <linux/platform_device.h>
@@ -103,7 +104,7 @@ static int imx_scu_gpio_probe(struct platform_device *pdev)
        gc = &priv->chip;
        gc->base = -1;
        gc->parent = dev;
-       gc->ngpio = sizeof(scu_rsrc_arr)/sizeof(unsigned int);
+       gc->ngpio = ARRAY_SIZE(scu_rsrc_arr);
        gc->label = dev_name(dev);
        gc->get = imx_scu_gpio_get;
        gc->set = imx_scu_gpio_set;
--
Quoted 2 lines

2.25.1

The commit title should be "gpio: imx-scu: ..."

I fixed it and applied.

Bart