Skip to contentSkip to conversation

pinctrl: rp1: Use ARRAY_SIZE() to compute group sizes

PATCH New Andrea della Porta 1 participant 1 message Nov 25

Subsystems (3)
lore
Share & tools
lore

Andrea della Porta

author maintainer
#0 lore raw

PATCH 1/1 pinctrl: rp1: Use ARRAY_SIZE() to compute group sizes

Coccinelle reports:

drivers/pinctrl/pinctrl-rp1.c:343:39-40: WARNING: Use ARRAY_SIZE drivers/pinctrl/pinctrl-rp1.c:444:33-34: WARNING: Use ARRAY_SIZE

PIN_ARRAY_SIZE() and GRP_ARRAY_SIZE() open-code the element count of a compound literal as sizeof(array) / sizeof(element), duplicating the element type from the corresponding PIN_ARRAY() and GRP_ARRAY() macros.

Use ARRAY_SIZE() on the PIN_ARRAY()/GRP_ARRAY() compound literals instead, so the element type is no longer repeated and the array check in ARRAY_SIZE() applies. Wrap the compound literals in parentheses so they can be safely passed as macro arguments, and include <linux/array_size.h> explicitly.

No functional change is expected.

Fixes e3ce7b897388 ("pinctrl: rp1: Implement RaspberryPi RP1 pinmux/pinconf support")
---
 drivers/pinctrl/pinctrl-rp1.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pinctrl/pinctrl-rp1.c +5 -4
index dd0e85c2ca33..da86bbc40f41 100644
@@ -8,6 +8,7 @@
  * pinctrl-bcm2835.c, please see original file for copyright information
  */
 
+#include <linux/array_size.h>
 #include <linux/gpio/driver.h>
 #include <linux/of_irq.h>
 #include <linux/pinctrl/pinconf.h>
@@ -338,9 +339,9 @@ static struct pinctrl_pin_desc rp1_gpio_pins[] = {
 };
 
 #define PIN_ARRAY(...) \
-	(const unsigned int []) {__VA_ARGS__}
+	((const unsigned int []) {__VA_ARGS__})
 #define PIN_ARRAY_SIZE(...) \
-	(sizeof((unsigned int[]) {__VA_ARGS__}) / sizeof(unsigned int))
+	ARRAY_SIZE(PIN_ARRAY(__VA_ARGS__))
 #define RP1_GROUP(name, ...) \
 	PINCTRL_PINGROUP(#name, PIN_ARRAY(__VA_ARGS__), \
 			 PIN_ARRAY_SIZE(__VA_ARGS__))
@@ -439,9 +440,9 @@ static const struct pingroup rp1_gpio_groups[] = {
 };
 
 #define GRP_ARRAY(...) \
-	(const char * []) {__VA_ARGS__}
+	((const char * []) {__VA_ARGS__})
 #define GRP_ARRAY_SIZE(...) \
-	(sizeof((char *[]) {__VA_ARGS__}) / sizeof(char *))
+	ARRAY_SIZE(GRP_ARRAY(__VA_ARGS__))
 #define RP1_FNC(f, ...) \
 	[func_##f] = PINCTRL_PINFUNCTION(#f, GRP_ARRAY(__VA_ARGS__), \
 					 GRP_ARRAY_SIZE(__VA_ARGS__))
Signature · 1 line
2.51.0