All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 11/16] trivial: use ARRAY_SIZE
@ 2010-06-28 11:55 ` Kulikov Vasiliy
  0 siblings, 0 replies; 13+ messages in thread
From: Kulikov Vasiliy @ 2010-06-28 11:55 UTC (permalink / raw)
  To: trivial
  Cc: Kernel Janitors, Greg Kroah-Hartman, Kulikov Vasiliy,
	Simon Horman, Andrea Gelmini, devel, linux-kernel

Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).

Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
---
 drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
index da3b774..9b04653 100644
--- a/drivers/staging/otus/hal/hpreg.c
+++ b/drivers/staging/otus/hal/hpreg.c
@@ -29,9 +29,6 @@
 #include "hpreg.h"
 #include "hpusb.h"
 
-/* used throughout this file... */
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
-
 #define HAL_MODE_11A_TURBO	HAL_MODE_108A
 #define HAL_MODE_11G_TURBO	HAL_MODE_108G
 
@@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
 	u64_t flags = NO_REQ;
 	REG_DMN_PAIR_MAPPING *regPair = NULL;
 
-	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
+	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
 		if (regDomainPairs[i].regDmnEnum == regionCode) {
 			regPair = &regDomainPairs[i];
 			found = 1;
@@ -1581,7 +1578,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
 	 * unitary reg domain of the pair
 	 */
 
-	for (i = 0 ; i < N(regDomains) ; i++) {
+	for (i = 0 ; i < ARRAY_SIZE(regDomains) ; i++) {
 		if (regDomains[i].regDmnEnum == regDmn) {
 			if (rd != NULL) {
 					zfMemoryCopy((u8_t *)rd, (u8_t *)&regDomains[i],
@@ -1653,7 +1650,7 @@ void zfHpGetRegulationTable(zdev_t *dev, u16_t regionCode, u16_t c_lo, u16_t c_h
 
 	zmw_enter_critical_section(dev);
 
-	for (cm = modes; cm < &modes[N(modes)]; cm++) {
+	for (cm = modes; cm < &modes[ARRAY_SIZE(modes)]; cm++) {
 		u16_t c;
 		u64_t *channelBM = NULL;
 		REG_DOMAIN *rd = NULL;
@@ -1846,7 +1843,7 @@ void zfHpGetRegulationTablefromCountry(zdev_t *dev, u16_t CountryCode)
 
 	zmw_declare_for_critical_section();
 
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		if (CountryCode == allCountries[i].countryCode) {
 			RegDomain = allCountries[i].regDmnEnum;
 
@@ -1881,7 +1878,7 @@ u8_t zfHpGetRegulationTablefromISO(zdev_t *dev, u8_t *countryInfo, u8_t length)
 		strLen = 3; */
 	}
 	/* zm_debug_msg_s("Desired iso name = ", isoName); */
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		/* zm_debug_msg_s("Current iso name = ", allCountries[i].isoName); */
 		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, (u8_t *)&countryInfo[2], length-1)) {
 			/* DbgPrint("Set current iso name = %s\n", allCountries[i].isoName); */
@@ -1937,7 +1934,7 @@ const char *zfHpGetisoNamefromregionCode(zdev_t *dev, u16_t regionCode)
 {
 	u16_t i;
 
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		if (allCountries[i].regDmnEnum == regionCode)
 			return allCountries[i].isoName;
 	}
@@ -1953,7 +1950,7 @@ u16_t zfHpGetRegionCodeFromIsoName(zdev_t *dev, u8_t *countryIsoName)
 	/* if no matching item, return default */
 	regionCode = DEF_REGDMN;
 
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, countryIsoName, 2)) {
 			regionCode = allCountries[i].regDmnEnum;
 		break;
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 11/16] trivial: use ARRAY_SIZE
@ 2010-06-28 11:55 ` Kulikov Vasiliy
  0 siblings, 0 replies; 13+ messages in thread
From: Kulikov Vasiliy @ 2010-06-28 11:55 UTC (permalink / raw)
  To: trivial
  Cc: Kernel Janitors, Greg Kroah-Hartman, Kulikov Vasiliy,
	Simon Horman, Andrea Gelmini, devel, linux-kernel

Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).

Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
---
 drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
index da3b774..9b04653 100644
--- a/drivers/staging/otus/hal/hpreg.c
+++ b/drivers/staging/otus/hal/hpreg.c
@@ -29,9 +29,6 @@
 #include "hpreg.h"
 #include "hpusb.h"
 
-/* used throughout this file... */
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
-
 #define HAL_MODE_11A_TURBO	HAL_MODE_108A
 #define HAL_MODE_11G_TURBO	HAL_MODE_108G
 
@@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
 	u64_t flags = NO_REQ;
 	REG_DMN_PAIR_MAPPING *regPair = NULL;
 
-	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
+	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
 		if (regDomainPairs[i].regDmnEnum = regionCode) {
 			regPair = &regDomainPairs[i];
 			found = 1;
@@ -1581,7 +1578,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
 	 * unitary reg domain of the pair
 	 */
 
-	for (i = 0 ; i < N(regDomains) ; i++) {
+	for (i = 0 ; i < ARRAY_SIZE(regDomains) ; i++) {
 		if (regDomains[i].regDmnEnum = regDmn) {
 			if (rd != NULL) {
 					zfMemoryCopy((u8_t *)rd, (u8_t *)&regDomains[i],
@@ -1653,7 +1650,7 @@ void zfHpGetRegulationTable(zdev_t *dev, u16_t regionCode, u16_t c_lo, u16_t c_h
 
 	zmw_enter_critical_section(dev);
 
-	for (cm = modes; cm < &modes[N(modes)]; cm++) {
+	for (cm = modes; cm < &modes[ARRAY_SIZE(modes)]; cm++) {
 		u16_t c;
 		u64_t *channelBM = NULL;
 		REG_DOMAIN *rd = NULL;
@@ -1846,7 +1843,7 @@ void zfHpGetRegulationTablefromCountry(zdev_t *dev, u16_t CountryCode)
 
 	zmw_declare_for_critical_section();
 
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		if (CountryCode = allCountries[i].countryCode) {
 			RegDomain = allCountries[i].regDmnEnum;
 
@@ -1881,7 +1878,7 @@ u8_t zfHpGetRegulationTablefromISO(zdev_t *dev, u8_t *countryInfo, u8_t length)
 		strLen = 3; */
 	}
 	/* zm_debug_msg_s("Desired iso name = ", isoName); */
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		/* zm_debug_msg_s("Current iso name = ", allCountries[i].isoName); */
 		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, (u8_t *)&countryInfo[2], length-1)) {
 			/* DbgPrint("Set current iso name = %s\n", allCountries[i].isoName); */
@@ -1937,7 +1934,7 @@ const char *zfHpGetisoNamefromregionCode(zdev_t *dev, u16_t regionCode)
 {
 	u16_t i;
 
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		if (allCountries[i].regDmnEnum = regionCode)
 			return allCountries[i].isoName;
 	}
@@ -1953,7 +1950,7 @@ u16_t zfHpGetRegionCodeFromIsoName(zdev_t *dev, u8_t *countryIsoName)
 	/* if no matching item, return default */
 	regionCode = DEF_REGDMN;
 
-	for (i = 0; i < N(allCountries); i++) {
+	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
 		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, countryIsoName, 2)) {
 			regionCode = allCountries[i].regDmnEnum;
 		break;
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
  2010-06-28 11:55 ` Kulikov Vasiliy
@ 2010-06-28 12:42   ` walter harms
  -1 siblings, 0 replies; 13+ messages in thread
From: walter harms @ 2010-06-28 12:42 UTC (permalink / raw)
  To: Kulikov Vasiliy
  Cc: trivial, Kernel Janitors, Greg Kroah-Hartman, Simon Horman,
	Andrea Gelmini, devel, linux-kernel



Kulikov Vasiliy schrieb:
> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
> 
> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
> ---
>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
>  1 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
> index da3b774..9b04653 100644
> --- a/drivers/staging/otus/hal/hpreg.c
> +++ b/drivers/staging/otus/hal/hpreg.c
> @@ -29,9 +29,6 @@
>  #include "hpreg.h"
>  #include "hpusb.h"
>  
> -/* used throughout this file... */
> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
> -
>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
>  
> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	u64_t flags = NO_REQ;
>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
>  
> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
>  		if (regDomainPairs[i].regDmnEnum == regionCode) {
>  			regPair = &regDomainPairs[i];
>  			found = 1;



This looks odd, i do not see the rest of the code but perhaps a break would help
to eleminate the "found" ??

just my two cents,
 wh


> @@ -1581,7 +1578,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	 * unitary reg domain of the pair
>  	 */
>  
> -	for (i = 0 ; i < N(regDomains) ; i++) {
> +	for (i = 0 ; i < ARRAY_SIZE(regDomains) ; i++) {
>  		if (regDomains[i].regDmnEnum == regDmn) {
>  			if (rd != NULL) {
>  					zfMemoryCopy((u8_t *)rd, (u8_t *)&regDomains[i],
> @@ -1653,7 +1650,7 @@ void zfHpGetRegulationTable(zdev_t *dev, u16_t regionCode, u16_t c_lo, u16_t c_h
>  
>  	zmw_enter_critical_section(dev);
>  
> -	for (cm = modes; cm < &modes[N(modes)]; cm++) {
> +	for (cm = modes; cm < &modes[ARRAY_SIZE(modes)]; cm++) {
>  		u16_t c;
>  		u64_t *channelBM = NULL;
>  		REG_DOMAIN *rd = NULL;
> @@ -1846,7 +1843,7 @@ void zfHpGetRegulationTablefromCountry(zdev_t *dev, u16_t CountryCode)
>  
>  	zmw_declare_for_critical_section();
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (CountryCode == allCountries[i].countryCode) {
>  			RegDomain = allCountries[i].regDmnEnum;
>  
> @@ -1881,7 +1878,7 @@ u8_t zfHpGetRegulationTablefromISO(zdev_t *dev, u8_t *countryInfo, u8_t length)
>  		strLen = 3; */
>  	}
>  	/* zm_debug_msg_s("Desired iso name = ", isoName); */
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		/* zm_debug_msg_s("Current iso name = ", allCountries[i].isoName); */
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, (u8_t *)&countryInfo[2], length-1)) {
>  			/* DbgPrint("Set current iso name = %s\n", allCountries[i].isoName); */
> @@ -1937,7 +1934,7 @@ const char *zfHpGetisoNamefromregionCode(zdev_t *dev, u16_t regionCode)
>  {
>  	u16_t i;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (allCountries[i].regDmnEnum == regionCode)
>  			return allCountries[i].isoName;
>  	}
> @@ -1953,7 +1950,7 @@ u16_t zfHpGetRegionCodeFromIsoName(zdev_t *dev, u8_t *countryIsoName)
>  	/* if no matching item, return default */
>  	regionCode = DEF_REGDMN;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, countryIsoName, 2)) {
>  			regionCode = allCountries[i].regDmnEnum;
>  		break;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
@ 2010-06-28 12:42   ` walter harms
  0 siblings, 0 replies; 13+ messages in thread
From: walter harms @ 2010-06-28 12:42 UTC (permalink / raw)
  To: Kulikov Vasiliy
  Cc: trivial, Kernel Janitors, Greg Kroah-Hartman, Simon Horman,
	Andrea Gelmini, devel, linux-kernel



Kulikov Vasiliy schrieb:
> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
> 
> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
> ---
>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
>  1 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
> index da3b774..9b04653 100644
> --- a/drivers/staging/otus/hal/hpreg.c
> +++ b/drivers/staging/otus/hal/hpreg.c
> @@ -29,9 +29,6 @@
>  #include "hpreg.h"
>  #include "hpusb.h"
>  
> -/* used throughout this file... */
> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
> -
>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
>  
> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	u64_t flags = NO_REQ;
>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
>  
> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
>  		if (regDomainPairs[i].regDmnEnum = regionCode) {
>  			regPair = &regDomainPairs[i];
>  			found = 1;



This looks odd, i do not see the rest of the code but perhaps a break would help
to eleminate the "found" ??

just my two cents,
 wh


> @@ -1581,7 +1578,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	 * unitary reg domain of the pair
>  	 */
>  
> -	for (i = 0 ; i < N(regDomains) ; i++) {
> +	for (i = 0 ; i < ARRAY_SIZE(regDomains) ; i++) {
>  		if (regDomains[i].regDmnEnum = regDmn) {
>  			if (rd != NULL) {
>  					zfMemoryCopy((u8_t *)rd, (u8_t *)&regDomains[i],
> @@ -1653,7 +1650,7 @@ void zfHpGetRegulationTable(zdev_t *dev, u16_t regionCode, u16_t c_lo, u16_t c_h
>  
>  	zmw_enter_critical_section(dev);
>  
> -	for (cm = modes; cm < &modes[N(modes)]; cm++) {
> +	for (cm = modes; cm < &modes[ARRAY_SIZE(modes)]; cm++) {
>  		u16_t c;
>  		u64_t *channelBM = NULL;
>  		REG_DOMAIN *rd = NULL;
> @@ -1846,7 +1843,7 @@ void zfHpGetRegulationTablefromCountry(zdev_t *dev, u16_t CountryCode)
>  
>  	zmw_declare_for_critical_section();
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (CountryCode = allCountries[i].countryCode) {
>  			RegDomain = allCountries[i].regDmnEnum;
>  
> @@ -1881,7 +1878,7 @@ u8_t zfHpGetRegulationTablefromISO(zdev_t *dev, u8_t *countryInfo, u8_t length)
>  		strLen = 3; */
>  	}
>  	/* zm_debug_msg_s("Desired iso name = ", isoName); */
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		/* zm_debug_msg_s("Current iso name = ", allCountries[i].isoName); */
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, (u8_t *)&countryInfo[2], length-1)) {
>  			/* DbgPrint("Set current iso name = %s\n", allCountries[i].isoName); */
> @@ -1937,7 +1934,7 @@ const char *zfHpGetisoNamefromregionCode(zdev_t *dev, u16_t regionCode)
>  {
>  	u16_t i;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (allCountries[i].regDmnEnum = regionCode)
>  			return allCountries[i].isoName;
>  	}
> @@ -1953,7 +1950,7 @@ u16_t zfHpGetRegionCodeFromIsoName(zdev_t *dev, u8_t *countryIsoName)
>  	/* if no matching item, return default */
>  	regionCode = DEF_REGDMN;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, countryIsoName, 2)) {
>  			regionCode = allCountries[i].regDmnEnum;
>  		break;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
  2010-06-28 12:42   ` walter harms
@ 2010-06-28 13:22     ` walter harms
  -1 siblings, 0 replies; 13+ messages in thread
From: walter harms @ 2010-06-28 13:22 UTC (permalink / raw)
  To: Kulikov Vasiliy
  Cc: trivial, Kernel Janitors, Greg Kroah-Hartman, Simon Horman,
	Andrea Gelmini, devel, linux-kernel



walter harms schrieb:
> 
> Kulikov Vasiliy schrieb:
>> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
>>
>> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
>> ---
>>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
>>  1 files changed, 7 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
>> index da3b774..9b04653 100644
>> --- a/drivers/staging/otus/hal/hpreg.c
>> +++ b/drivers/staging/otus/hal/hpreg.c
>> @@ -29,9 +29,6 @@
>>  #include "hpreg.h"
>>  #include "hpusb.h"
>>  
>> -/* used throughout this file... */
>> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
>> -
>>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
>>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
>>  
>> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>>  	u64_t flags = NO_REQ;
>>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
>>  
>> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
>> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
>>  		if (regDomainPairs[i].regDmnEnum == regionCode) {
>>  			regPair = &regDomainPairs[i];
>>  			found = 1;
> 
> 
> 
> This looks odd, i do not see the rest of the code but perhaps a break would help
> to eleminate the "found" ??
> 
> just my two cents,
>  wh
> 
1554 u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
1555 {
1556         s16_t i, found, regDmn;
1557         u64_t flags=NO_REQ;
1558         REG_DMN_PAIR_MAPPING *regPair=NULL;
1559
1560         for (i=0, found=0; (i<N(regDomainPairs))&&(!found); i++)
1561         {
1562                 if (regDomainPairs[i].regDmnEnum == regionCode)
1563                 {
1564                         regPair = &regDomainPairs[i];
1565                         found = 1;
1566                 }
1567         }
1568         if (!found)
1569         {
1570                 zm_debug_msg1("Failed to find reg domain pair ", regionCode);
1571                 return FALSE;
1572         }


This is would stop at the first hit and work without found.
Otherwise someone could add an {NULL} at the end of the array
und use a while () that would eliminate the need for ARRAY_SIZE also.

re,
 wh

for (i=0; i<ARRAY_SIZE(regDomainPairs);i++ )
	if (regDomainPairs[i].regDmnEnum == regionCode)
                    { regPair = &regDomainPairs[i]; break ; }

if (!regPair) {
        zm_debug_msg1("Failed to find reg domain pair ", regionCode);
        return FALSE;
}




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
@ 2010-06-28 13:22     ` walter harms
  0 siblings, 0 replies; 13+ messages in thread
From: walter harms @ 2010-06-28 13:22 UTC (permalink / raw)
  To: Kulikov Vasiliy
  Cc: trivial, Kernel Janitors, Greg Kroah-Hartman, Simon Horman,
	Andrea Gelmini, devel, linux-kernel



walter harms schrieb:
> 
> Kulikov Vasiliy schrieb:
>> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
>>
>> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
>> ---
>>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
>>  1 files changed, 7 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
>> index da3b774..9b04653 100644
>> --- a/drivers/staging/otus/hal/hpreg.c
>> +++ b/drivers/staging/otus/hal/hpreg.c
>> @@ -29,9 +29,6 @@
>>  #include "hpreg.h"
>>  #include "hpusb.h"
>>  
>> -/* used throughout this file... */
>> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
>> -
>>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
>>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
>>  
>> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>>  	u64_t flags = NO_REQ;
>>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
>>  
>> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
>> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
>>  		if (regDomainPairs[i].regDmnEnum = regionCode) {
>>  			regPair = &regDomainPairs[i];
>>  			found = 1;
> 
> 
> 
> This looks odd, i do not see the rest of the code but perhaps a break would help
> to eleminate the "found" ??
> 
> just my two cents,
>  wh
> 
1554 u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
1555 {
1556         s16_t i, found, regDmn;
1557         u64_t flags=NO_REQ;
1558         REG_DMN_PAIR_MAPPING *regPair=NULL;
1559
1560         for (i=0, found=0; (i<N(regDomainPairs))&&(!found); i++)
1561         {
1562                 if (regDomainPairs[i].regDmnEnum = regionCode)
1563                 {
1564                         regPair = &regDomainPairs[i];
1565                         found = 1;
1566                 }
1567         }
1568         if (!found)
1569         {
1570                 zm_debug_msg1("Failed to find reg domain pair ", regionCode);
1571                 return FALSE;
1572         }


This is would stop at the first hit and work without found.
Otherwise someone could add an {NULL} at the end of the array
und use a while () that would eliminate the need for ARRAY_SIZE also.

re,
 wh

for (i=0; i<ARRAY_SIZE(regDomainPairs);i++ )
	if (regDomainPairs[i].regDmnEnum = regionCode)
                    { regPair = &regDomainPairs[i]; break ; }

if (!regPair) {
        zm_debug_msg1("Failed to find reg domain pair ", regionCode);
        return FALSE;
}




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
  2010-06-28 13:22     ` walter harms
@ 2010-06-29  0:58       ` Simon Horman
  -1 siblings, 0 replies; 13+ messages in thread
From: Simon Horman @ 2010-06-29  0:58 UTC (permalink / raw)
  To: walter harms
  Cc: Kulikov Vasiliy, trivial, Kernel Janitors, Greg Kroah-Hartman,
	Andrea Gelmini, devel, linux-kernel

On Mon, Jun 28, 2010 at 03:22:49PM +0200, walter harms wrote:
> 
> 
> walter harms schrieb:
> > 
> > Kulikov Vasiliy schrieb:
> >> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
> >>
> >> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
> >> ---
> >>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
> >>  1 files changed, 7 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
> >> index da3b774..9b04653 100644
> >> --- a/drivers/staging/otus/hal/hpreg.c
> >> +++ b/drivers/staging/otus/hal/hpreg.c
> >> @@ -29,9 +29,6 @@
> >>  #include "hpreg.h"
> >>  #include "hpusb.h"
> >>  
> >> -/* used throughout this file... */
> >> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
> >> -
> >>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
> >>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
> >>  
> >> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
> >>  	u64_t flags = NO_REQ;
> >>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
> >>  
> >> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
> >> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
> >>  		if (regDomainPairs[i].regDmnEnum == regionCode) {
> >>  			regPair = &regDomainPairs[i];
> >>  			found = 1;
> > 
> > 
> > 
> > This looks odd, i do not see the rest of the code but perhaps a break would help
> > to eleminate the "found" ??
> > 
> > just my two cents,
> >  wh
> > 
> 1554 u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
> 1555 {
> 1556         s16_t i, found, regDmn;
> 1557         u64_t flags=NO_REQ;
> 1558         REG_DMN_PAIR_MAPPING *regPair=NULL;
> 1559
> 1560         for (i=0, found=0; (i<N(regDomainPairs))&&(!found); i++)
> 1561         {
> 1562                 if (regDomainPairs[i].regDmnEnum == regionCode)
> 1563                 {
> 1564                         regPair = &regDomainPairs[i];
> 1565                         found = 1;
> 1566                 }
> 1567         }
> 1568         if (!found)
> 1569         {
> 1570                 zm_debug_msg1("Failed to find reg domain pair ", regionCode);
> 1571                 return FALSE;
> 1572         }
> 
> 
> This is would stop at the first hit and work without found.
> Otherwise someone could add an {NULL} at the end of the array
> und use a while () that would eliminate the need for ARRAY_SIZE also.

Either of those suggestions sounds fine to me, but it sounds
like it should be in a separate patch.

> 
> re,
>  wh
> 
> for (i=0; i<ARRAY_SIZE(regDomainPairs);i++ )
> 	if (regDomainPairs[i].regDmnEnum == regionCode)
>                     { regPair = &regDomainPairs[i]; break ; }
> 
> if (!regPair) {
>         zm_debug_msg1("Failed to find reg domain pair ", regionCode);
>         return FALSE;
> }
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
@ 2010-06-29  0:58       ` Simon Horman
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Horman @ 2010-06-29  0:58 UTC (permalink / raw)
  To: walter harms
  Cc: Kulikov Vasiliy, trivial, Kernel Janitors, Greg Kroah-Hartman,
	Andrea Gelmini, devel, linux-kernel

On Mon, Jun 28, 2010 at 03:22:49PM +0200, walter harms wrote:
> 
> 
> walter harms schrieb:
> > 
> > Kulikov Vasiliy schrieb:
> >> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
> >>
> >> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
> >> ---
> >>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
> >>  1 files changed, 7 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
> >> index da3b774..9b04653 100644
> >> --- a/drivers/staging/otus/hal/hpreg.c
> >> +++ b/drivers/staging/otus/hal/hpreg.c
> >> @@ -29,9 +29,6 @@
> >>  #include "hpreg.h"
> >>  #include "hpusb.h"
> >>  
> >> -/* used throughout this file... */
> >> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
> >> -
> >>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
> >>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
> >>  
> >> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
> >>  	u64_t flags = NO_REQ;
> >>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
> >>  
> >> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
> >> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
> >>  		if (regDomainPairs[i].regDmnEnum = regionCode) {
> >>  			regPair = &regDomainPairs[i];
> >>  			found = 1;
> > 
> > 
> > 
> > This looks odd, i do not see the rest of the code but perhaps a break would help
> > to eleminate the "found" ??
> > 
> > just my two cents,
> >  wh
> > 
> 1554 u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
> 1555 {
> 1556         s16_t i, found, regDmn;
> 1557         u64_t flags=NO_REQ;
> 1558         REG_DMN_PAIR_MAPPING *regPair=NULL;
> 1559
> 1560         for (i=0, found=0; (i<N(regDomainPairs))&&(!found); i++)
> 1561         {
> 1562                 if (regDomainPairs[i].regDmnEnum = regionCode)
> 1563                 {
> 1564                         regPair = &regDomainPairs[i];
> 1565                         found = 1;
> 1566                 }
> 1567         }
> 1568         if (!found)
> 1569         {
> 1570                 zm_debug_msg1("Failed to find reg domain pair ", regionCode);
> 1571                 return FALSE;
> 1572         }
> 
> 
> This is would stop at the first hit and work without found.
> Otherwise someone could add an {NULL} at the end of the array
> und use a while () that would eliminate the need for ARRAY_SIZE also.

Either of those suggestions sounds fine to me, but it sounds
like it should be in a separate patch.

> 
> re,
>  wh
> 
> for (i=0; i<ARRAY_SIZE(regDomainPairs);i++ )
> 	if (regDomainPairs[i].regDmnEnum = regionCode)
>                     { regPair = &regDomainPairs[i]; break ; }
> 
> if (!regPair) {
>         zm_debug_msg1("Failed to find reg domain pair ", regionCode);
>         return FALSE;
> }
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
  2010-06-28 11:55 ` Kulikov Vasiliy
@ 2010-06-29  1:00   ` Simon Horman
  -1 siblings, 0 replies; 13+ messages in thread
From: Simon Horman @ 2010-06-29  1:00 UTC (permalink / raw)
  To: Kulikov Vasiliy
  Cc: trivial, Kernel Janitors, Greg Kroah-Hartman, Andrea Gelmini,
	devel, linux-kernel

On Mon, Jun 28, 2010 at 03:55:24PM +0400, Kulikov Vasiliy wrote:
> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
> 
> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>

Looks good.

Acked-by: Simon Horman <horms@verge.net.au>

> ---
>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
>  1 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
> index da3b774..9b04653 100644
> --- a/drivers/staging/otus/hal/hpreg.c
> +++ b/drivers/staging/otus/hal/hpreg.c
> @@ -29,9 +29,6 @@
>  #include "hpreg.h"
>  #include "hpusb.h"
>  
> -/* used throughout this file... */
> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
> -
>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
>  
> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	u64_t flags = NO_REQ;
>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
>  
> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
>  		if (regDomainPairs[i].regDmnEnum == regionCode) {
>  			regPair = &regDomainPairs[i];
>  			found = 1;
> @@ -1581,7 +1578,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	 * unitary reg domain of the pair
>  	 */
>  
> -	for (i = 0 ; i < N(regDomains) ; i++) {
> +	for (i = 0 ; i < ARRAY_SIZE(regDomains) ; i++) {
>  		if (regDomains[i].regDmnEnum == regDmn) {
>  			if (rd != NULL) {
>  					zfMemoryCopy((u8_t *)rd, (u8_t *)&regDomains[i],
> @@ -1653,7 +1650,7 @@ void zfHpGetRegulationTable(zdev_t *dev, u16_t regionCode, u16_t c_lo, u16_t c_h
>  
>  	zmw_enter_critical_section(dev);
>  
> -	for (cm = modes; cm < &modes[N(modes)]; cm++) {
> +	for (cm = modes; cm < &modes[ARRAY_SIZE(modes)]; cm++) {
>  		u16_t c;
>  		u64_t *channelBM = NULL;
>  		REG_DOMAIN *rd = NULL;
> @@ -1846,7 +1843,7 @@ void zfHpGetRegulationTablefromCountry(zdev_t *dev, u16_t CountryCode)
>  
>  	zmw_declare_for_critical_section();
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (CountryCode == allCountries[i].countryCode) {
>  			RegDomain = allCountries[i].regDmnEnum;
>  
> @@ -1881,7 +1878,7 @@ u8_t zfHpGetRegulationTablefromISO(zdev_t *dev, u8_t *countryInfo, u8_t length)
>  		strLen = 3; */
>  	}
>  	/* zm_debug_msg_s("Desired iso name = ", isoName); */
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		/* zm_debug_msg_s("Current iso name = ", allCountries[i].isoName); */
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, (u8_t *)&countryInfo[2], length-1)) {
>  			/* DbgPrint("Set current iso name = %s\n", allCountries[i].isoName); */
> @@ -1937,7 +1934,7 @@ const char *zfHpGetisoNamefromregionCode(zdev_t *dev, u16_t regionCode)
>  {
>  	u16_t i;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (allCountries[i].regDmnEnum == regionCode)
>  			return allCountries[i].isoName;
>  	}
> @@ -1953,7 +1950,7 @@ u16_t zfHpGetRegionCodeFromIsoName(zdev_t *dev, u8_t *countryIsoName)
>  	/* if no matching item, return default */
>  	regionCode = DEF_REGDMN;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, countryIsoName, 2)) {
>  			regionCode = allCountries[i].regDmnEnum;
>  		break;
> -- 
> 1.7.0.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
@ 2010-06-29  1:00   ` Simon Horman
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Horman @ 2010-06-29  1:00 UTC (permalink / raw)
  To: Kulikov Vasiliy
  Cc: trivial, Kernel Janitors, Greg Kroah-Hartman, Andrea Gelmini,
	devel, linux-kernel

On Mon, Jun 28, 2010 at 03:55:24PM +0400, Kulikov Vasiliy wrote:
> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
> 
> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>

Looks good.

Acked-by: Simon Horman <horms@verge.net.au>

> ---
>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
>  1 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
> index da3b774..9b04653 100644
> --- a/drivers/staging/otus/hal/hpreg.c
> +++ b/drivers/staging/otus/hal/hpreg.c
> @@ -29,9 +29,6 @@
>  #include "hpreg.h"
>  #include "hpusb.h"
>  
> -/* used throughout this file... */
> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
> -
>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
>  
> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	u64_t flags = NO_REQ;
>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
>  
> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
>  		if (regDomainPairs[i].regDmnEnum = regionCode) {
>  			regPair = &regDomainPairs[i];
>  			found = 1;
> @@ -1581,7 +1578,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>  	 * unitary reg domain of the pair
>  	 */
>  
> -	for (i = 0 ; i < N(regDomains) ; i++) {
> +	for (i = 0 ; i < ARRAY_SIZE(regDomains) ; i++) {
>  		if (regDomains[i].regDmnEnum = regDmn) {
>  			if (rd != NULL) {
>  					zfMemoryCopy((u8_t *)rd, (u8_t *)&regDomains[i],
> @@ -1653,7 +1650,7 @@ void zfHpGetRegulationTable(zdev_t *dev, u16_t regionCode, u16_t c_lo, u16_t c_h
>  
>  	zmw_enter_critical_section(dev);
>  
> -	for (cm = modes; cm < &modes[N(modes)]; cm++) {
> +	for (cm = modes; cm < &modes[ARRAY_SIZE(modes)]; cm++) {
>  		u16_t c;
>  		u64_t *channelBM = NULL;
>  		REG_DOMAIN *rd = NULL;
> @@ -1846,7 +1843,7 @@ void zfHpGetRegulationTablefromCountry(zdev_t *dev, u16_t CountryCode)
>  
>  	zmw_declare_for_critical_section();
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (CountryCode = allCountries[i].countryCode) {
>  			RegDomain = allCountries[i].regDmnEnum;
>  
> @@ -1881,7 +1878,7 @@ u8_t zfHpGetRegulationTablefromISO(zdev_t *dev, u8_t *countryInfo, u8_t length)
>  		strLen = 3; */
>  	}
>  	/* zm_debug_msg_s("Desired iso name = ", isoName); */
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		/* zm_debug_msg_s("Current iso name = ", allCountries[i].isoName); */
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, (u8_t *)&countryInfo[2], length-1)) {
>  			/* DbgPrint("Set current iso name = %s\n", allCountries[i].isoName); */
> @@ -1937,7 +1934,7 @@ const char *zfHpGetisoNamefromregionCode(zdev_t *dev, u16_t regionCode)
>  {
>  	u16_t i;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (allCountries[i].regDmnEnum = regionCode)
>  			return allCountries[i].isoName;
>  	}
> @@ -1953,7 +1950,7 @@ u16_t zfHpGetRegionCodeFromIsoName(zdev_t *dev, u8_t *countryIsoName)
>  	/* if no matching item, return default */
>  	regionCode = DEF_REGDMN;
>  
> -	for (i = 0; i < N(allCountries); i++) {
> +	for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
>  		if (zfMemoryIsEqual((u8_t *)allCountries[i].isoName, countryIsoName, 2)) {
>  			regionCode = allCountries[i].regDmnEnum;
>  		break;
> -- 
> 1.7.0.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
  2010-06-28 11:55 ` Kulikov Vasiliy
                   ` (2 preceding siblings ...)
  (?)
@ 2010-06-29  9:31 ` walter harms
  -1 siblings, 0 replies; 13+ messages in thread
From: walter harms @ 2010-06-29  9:31 UTC (permalink / raw)
  To: kernel-janitors



Simon Horman schrieb:
> On Mon, Jun 28, 2010 at 03:22:49PM +0200, walter harms wrote:
>>
>> walter harms schrieb:
>>> Kulikov Vasiliy schrieb:
>>>> Change sizeof(x) / sizeof(*x) to ARRAY_SIZE(x).
>>>>
>>>> Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
>>>> ---
>>>>  drivers/staging/otus/hal/hpreg.c |   17 +++++++----------
>>>>  1 files changed, 7 insertions(+), 10 deletions(-)
>>>>
>>>> diff --git a/drivers/staging/otus/hal/hpreg.c b/drivers/staging/otus/hal/hpreg.c
>>>> index da3b774..9b04653 100644
>>>> --- a/drivers/staging/otus/hal/hpreg.c
>>>> +++ b/drivers/staging/otus/hal/hpreg.c
>>>> @@ -29,9 +29,6 @@
>>>>  #include "hpreg.h"
>>>>  #include "hpusb.h"
>>>>  
>>>> -/* used throughout this file... */
>>>> -#define	N(a)	(sizeof(a) / sizeof(a[0]))
>>>> -
>>>>  #define HAL_MODE_11A_TURBO	HAL_MODE_108A
>>>>  #define HAL_MODE_11G_TURBO	HAL_MODE_108G
>>>>  
>>>> @@ -1557,7 +1554,7 @@ u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>>>>  	u64_t flags = NO_REQ;
>>>>  	REG_DMN_PAIR_MAPPING *regPair = NULL;
>>>>  
>>>> -	for (i = 0, found = 0; (i < N(regDomainPairs)) && (!found); i++) {
>>>> +	for (i = 0, found = 0; (i < ARRAY_SIZE(regDomainPairs)) && (!found); i++) {
>>>>  		if (regDomainPairs[i].regDmnEnum = regionCode) {
>>>>  			regPair = &regDomainPairs[i];
>>>>  			found = 1;
>>>
>>>
>>> This looks odd, i do not see the rest of the code but perhaps a break would help
>>> to eleminate the "found" ??
>>>
>>> just my two cents,
>>>  wh
>>>
>> 1554 u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>> 1555 {
>> 1556         s16_t i, found, regDmn;
>> 1557         u64_t flags=NO_REQ;
>> 1558         REG_DMN_PAIR_MAPPING *regPair=NULL;
>> 1559
>> 1560         for (i=0, found=0; (i<N(regDomainPairs))&&(!found); i++)
>> 1561         {
>> 1562                 if (regDomainPairs[i].regDmnEnum = regionCode)
>> 1563                 {
>> 1564                         regPair = &regDomainPairs[i];
>> 1565                         found = 1;
>> 1566                 }
>> 1567         }
>> 1568         if (!found)
>> 1569         {
>> 1570                 zm_debug_msg1("Failed to find reg domain pair ", regionCode);
>> 1571                 return FALSE;
>> 1572         }
>>
>>
>> This is would stop at the first hit and work without found.
>> Otherwise someone could add an {NULL} at the end of the array
>> und use a while () that would eliminate the need for ARRAY_SIZE also.
> 
> Either of those suggestions sounds fine to me, but it sounds
> like it should be in a separate patch.
> 
>> re,
>>  wh
>>
>> for (i=0; i<ARRAY_SIZE(regDomainPairs);i++ )
>> 	if (regDomainPairs[i].regDmnEnum = regionCode)
>>                     { regPair = &regDomainPairs[i]; break ; }
>>
>> if (!regPair) {
>>         zm_debug_msg1("Failed to find reg domain pair ", regionCode);
>>         return FALSE;
>> }
>>
>>

Hi Kulikov Vasiliy,
can you make that patch also, i have simply no time (and no actual kernel)
feel free to choose a methode you like.

re,
 wh

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
  2010-06-28 11:55 ` Kulikov Vasiliy
                   ` (3 preceding siblings ...)
  (?)
@ 2010-06-29 10:31 ` Kulikov Vasiliy
  -1 siblings, 0 replies; 13+ messages in thread
From: Kulikov Vasiliy @ 2010-06-29 10:31 UTC (permalink / raw)
  To: kernel-janitors

On Tue, Jun 29, 2010 at 11:31 +0200, walter harms wrote:
> >> 1554 u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
> >> 1555 {
> >> 1556         s16_t i, found, regDmn;
> >> 1557         u64_t flags=NO_REQ;
> >> 1558         REG_DMN_PAIR_MAPPING *regPair=NULL;
> >> 1559
> >> 1560         for (i=0, found=0; (i<N(regDomainPairs))&&(!found); i++)
> >> 1561         {
> >> 1562                 if (regDomainPairs[i].regDmnEnum = regionCode)
> >> 1563                 {
> >> 1564                         regPair = &regDomainPairs[i];
> >> 1565                         found = 1;
> >> 1566                 }
> >> 1567         }
> >> 1568         if (!found)
> >> 1569         {
> >> 1570                 zm_debug_msg1("Failed to find reg domain pair ", regionCode);
> >> 1571                 return FALSE;
> >> 1572         }
> >>
> >>
> >> This is would stop at the first hit and work without found.
> >> Otherwise someone could add an {NULL} at the end of the array
> >> und use a while () that would eliminate the need for ARRAY_SIZE also.
> > 
> > Either of those suggestions sounds fine to me, but it sounds
> > like it should be in a separate patch.
> > 
> >> re,
> >>  wh
> >>
> >> for (i=0; i<ARRAY_SIZE(regDomainPairs);i++ )
> >> 	if (regDomainPairs[i].regDmnEnum = regionCode)
> >>                     { regPair = &regDomainPairs[i]; break ; }
> >>
> >> if (!regPair) {
> >>         zm_debug_msg1("Failed to find reg domain pair ", regionCode);
> >>         return FALSE;
> >> }
> >>
> >>
> 
> Hi Kulikov Vasiliy,
> can you make that patch also, i have simply no time (and no actual kernel)
> feel free to choose a methode you like.

Hi,

We cannot trivially create array element with .regDmnEnum = 0 because one
element already has got this value:

static REG_DMN_PAIR_MAPPING regDomainPairs[] = {
         {NO_ENUMRD,         FCC2,       DEBUG_REG_DMN,  NO_REQ, NO_REQ, PSCAN_DEFER, 0 },

enum EnumRd {
        NO_ENUMRD = 0x00, 

And I don't think that creating another constant with meaning 'element after the last' from
the set 'any u16 except already used' is a good idea. If this value is added to the array
in future we must change this magic constant too. And current implementation just works :)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 11/16] trivial: use ARRAY_SIZE
  2010-06-28 11:55 ` Kulikov Vasiliy
                   ` (4 preceding siblings ...)
  (?)
@ 2010-06-29 11:09 ` walter harms
  -1 siblings, 0 replies; 13+ messages in thread
From: walter harms @ 2010-06-29 11:09 UTC (permalink / raw)
  To: kernel-janitors



Kulikov Vasiliy schrieb:
> On Tue, Jun 29, 2010 at 11:31 +0200, walter harms wrote:
>>>> 1554 u8_t GetWmRD(u16_t regionCode, u16_t channelFlag, REG_DOMAIN *rd)
>>>> 1555 {
>>>> 1556         s16_t i, found, regDmn;
>>>> 1557         u64_t flags=NO_REQ;
>>>> 1558         REG_DMN_PAIR_MAPPING *regPair=NULL;
>>>> 1559
>>>> 1560         for (i=0, found=0; (i<N(regDomainPairs))&&(!found); i++)
>>>> 1561         {
>>>> 1562                 if (regDomainPairs[i].regDmnEnum = regionCode)
>>>> 1563                 {
>>>> 1564                         regPair = &regDomainPairs[i];
>>>> 1565                         found = 1;
>>>> 1566                 }
>>>> 1567         }
>>>> 1568         if (!found)
>>>> 1569         {
>>>> 1570                 zm_debug_msg1("Failed to find reg domain pair ", regionCode);
>>>> 1571                 return FALSE;
>>>> 1572         }
>>>>
>>>>
>>>> This is would stop at the first hit and work without found.
>>>> Otherwise someone could add an {NULL} at the end of the array
>>>> und use a while () that would eliminate the need for ARRAY_SIZE also.
>>> Either of those suggestions sounds fine to me, but it sounds
>>> like it should be in a separate patch.
>>>
>>>> re,
>>>>  wh
>>>>
>>>> for (i=0; i<ARRAY_SIZE(regDomainPairs);i++ )
>>>> 	if (regDomainPairs[i].regDmnEnum = regionCode)
>>>>                     { regPair = &regDomainPairs[i]; break ; }
>>>>
>>>> if (!regPair) {
>>>>         zm_debug_msg1("Failed to find reg domain pair ", regionCode);
>>>>         return FALSE;
>>>> }
>>>>
>>>>
>> Hi Kulikov Vasiliy,
>> can you make that patch also, i have simply no time (and no actual kernel)
>> feel free to choose a methode you like.
> 
> Hi,
> 
> We cannot trivially create array element with .regDmnEnum = 0 because one
> element already has got this value:
> 
> static REG_DMN_PAIR_MAPPING regDomainPairs[] = {
>          {NO_ENUMRD,         FCC2,       DEBUG_REG_DMN,  NO_REQ, NO_REQ, PSCAN_DEFER, 0 },
> 
> enum EnumRd {
>         NO_ENUMRD = 0x00, 
> 
> And I don't think that creating another constant with meaning 'element after the last' from
> the set 'any u16 except already used' is a good idea. If this value is added to the array
> in future we must change this magic constant too. And current implementation just works :)
> 
>  
feel free to choose what methode you like,

btw: the check is for regDomainPairs not for regDomainPairs->regDmnEnum. Checking for regDmnEnum=0
is not clever, but you can check for regDomainPairs=NULL.

re,
 wh

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-06-29 11:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-28 11:55 [PATCH 11/16] trivial: use ARRAY_SIZE Kulikov Vasiliy
2010-06-28 11:55 ` Kulikov Vasiliy
2010-06-28 12:42 ` walter harms
2010-06-28 12:42   ` walter harms
2010-06-28 13:22   ` walter harms
2010-06-28 13:22     ` walter harms
2010-06-29  0:58     ` Simon Horman
2010-06-29  0:58       ` Simon Horman
2010-06-29  1:00 ` Simon Horman
2010-06-29  1:00   ` Simon Horman
2010-06-29  9:31 ` walter harms
2010-06-29 10:31 ` Kulikov Vasiliy
2010-06-29 11:09 ` walter harms

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.