Patchwork [v4,5/13] Use ARRAY_SIZE to iterate over firmware_features_table array

login
register
mail settings
Submitter Nathan Fontenot
Date April 24, 2013, 3:55 p.m.
Message ID <5178005C.1070204@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/239259/
State Accepted, archived
Commit 43c0ea60537d9423f0f1b5c14b0cd0a0b4af5c81
Delegated to: Benjamin Herrenschmidt
Headers show

Comments

Nathan Fontenot - April 24, 2013, 3:55 p.m.
When iterating over the entries in firmware_features_table we only need
to go over the actual number of entries in the array instead of declaring
it to be bigger and checking to make sure there is a valid entry in every
slot.

This patch removes the FIRMWARE_MAX_FEATURES #define and replaces the
array looping with the use of ARRAY_SIZE().

Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/firmware.h       |    1 -
 arch/powerpc/platforms/pseries/firmware.c |    8 +++-----
 2 files changed, 3 insertions(+), 6 deletions(-)
Stephen Rothwell - April 26, 2013, 3:08 a.m.
Hi Nathan,

On Wed, 24 Apr 2013 10:55:08 -0500 Nathan Fontenot <nfont@linux.vnet.ibm.com> wrote:
>
> When iterating over the entries in firmware_features_table we only need
> to go over the actual number of entries in the array instead of declaring
> it to be bigger and checking to make sure there is a valid entry in every
> slot.
> 
> This patch removes the FIRMWARE_MAX_FEATURES #define and replaces the
> array looping with the use of ARRAY_SIZE().
> 

Suggested-by: Stephen Rothwell <sfr@canb.auug.org.au>

> Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
> @@ -77,12 +77,10 @@
>  	pr_debug(" -> fw_feature_init()\n");
>  
>  	for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) {
> -		for (i = 0; i < FIRMWARE_MAX_FEATURES; i++) {
> +		for (i = 0; i < ARRAY_SIZE(firmware_features_table); i++) {

You should explicitly include linux/kernel.h to use ARRAY_SIZE().

Patch

Index: powerpc/arch/powerpc/include/asm/firmware.h
===================================================================
--- powerpc.orig/arch/powerpc/include/asm/firmware.h	2013-04-23 14:17:16.000000000 -0500
+++ powerpc/arch/powerpc/include/asm/firmware.h	2013-04-23 14:19:54.000000000 -0500
@@ -18,7 +18,6 @@ 
 #include <asm/feature-fixups.h>
 
 /* firmware feature bitmask values */
-#define FIRMWARE_MAX_FEATURES 63
 
 #define FW_FEATURE_PFT		ASM_CONST(0x0000000000000001)
 #define FW_FEATURE_TCE		ASM_CONST(0x0000000000000002)
Index: powerpc/arch/powerpc/platforms/pseries/firmware.c
===================================================================
--- powerpc.orig/arch/powerpc/platforms/pseries/firmware.c	2013-04-23 14:17:16.000000000 -0500
+++ powerpc/arch/powerpc/platforms/pseries/firmware.c	2013-04-23 14:46:10.000000000 -0500
@@ -39,7 +39,7 @@ 
  * string must match.
  */
 static __initdata firmware_feature_t
-firmware_features_table[FIRMWARE_MAX_FEATURES] = {
+firmware_features_table[] = {
 	{FW_FEATURE_PFT,		"hcall-pft"},
 	{FW_FEATURE_TCE,		"hcall-tce"},
 	{FW_FEATURE_SPRG0,		"hcall-sprg0"},
@@ -77,12 +77,10 @@ 
 	pr_debug(" -> fw_feature_init()\n");
 
 	for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) {
-		for (i = 0; i < FIRMWARE_MAX_FEATURES; i++) {
+		for (i = 0; i < ARRAY_SIZE(firmware_features_table); i++) {
 			const char *name = firmware_features_table[i].name;
 			size_t size;
-			/* check value against table of strings */
-			if (!name)
-				continue;
+
 			/*
 			 * If there is a '*' at the end of name, only check
 			 * upto there