Skip to contentSkip to conversation

kernel 2.6 size macro clean ups in

PATCH Aaron Cripps 4 participants 9 messages May 29, 2007 – Jun 6, 2007

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

removed the MAX_SPEEDS macro in favor of the more generic ARRAY_SIZE macro defined in kernel.h
Also cleaned up trailing whitespaces.
Compile tested, no issues found at compile time.

drivers/net/irda/actisys-sir.c +16 -18
diff -Nuar linux-2.6/drivers/net/irda/actisys-sir.c linux-2.6-patched/drivers/net/irda/actisys-sir.c
@@ -1,8 +1,8 @@
 /*********************************************************************
- *                
+ *
  * Filename:      actisys.c
  * Version:       1.1
- * Description:   Implementation for the ACTiSYS IR-220L and IR-220L+ 
+ * Description:   Implementation for the ACTiSYS IR-220L and IR-220L+
  *                dongles
  * Status:        Beta.
  * Authors:       Dag Brattli <[email protected]> (initially)
@@ -11,20 +11,20 @@
  * Created at:    Wed Oct 21 20:02:35 1998
  * Modified at:   Sun Oct 27 22:02:13 2002
  * Modified by:   Martin Diehl <[email protected]>
- * 
+ *
  *     Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
  *     Copyright (c) 1999 Jean Tourrilhes
  *     Copyright (c) 2002 Martin Diehl
- *      
- *     This program is free software; you can redistribute it and/or 
- *     modify it under the terms of the GNU General Public License as 
- *     published by the Free Software Foundation; either version 2 of 
+ *
+ *     This program is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of
  *     the License, or (at your option) any later version.
- *  
+ *
  *     Neither Dag Brattli nor University of Troms������ admit liability nor
- *     provide warranty for any of this software. This material is 
+ *     provide warranty for any of this software. This material is
  *     provided "AS-IS" and at no charge.
- *     
+ *
  ********************************************************************/
 
 /*
@@ -48,7 +48,7 @@
 
 #include "sir-dev.h"
 
-/* 
+/*
  * Define the timing of the pulses we send to the dongle (to reset it, and
  * to toggle speeds). Basically, the limit here is the propagation speed of
  * the signals through the serial port, the dongle being much faster.  Any
@@ -67,8 +67,6 @@
 /* Note : the 220L doesn't support 38400, but we will fix that below */
 static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
 
-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0]))
-
 static struct dongle_driver act220l = {
 	.owner		= THIS_MODULE,
 	.driver_name	= "Actisys ACT-220L",
@@ -166,17 +164,17 @@
 	int i = 0;
 
         IRDA_DEBUG(4, "%s(), speed=%d (was %d)\n", __FUNCTION__,
-        	speed, dev->speed);
+		speed, dev->speed);
 
 	/* dongle was already resetted from irda_request state machine,
 	 * we are in known state (dongle default)
 	 */
 
-	/* 
+	/*
 	 * Now, we can set the speed requested. Send RTS pulses until we
-         * reach the target speed 
+         * reach the target speed
 	 */
-	for (i = 0; i < MAX_SPEEDS; i++) {
+	for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
 		if (speed == baud_rates[i]) {
 			dev->speed = speed;
 			break;
@@ -191,7 +189,7 @@
 	}
 
 	/* Check if life is sweet... */
-	if (i >= MAX_SPEEDS) {
+	if (i >= ARRAY_SIZE(baud_rates)) {
 		actisys_reset(dev);
 		ret = -EINVAL;  /* This should not happen */
 	}

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#1 lore raw

Re: [KJ] Re: [PATCH ARRAY_SIZE 1/4] kernel 2.6 size macro clean ups

This patch includes a bunch of white-space changes. I recommend passing -B to the diff command.

Jaco

Quoted 108 lines · Aaron Cripps

------------------------------------------------------------------------

removed the MAX_SPEEDS macro in favor of the more generic ARRAY_SIZE macro defined in kernel.h
Also cleaned up trailing whitespaces.
Compile tested, no issues found at compile time.

diff -Nuar linux-2.6/drivers/net/irda/actisys-sir.c linux-2.6-patched/drivers/net/irda/actisys-sir.c

drivers/net/irda/actisys-sir.c +16 -19
@@ -1,8 +1,8 @@
 /*********************************************************************
- *                
+ *
  * Filename:      actisys.c
  * Version:       1.1
- * Description:   Implementation for the ACTiSYS IR-220L and IR-220L+ 
+ * Description:   Implementation for the ACTiSYS IR-220L and IR-220L+
  *                dongles
  * Status:        Beta.
  * Authors:       Dag Brattli <[email protected]> (initially)
@@ -11,20 +11,20 @@
  * Created at:    Wed Oct 21 20:02:35 1998
  * Modified at:   Sun Oct 27 22:02:13 2002
  * Modified by:   Martin Diehl <[email protected]>
- * 
+ *
  *     Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
  *     Copyright (c) 1999 Jean Tourrilhes
  *     Copyright (c) 2002 Martin Diehl
- *      
- *     This program is free software; you can redistribute it and/or 
- *     modify it under the terms of the GNU General Public License as 
- *     published by the Free Software Foundation; either version 2 of 
+ *
+ *     This program is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of
  *     the License, or (at your option) any later version.
- *  
+ *
  *     Neither Dag Brattli nor University of Tromsø admit liability nor
- *     provide warranty for any of this software. This material is 
+ *     provide warranty for any of this software. This material is
  *     provided "AS-IS" and at no charge.
- *     
+ *
  ********************************************************************/
 
 /*
@@ -48,7 +48,7 @@
 
 #include "sir-dev.h"
 
-/* 
+/*
  * Define the timing of the pulses we send to the dongle (to reset it, and
  * to toggle speeds). Basically, the limit here is the propagation speed of
  * the signals through the serial port, the dongle being much faster.  Any
@@ -67,8 +67,6 @@
 /* Note : the 220L doesn't support 38400, but we will fix that below */
 static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
 
-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0]))
-
 static struct dongle_driver act220l = {
 	.owner		= THIS_MODULE,
 	.driver_name	= "Actisys ACT-220L",
@@ -166,17 +164,17 @@
 	int i = 0;
 
         IRDA_DEBUG(4, "%s(), speed=%d (was %d)\n", __FUNCTION__,
-        	speed, dev->speed);
+		speed, dev->speed);
 
 	/* dongle was already resetted from irda_request state machine,
 	 * we are in known state (dongle default)
 	 */
 
-	/* 
+	/*
 	 * Now, we can set the speed requested. Send RTS pulses until we
-         * reach the target speed 
+         * reach the target speed
 	 */
-	for (i = 0; i < MAX_SPEEDS; i++) {
+	for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
 		if (speed = baud_rates[i]) {
 			dev->speed = speed;
 			break;
@@ -191,7 +189,7 @@
 	}
 
 	/* Check if life is sweet... */
-	if (i >= MAX_SPEEDS) {
+	if (i >= ARRAY_SIZE(baud_rates)) {
 		actisys_reset(dev);
 		ret = -EINVAL;  /* This should not happen */
 	}
 
 
------------------------------------------------------------------------
Quoted 4 lines

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#2 lore raw

Re: [KJ] Re: [PATCH ARRAY_SIZE 1/4] kernel 2.6 size macro clean ups

In reply to Aaron Cripps
Quoted 4 lines · Jaco Kroon

This patch includes a bunch of white-space changes. I recommend passing -B to the diff command.

Jaco

Actually, I did that on purpose, as is mentioned in the Patch. The whitespace changes are "harmless" and
make for "better formatted" code. (okay, so the formatting is the same, but at least the code after the whitespace
changes is somewhat uniform).
-acripps

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#3 lore raw

Re: [KJ] Re: [PATCH ARRAY_SIZE 1/4] kernel 2.6 size macro clean ups

In reply to Aaron Cripps
Quoted 11 lines · Aaron Cripps
Quoted 4 lines · Jaco Kroon

This patch includes a bunch of white-space changes. I recommend passing -B to the diff command.

Jaco

Actually, I did that on purpose, as is mentioned in the Patch. The whitespace changes are "harmless" and
make for "better formatted" code. (okay, so the formatting is the same, but at least the code after the whitespace
changes is somewhat uniform).
-acripps

Perhaps, but then these are two different "changes" and should probably be separate patches.

Jaco
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#4 lore raw

Re: [KJ] Re: [PATCH ARRAY_SIZE 1/4] kernel 2.6 size macro clean ups

In reply to Aaron Cripps
Quoted 4 lines · On Wed, 30 May 2007 00:17:15 +0200 Jaco Kroon wrote:
Quoted 3 lines · Aaron Cripps
Quoted 2 lines · Jaco Kroon

This patch includes a bunch of white-space changes. I recommend passing -B to the diff command.

We really don't want to risk mis-applying a patch.

Quoted 10 lines
Quoted 7 lines
Quoted 1 line

Jaco

Actually, I did that on purpose, as is mentioned in the Patch. The whitespace changes are "harmless" and
make for "better formatted" code. (okay, so the formatting is the same, but at least the code after the whitespace
changes is somewhat uniform).
-acripps

Perhaps, but then these are two different "changes" and should probably be separate patches.

Agreed.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
_______________________________________________
Kernel-janitors mailing list [email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#5 lore raw

Re: [KJ] Re: [PATCH ARRAY_SIZE 1/4] kernel 2.6 size macro clean ups

In reply to Aaron Cripps
Quoted 8 lines · Randy Dunlap
Quoted 4 lines · On Wed, 30 May 2007 00:17:15 +0200 Jaco Kroon wrote:
Quoted 3 lines · Aaron Cripps
Quoted 2 lines · Jaco Kroon

This patch includes a bunch of white-space changes. I recommend passing -B to the diff command.

We really don't want to risk mis-applying a patch.

-B and -b does two different things. -B will simply ignore the diff between two lines IFF the only changes is whitespace. In other words, if the destination line is the same as the source except for whitespace it'll pretend the destination is the same in terms of whitespace as well.

-b however is dangerous. It breaks things. Avoid.

Jaco
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#6 lore raw
In reply to Aaron Cripps

this is a simple patch to remove the MAX_SPEEDS macro in favor of the more generic ARRAY_SIZE(arr) macro defined in kernel.h

drivers/net/irda/actisys-sir.c +0 -2
index 9715ab5..44bf0c2 100644
@@ -67,8 +67,6 @@ static int actisys_reset(struct sir_dev *);
 /* Note : the 220L doesn't support 38400, but we will fix that below */
 static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
 
-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0]))
-
 static struct dongle_driver act220l = {
     .owner        = THIS_MODULE,
     .driver_name    = "Actisys ACT-220L",
@@ -176,7 +174,7 @@ static int actisys_change_speed(struct sir_dev *dev, 

unsigned speed)
* Now, we can set the speed requested. Send RTS pulses until we
* reach the target speed
*/
- for (i = 0; i < MAX_SPEEDS; i++) {

+    for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
         if (speed = baud_rates[i]) {
             dev->speed = speed;
             break;
@@ -191,7 +189,7 @@ static int actisys_change_speed(struct sir_dev *dev, 
unsigned speed)
     }
 
     /* Check if life is sweet... */
-    if (i >= MAX_SPEEDS) {
+    if (i >= ARRAY_SIZE(baud_rates)) {
         actisys_reset(dev);
         ret = -EINVAL;  /* This should not happen */
     }

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#7 lore raw
In reply to Aaron Cripps

this is a simple patch to remove the MAX_SPEEDS macro in favor of the more generic ARRAY_SIZE(arr) macro defined in kernel.h
RE: Forgot the #import <linux/kernel.h> statement. It's there now.

drivers/net/irda/actisys-sir.c +0 -0
index 9715ab5..44bf0c2 100644
@@ -43,7 +43,7 @@

#include <linux/module.h>
#include <linux/delay.h>
#include <linux/init.h>
-
+#include <linux/kernel.h>
#include <net/irda/irda.h>

#include "sir-dev.h"
@@ -67,8 +67,6 @@ static int actisys_reset(struct sir_dev *);
/* Note : the 220L doesn't support 38400, but we will fix that below */ static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };

-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0])) -
static struct dongle_driver act220l = {
.owner = THIS_MODULE,
.driver_name = "Actisys ACT-220L",
@@ -176,7 +174,7 @@ static int actisys_change_speed(struct sir_dev *dev, unsigned speed)
* Now, we can set the speed requested. Send RTS pulses until we
* reach the target speed
*/
- for (i = 0; i < MAX_SPEEDS; i++) {

+    for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
         if (speed = baud_rates[i]) {
             dev->speed = speed;
             break;
@@ -191,7 +189,7 @@ static int actisys_change_speed(struct sir_dev *dev, 
unsigned speed)
     }
 
     /* Check if life is sweet... */
-    if (i >= MAX_SPEEDS) {
+    if (i >= ARRAY_SIZE(baud_rates)) {
         actisys_reset(dev);
         ret = -EINVAL;  /* This should not happen */
     }

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#8 lore raw

Re: [KJ] Re: [PATCH ARRAY_SIZE 1/4] kernel 2.6 size macro clean ups

In reply to Aaron Cripps
Quoted 13 lines · Aaron Cripps

this is a simple patch to remove the MAX_SPEEDS macro in favor of the more
generic ARRAY_SIZE(arr) macro defined in kernel.h
RE: Forgot the #import <linux/kernel.h> statement. It's there now.

drivers/net/irda/actisys-sir.c +0 -0
index 9715ab5..44bf0c2 100644

drivers/net/irda/actisys-sir.c line 46

Quoted 5 lines
drivers/net/irda/actisys-sir.c +1 -1
@@ -43,7 +43,7 @@
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/init.h>
-
+#include <linux/kernel.h>

The patch is space-padded, please fix your client (or use ex the script "sendpatchset") and send again. (The patch seemed correct otherwise)

drivers/net/irda/actisys-sir.c static int actisys_reset(struct sir_dev *); · line 71

Quoted 9 lines
drivers/net/irda/actisys-sir.c +0 -2
 #include <net/irda/irda.h>
 
 #include "sir-dev.h"
@@ -67,8 +67,6 @@ static int actisys_reset(struct sir_dev *);
 /* Note : the 220L doesn't support 38400, but we will fix that below */
 static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
 
-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0]))
-

Can anyone explain why the number of possible speeds are called MAX_SPEEDS? Maybe it should have been NUM_MAX_SPEEDS...

Richard Knutsson

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors