Skip to contentSkip to conversation

staging: vc04_services: vchiq_arm: Use ARRAY_SIZE macro

PATCH In review sayli karnik 2 participants 4 messages Oct 16, 2016 – Oct 17, 2016

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

PATCH v2 1/1 staging: vc04_services: vchiq_arm: Use ARRAY_SIZE macro

This patch uses ARRAY_SIZE macro instead of division of two sizeofs to find array size.
Done using coccinelle.
@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)

---
Changes in v2:
Adjusted the changed part in one line

 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +1 -2
index 5ec7c96..7fee140 100644
@@ -190,8 +190,7 @@ static const char *const ioctl_names[] = {
 	"CLOSE_DELIVERED"
 };
 
-vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
-	(VCHIQ_IOC_MAX + 1));
+vchiq_static_assert(ARRAY_SIZE(ioctl_names) == (VCHIQ_IOC_MAX + 1));
 
 static void
 dump_phys_mem(void *virt_addr, uint32_t num_bytes);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 31 lines · sayli karnik

This patch uses ARRAY_SIZE macro instead of division of two sizeofs to find array size.
Done using coccinelle.
@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)

---
Changes in v2:
Adjusted the changed part in one line

 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +0 -0
index 5ec7c96..7fee140 100644

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c static const char *const ioctl_names[] = { · line 193

Quoted 6 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +1 -2
@@ -190,8 +190,7 @@ static const char *const ioctl_names[] = {
 	"CLOSE_DELIVERED"
 };
 
-vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
-	(VCHIQ_IOC_MAX + 1));
+vchiq_static_assert(ARRAY_SIZE(ioctl_names) == (VCHIQ_IOC_MAX + 1));

How were you able to test build this change? The code is currently broken in the build unless you add a number of external patches at the moment :(

thanks,

greg k-h

#2 lore raw
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · sayli karnik

This patch uses ARRAY_SIZE macro instead of division of two sizeofs to find array size.
Done using coccinelle.
@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)

---
Changes in v2:
Adjusted the changed part in one line

 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +0 -0
index 5ec7c96..7fee140 100644
@@ -190,8 +190,7 @@ static const char *const ioctl_names[] = {
      "CLOSE_DELIVERED"
 };
 
Quoted 8 lines

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c static const char *const ioctl_names[] = { · line 193

Quoted 3 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +1 -2
-vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
-     (VCHIQ_IOC_MAX + 1));
+vchiq_static_assert(ARRAY_SIZE(ioctl_names) == (VCHIQ_IOC_MAX + 1));

How were you able to test build this change? The code is currently broken in the build unless you add a number of external patches at the moment :(

Yes it is broken.
Also there isn't a Makefile in drivers/staging/vc04_services/interface/vchiq_arm/ to build it.

thanks,
sayli

Quoted 3 lines

thanks,

greg k-h

#3 lore raw
Quoted 45 lines · sayli karnik
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · sayli karnik

This patch uses ARRAY_SIZE macro instead of division of two sizeofs to find array size.
Done using coccinelle.
@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)

---
Changes in v2:
Adjusted the changed part in one line

 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +0 -0
index 5ec7c96..7fee140 100644
@@ -190,8 +190,7 @@ static const char *const ioctl_names[] = {
      "CLOSE_DELIVERED"
 };
 
Quoted 8 lines

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c static const char *const ioctl_names[] = { · line 193

Quoted 3 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +1 -2
-vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
-     (VCHIQ_IOC_MAX + 1));
+vchiq_static_assert(ARRAY_SIZE(ioctl_names) == (VCHIQ_IOC_MAX + 1));

How were you able to test build this change? The code is currently broken in the build unless you add a number of external patches at the moment :(

Quoted 3 lines

Yes it is broken.
Also there isn't a Makefile in drivers/staging/vc04_services/interface/vchiq_arm/ to build it.

That's ok, the Makefile a few directories up from that is the one that builds it.

I'm going to hold off applying this patch until you can test-build it.

thanks,

greg k-h