pinctrl: rp1: Use ARRAY_SIZE() to compute group sizes
Subsystems (3)
Andrea della Porta
maintainerPATCH 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.
--- drivers/pinctrl/pinctrl-rp1.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pinctrl/pinctrl-rp1.c +5 -4
@@ -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