net: Use ARRAY_SIZE at appropriate places
PATCH 1/1 net: Use ARRAY_SIZE at appropriate places
Use ARRAY_SIZE instead of having similar implementation in each drivers.
---
Hi,tools/checkpatch.pl shows
total: 2 errors, 12 warnings, 0 checks, 89 lines checked
The errors are:
ERROR: code indent should use tabs where possible
The warnings are something like below:
WARNING: line over 80 characters
WARNING: please, no spaces at the start of a line
WARNING: Avoid CamelCase: <ixEthDBPortDefinitions>
I don't fixup the checkpatch.pl issues because I feel having the patch as is seems cleaner.
Regards,
Axel
drivers/net/ax88180.c | 2 +- drivers/net/fsl_mcdmafec.c | 2 +- drivers/net/lan91c96.c | 2 +- drivers/net/mcffec.c | 2 +- drivers/net/mcfmii.c | 2 +- drivers/net/ne2000.c | 2 +- drivers/net/npe/IxEthDBFeatures.c | 4 ++-- drivers/net/npe/IxOsalIoMem.c | 3 +-- drivers/net/npe/include/IxEthDBPortDefs.h | 2 +- drivers/net/npe/include/IxOsalTypes.h | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-)
drivers/net/ax88180.c +1 -1
@@ -157,7 +157,7 @@ static void ax88180_mac_reset (struct eth_device *dev)OUTW (dev,MISC_RESET_MAC ,MISC ); tmpval =INW (dev,MISC ); -for (i =0 ; i < (sizeof (program_seq) /sizeof (program_seq[0 ])); i++) +for (i =0 ; i <ARRAY_SIZE (program_seq); i++)OUTW (dev, program_seq[i].value, program_seq[i].offset); }
drivers/net/fsl_mcdmafec.c +1 -1
@@ -520,7 +520,7 @@ int mcdmafec_initialize(bd_t * bis)u32 tmp =CONFIG_SYS_INTSRAM +0x2000 ;#endif -for (i =0 ; i <sizeof (fec_info) /sizeof (fec_info[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (fec_info); i++) { dev = (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE,
drivers/net/lan91c96.c +1 -1
@@ -779,7 +779,7 @@ static int lan91c96_detect_chip(struct eth_device *dev)SMC_SELECT_BANK (dev,3 ); chip_id = (SMC_inw (dev,0xA ) &LAN91C96_REV_CHIPID ) >>4 ;SMC_SELECT_BANK (dev,0 ); -for (r =0 ; r <sizeof (supported_chips) /sizeof (struct id_type ); r++) +for (r =0 ; r <ARRAY_SIZE (supported_chips); r++)if (chip_id == supported_chips[r].id)return r;return 0 ;
drivers/net/mcffec.c +1 -1
@@ -559,7 +559,7 @@ int mcffec_initialize(bd_t * bis)u32 tmp =CONFIG_SYS_INIT_RAM_ADDR +0x1000 ;#endif -for (i =0 ; i <sizeof (fec_info) /sizeof (fec_info[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (fec_info); i++) { dev = (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE,
drivers/net/mcfmii.c +1 -1
@@ -186,7 +186,7 @@ int mii_discover_phy(struct eth_device *dev)printf ("PHY @ 0x%x pass %d\n" , phyno, pass);#endif -for (i =0 ; (i < (sizeof (phyinfo) /sizeof (phy_info_t))) +for (i =0 ; (i <ARRAY_SIZE (phyinfo)) && (phyinfo[i].phyid !=0 ); i++) {if (phyinfo[i].phyid == phytype) {#ifdef ET_DEBUG
drivers/net/ne2000.c +1 -1
@@ -228,7 +228,7 @@ int get_prom(u8* mac_addr, u8* base_addr)mdelay (10 ); -for (i =0 ; i <sizeof (program_seq) /sizeof (program_seq[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (program_seq); i++)n2k_outb (program_seq[i].value, program_seq[i].offset);PRINTK ("PROM:" );
drivers/net/npe/IxEthDBFeatures.c +2 -2
@@ -144,7 +144,7 @@ void ixEthDBFeatureCapabilityScan(void)/* find the traffic class definition index compatible with the current NPE A functionality ID */ for (trafficClassDefinitionIndex =0 ; - trafficClassDefinitionIndex <sizeof (ixEthDBTrafficClassDefinitions) /sizeof (ixEthDBTrafficClassDefinitions[0 ]); + trafficClassDefinitionIndex <ARRAY_SIZE (ixEthDBTrafficClassDefinitions); trafficClassDefinitionIndex++) {if (ixEthDBTrafficClassDefinitions[trafficClassDefinitionIndex][IX_ETH_DB_NPE_A_FUNCTIONALITY_ID_INDEX ] == npeAImageId.functionalityId)
@@ -155,7 +155,7 @@ void ixEthDBFeatureCapabilityScan(void) }/* select the default case if we went over the array boundary */ -if (trafficClassDefinitionIndex ==sizeof (ixEthDBTrafficClassDefinitions) /sizeof (ixEthDBTrafficClassDefinitions[0 ])) +if (trafficClassDefinitionIndex ==ARRAY_SIZE (ixEthDBTrafficClassDefinitions)) { trafficClassDefinitionIndex =0 ;/* the first record is the default case */ }
drivers/net/npe/IxOsalIoMem.c +1 -2
@@ -66,8 +66,7 @@ ixOsalMemMapFind (UINT32 requestedAddress, {UINT32 mapIndex; -UINT32 numMapElements = -sizeof (ixOsalGlobalMemoryMap) /sizeof (IxOsalMemoryMap); +UINT32 numMapElements =ARRAY_SIZE (ixOsalGlobalMemoryMap);for (mapIndex =0 ; mapIndex < numMapElements; mapIndex++) {
drivers/net/npe/include/IxEthDBPortDefs.h +1 -1
@@ -106,7 +106,7 @@ static const IxEthDBPortDefinition ixEthDBPortDefinitions[] =* @def IX_ETH_DB_NUMBER_OF_PORTS * @brief number of supported ports */ -#define IX_ETH_DB_NUMBER_OF_PORTS (sizeof (ixEthDBPortDefinitions) / sizeof (ixEthDBPortDefinitions[0])) +#define IX_ETH_DB_NUMBER_OF_PORTS ARRAY_SIZE(ixEthDBPortDefinitions)/** * @def IX_ETH_DB_UNKNOWN_PORT
drivers/net/npe/include/IxOsalTypes.h +1 -1
@@ -93,7 +93,7 @@ typedef volatile INT32 VINT32;#ifndef NUMELEMS -#define NUMELEMS (x) (sizeof(x) / sizeof((x)[0])) +#define NUMELEMS (x) ARRAY_SIZE(x)#endif
Signature · 1 line
1.8.1.2
PATCH 1/1 net: Use ARRAY_SIZE at appropriate places
Hi Axel,
Quoted 21 lines · Axel Lin
Use
ARRAY_SIZEinstead of having similar implementation in each drivers.Signed-off-by Axel Lin <[email protected]>Cc Albert Aribaud <[email protected]>Cc Ben Warren <[email protected]>Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>Cc Joe Hershberger <[email protected]>Cc Marek Vasut <[email protected]>Cc Mike Frysinger <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>Cc TsiChungLiew <[email protected]>Cc Wolfgang Denk <[email protected]>Cc York Sun <[email protected]>---
Hi,tools/checkpatch.plshows
total: 2 errors, 12 warnings, 0 checks, 89 lines checkedThe errors are:
ERROR: code indent should use tabs where possible
Quoted 7 lines
The warnings are something like below:
WARNING: line over 80 characters
WARNING: please, no spaces at the start of a line
WARNING: Avoid CamelCase: <ixEthDBPortDefinitions>I don't fixup the checkpatch.pl issues because I feel having the patch as is seems cleaner.
Please fix these WARNINGS/ERRORS, as these comes issues comes up with your changed code-
--
Thanks,
Jagan.
Quoted 165 lines
Regards,
Axeldrivers/net/ax88180.c | 2 +- drivers/net/fsl_mcdmafec.c | 2 +- drivers/net/lan91c96.c | 2 +- drivers/net/mcffec.c | 2 +- drivers/net/mcfmii.c | 2 +- drivers/net/ne2000.c | 2 +- drivers/net/npe/IxEthDBFeatures.c | 4 ++-- drivers/net/npe/IxOsalIoMem.c | 3 +-- drivers/net/npe/include/IxEthDBPortDefs.h | 2 +- drivers/net/npe/include/IxOsalTypes.h | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-)drivers/net/ax88180.c +1
-1@@ -157,7 +157,7 @@ static void ax88180_mac_reset (struct eth_device *dev)OUTW (dev,MISC_RESET_MAC ,MISC ); tmpval =INW (dev,MISC ); -for (i =0 ; i < (sizeof (program_seq) /sizeof (program_seq[0 ])); i++) +for (i =0 ; i <ARRAY_SIZE (program_seq); i++)OUTW (dev, program_seq[i].value, program_seq[i].offset); }drivers/net/fsl_mcdmafec.c +1
-1@@ -520,7 +520,7 @@ int mcdmafec_initialize(bd_t * bis)u32 tmp =CONFIG_SYS_INTSRAM +0x2000 ;#endif -for (i =0 ; i <sizeof (fec_info) /sizeof (fec_info[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (fec_info); i++) { dev = (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE,drivers/net/lan91c96.c +1
-1@@ -779,7 +779,7 @@ static int lan91c96_detect_chip(struct eth_device *dev)SMC_SELECT_BANK (dev,3 ); chip_id = (SMC_inw (dev,0xA ) &LAN91C96_REV_CHIPID ) >>4 ;SMC_SELECT_BANK (dev,0 ); -for (r =0 ; r <sizeof (supported_chips) /sizeof (struct id_type ); r++) +for (r =0 ; r <ARRAY_SIZE (supported_chips); r++)if (chip_id == supported_chips[r].id)return r;return 0 ;drivers/net/mcffec.c +1
-1@@ -559,7 +559,7 @@ int mcffec_initialize(bd_t * bis)u32 tmp =CONFIG_SYS_INIT_RAM_ADDR +0x1000 ;#endif -for (i =0 ; i <sizeof (fec_info) /sizeof (fec_info[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (fec_info); i++) { dev = (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE,drivers/net/mcfmii.c +1
-1@@ -186,7 +186,7 @@ int mii_discover_phy(struct eth_device *dev)printf ("PHY @ 0x%x pass %d\n" , phyno, pass);#endif -for (i =0 ; (i < (sizeof (phyinfo) /sizeof (phy_info_t))) +for (i =0 ; (i <ARRAY_SIZE (phyinfo)) && (phyinfo[i].phyid !=0 ); i++) {if (phyinfo[i].phyid == phytype) {#ifdef ET_DEBUG drivers/net/ne2000.c +1
-1@@ -228,7 +228,7 @@ int get_prom(u8* mac_addr, u8* base_addr)mdelay (10 ); -for (i =0 ; i <sizeof (program_seq) /sizeof (program_seq[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (program_seq); i++)n2k_outb (program_seq[i].value, program_seq[i].offset);PRINTK ("PROM:" );drivers/net/npe/IxEthDBFeatures.c +2
-2@@ -144,7 +144,7 @@ void ixEthDBFeatureCapabilityScan(void)/* find the traffic class definition index compatible with the current NPE A functionality ID */ for (trafficClassDefinitionIndex =0 ; - trafficClassDefinitionIndex <sizeof (ixEthDBTrafficClassDefinitions) /sizeof (ixEthDBTrafficClassDefinitions[0 ]); + trafficClassDefinitionIndex <ARRAY_SIZE (ixEthDBTrafficClassDefinitions); trafficClassDefinitionIndex++) {if (ixEthDBTrafficClassDefinitions[trafficClassDefinitionIndex][IX_ETH_DB_NPE_A_FUNCTIONALITY_ID_INDEX ] == npeAImageId.functionalityId)@@ -155,7 +155,7 @@ void ixEthDBFeatureCapabilityScan(void) }/* select the default case if we went over the array boundary */ -if (trafficClassDefinitionIndex ==sizeof (ixEthDBTrafficClassDefinitions) /sizeof (ixEthDBTrafficClassDefinitions[0 ])) +if (trafficClassDefinitionIndex ==ARRAY_SIZE (ixEthDBTrafficClassDefinitions)) { trafficClassDefinitionIndex =0 ;/* the first record is the default case */ }drivers/net/npe/IxOsalIoMem.c +1
-2@@ -66,8 +66,7 @@ ixOsalMemMapFind (UINT32 requestedAddress, {UINT32 mapIndex; -UINT32 numMapElements = -sizeof (ixOsalGlobalMemoryMap) /sizeof (IxOsalMemoryMap); +UINT32 numMapElements =ARRAY_SIZE (ixOsalGlobalMemoryMap);for (mapIndex =0 ; mapIndex < numMapElements; mapIndex++) {drivers/net/npe/include/IxEthDBPortDefs.h +1
-1@@ -106,7 +106,7 @@ static const IxEthDBPortDefinition ixEthDBPortDefinitions[] =* @def IX_ETH_DB_NUMBER_OF_PORTS * @brief number of supported ports */ -#define IX_ETH_DB_NUMBER_OF_PORTS (sizeof (ixEthDBPortDefinitions) / sizeof (ixEthDBPortDefinitions[0])) +#define IX_ETH_DB_NUMBER_OF_PORTS ARRAY_SIZE(ixEthDBPortDefinitions)/** * @def IX_ETH_DB_UNKNOWN_PORT drivers/net/npe/include/IxOsalTypes.h +1
-2@@ -93,7 +93,7 @@ typedef volatile INT32 VINT32;#ifndef NUMELEMS -#define NUMELEMS (x) (sizeof(x) / sizeof((x)[0])) +#define NUMELEMS (x) ARRAY_SIZE(x)#endif --1.8.1.2
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
PATCH 1/1 net: Use ARRAY_SIZE at appropriate places
In reply to Axel LinDear Axel Lin,
Quoted 13 lines
Use
ARRAY_SIZEinstead of having similar implementation in each drivers.Signed-off-by Axel Lin <[email protected]>Cc Albert Aribaud <[email protected]>Cc Ben Warren <[email protected]>Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>Cc Joe Hershberger <[email protected]>Cc Marek Vasut <[email protected]>Cc Mike Frysinger <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>Cc TsiChungLiew <[email protected]>Cc Wolfgang Denk <[email protected]>Cc York Sun <[email protected]>
You can trim the CC a bit next time ;-)
Quoted 8 lines
---
Hi,tools/checkpatch.plshows
total: 2 errors, 12 warnings, 0 checks, 89 lines checkedThe errors are:
ERROR: code indent should use tabs where possible
Quoted 7 lines
The warnings are something like below:
WARNING: line over 80 characters
WARNING: please, no spaces at the start of a line
WARNING: Avoid CamelCase: <ixEthDBPortDefinitions>I don't fixup the checkpatch.pl issues because I feel having the patch as is seems cleaner.
No problem on my end, that's understandable.
Quoted 14 lines
Regards,
Axeldrivers/net/ax88180.c | 2 +- drivers/net/fsl_mcdmafec.c | 2 +- drivers/net/lan91c96.c | 2 +- drivers/net/mcffec.c | 2 +- drivers/net/mcfmii.c | 2 +- drivers/net/ne2000.c | 2 +- drivers/net/npe/IxEthDBFeatures.c | 4 ++-- drivers/net/npe/IxOsalIoMem.c | 3 +-- drivers/net/npe/include/IxEthDBPortDefs.h | 2 +- drivers/net/npe/include/IxOsalTypes.h | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-)
[...]
drivers/net/npe/include/IxOsalTypes.h typedef volatile INT32 VINT32; · line 97
Quoted 12 lines
* @def
IX_ETH_DB_UNKNOWN_PORT(quoted diff) +0
-0
b/drivers/net/npe/include/IxOsalTypes.hindex 06e71de..615c655 100644drivers/net/npe/include/IxOsalTypes.h +1
-1@@ -93,7 +93,7 @@ typedef volatile INT32 VINT32;#ifndef NUMELEMS -#define NUMELEMS (x) (sizeof(x) / sizeof((x)[0])) +#define NUMELEMS (x) ARRAY_SIZE(x)#endif
Just kill this macro altogether please.
Best regards,
Marek Vasut
PATCH 1/1 net: Use ARRAY_SIZE at appropriate places
2013/6/30 Marek Vasut <[email protected]>:
Quoted 16 lines
Dear Axel Lin,
Quoted 13 lines
Use
ARRAY_SIZEinstead of having similar implementation in each drivers.Signed-off-by Axel Lin <[email protected]>Cc Albert Aribaud <[email protected]>Cc Ben Warren <[email protected]>Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>Cc Joe Hershberger <[email protected]>Cc Marek Vasut <[email protected]>Cc Mike Frysinger <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>Cc TsiChungLiew <[email protected]>Cc Wolfgang Denk <[email protected]>Cc York Sun <[email protected]>
Quoted 1 line
You can trim the CC a bit next time ;-)
Hi Marek,
I try to cc related people. the maintainers, the driver authers, and developer who is active in recent commits.
Is there a smarter way to find who should be CCed? Some tool like get_maintainer.pl used in linux kernel may help.
Regards,
Axel
PATCH 1/1 net: Use ARRAY_SIZE at appropriate places
In reply to Marek VasutQuoted 7 lines
Quoted 7 lines
(quoted diff) +0
-0
b/drivers/net/npe/include/IxOsalTypes.hindex 06e71de..615c655 100644drivers/net/npe/include/IxOsalTypes.h +0
-0@@ -93,7 +93,7 @@ typedef volatile INT32 VINT32;
Quoted 6 lines
drivers/net/npe/include/IxOsalTypes.h typedef volatile INT32 VINT32; · line 97
Quoted 4 lines
drivers/net/npe/include/IxOsalTypes.h +1
-1#ifndef NUMELEMS -#define NUMELEMS (x) (sizeof(x) / sizeof((x)[0])) +#define NUMELEMS (x) ARRAY_SIZE(x)#endif Just kill this macro altogether please.
Ah, yes. I missed your comment here when I reply the mail. NUMELEMS is not used at all so it can be removed. Will fix it in v3.
I just sent v2 per Jagan Teki's request.
I think I'll wait for Jagan Teki's feedback before sending v3.
Thanks for the review.
Axel