All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3] [staging] bcm: Replace the BCM_DEBUG_* and BCM_SHOW_* macros with functions
@ 2012-05-29 11:07 Devendra Naga
  2012-05-29 13:45 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Devendra Naga @ 2012-05-29 11:07 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Eric Dumazet, Joe Perches, Kevin McKinney,
	devel, linux-kernel
  Cc: Devendra Naga

This patch is made by following the improvements told by Joe Perches,
replaced the BCM_DEBUG* and BCM_SHOW* macros into functions and added them
in a file and added macros in the Debug.h file. This patch also improves the if
check in bcm_show_debug_bitmap,

the check was
	if ((i == 1) || (i == 2) || (i == 4) || (i == 8));
and used is_power_of_two instead as suggested by Eric Dumazet.

Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>
---
 drivers/staging/bcm/Debug.c  |   55 +++++++++++++++++++++++++++++++++++++
 drivers/staging/bcm/Debug.h  |   62 ++++++++++++++----------------------------
 drivers/staging/bcm/Makefile |    2 +-
 3 files changed, 77 insertions(+), 42 deletions(-)
 create mode 100644 drivers/staging/bcm/Debug.c

diff --git a/drivers/staging/bcm/Debug.c b/drivers/staging/bcm/Debug.c
new file mode 100644
index 0000000..6522ad6
--- /dev/null
+++ b/drivers/staging/bcm/Debug.c
@@ -0,0 +1,55 @@
+#include <linux/log2.h>
+#include "headers.h"
+
+void bcm_debug_print(PMINI_ADAPTER Adapter, int Type, int SubType,
+			int dbg_level, const char *fmt, ...)
+{
+	struct va_format vaf;
+	va_list args;
+	UINT debug_level = Adapter->stDebugState.debug_level;
+
+	va_start(args, fmt);
+
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	if (DBG_TYPE_PRINTK == Type)
+		pr_info("%s: %pV", __func__, &vaf);
+	else if (Adapter &&
+		(dbg_level & DBG_LVL_BITMASK) <= debug_level &&
+		(Type & Adapter->stDebugState.type) &&
+		(SubType & Adapter->stDebugState.subtype[Type])) {
+		if (dbg_level & DBG_NO_FUNC_PRINT)
+			printk(KERN_DEBUG "%pV" , &vaf);
+		else
+			printk(KERN_DEBUG "%s: %pV", __func__, &vaf);
+	}
+
+	va_end(args);
+}
+
+void bcm_debug_print_buffer(PMINI_ADAPTER Adapter, int Type, int SubType,
+			    int dbg_level, const void *buffer, size_t bufferlen)
+{
+	if (DBG_TYPE_PRINTK == Type ||
+	   (Adapter &&
+	   (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level &&
+	   (Type & Adapter->stDebugState.type) &&
+	   (SubType & Adapter->stDebugState.subtype[Type]))) {
+		printk(KERN_DEBUG "%s:\n", __func__);
+		print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET,
+			       16, 1, buffer, bufferlen, false);
+	}
+}
+
+void bcm_show_debug_bitmap(PMINI_ADAPTER Adapter)
+{
+	int i;
+	for (i = 0; i < (NUMTYPES * 2) + 1; i++) {
+		if (is_power_of_2(i)) {
+			BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
+					"subtype[%d] = 0x%08x\n",
+					i, Adapter->stDebugState.subtype[i]);
+		}
+	}
+}
diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h
index 420382d..030c737 100644
--- a/drivers/staging/bcm/Debug.h
+++ b/drivers/staging/bcm/Debug.h
@@ -203,57 +203,37 @@ typedef struct _S_BCM_DEBUG_STATE {
 	 * corresponding to valid Type values. Hence we use the 'Type' field
 	 * as the index value, ignoring the array entries 0,3,5,6,7 !
 	 */
-	UINT subtype[(NUMTYPES*2)+1];
+	UINT subtype[(NUMTYPES * 2) + 1];
 	UINT debug_level;
 } S_BCM_DEBUG_STATE;
 /* Instantiated in the Adapter structure */
 /* We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not
  * we want the function's name printed.  */
-#define DBG_NO_FUNC_PRINT	1 << 31
+#define DBG_NO_FUNC_PRINT	(1 << 31)
 #define DBG_LVL_BITMASK		0xFF
 
 //--- Only for direct printk's; "hidden" to API.
 #define DBG_TYPE_PRINTK		3
 
-#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \
-	do {								\
-		if (DBG_TYPE_PRINTK == Type)				\
-			pr_info("%s:" string, __func__, ##args);	\
-		else if (Adapter &&					\
-			 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
-			 (Type & Adapter->stDebugState.type) &&		\
-			 (SubType & Adapter->stDebugState.subtype[Type])) { \
-			if (dbg_level & DBG_NO_FUNC_PRINT)		\
-				printk(KERN_DEBUG string, ##args);	\
-			else						\
-				printk(KERN_DEBUG "%s:" string, __func__, ##args);	\
-		}							\
-	} while (0)
-
-#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level,  buffer, bufferlen) do { \
-	if (DBG_TYPE_PRINTK == Type ||					\
-	    (Adapter &&							\
-	     (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level  && \
-	     (Type & Adapter->stDebugState.type) &&			\
-	     (SubType & Adapter->stDebugState.subtype[Type]))) {	\
-		printk(KERN_DEBUG "%s:\n", __func__);			\
-		print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET,	\
-			       16, 1, buffer, bufferlen, false);	\
-	}								\
-} while(0)
-
-
-#define BCM_SHOW_DEBUG_BITMAP(Adapter)	do { \
-	int i;									\
-	for (i=0; i<(NUMTYPES*2)+1; i++) {		\
-		if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) {		\
-		/* CAUTION! Forcefully turn on ALL debug paths and subpaths!	\
-		Adapter->stDebugState.subtype[i] = 0xffffffff;	*/ \
-		BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", 	\
-		i, Adapter->stDebugState.subtype[i]);	\
-		}	\
-	}		\
-} while (0)
+struct _MINI_ADAPTER;
+
+__printf(5, 6)
+
+void bcm_debug_print(struct _MINI_ADAPTER *Adapter, int Type, int SubType,
+			int dbg_level, const char *fmt, ...);
+void bcm_debug_print_buffer(struct _MINI_ADAPTER *Adapter, int Type, int SubType,
+			int dbg_level, const void *buffer, size_t bufferlen);
+void bcm_show_debug_bitmap(struct _MINI_ADAPTER *Adapter);
+
+#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, fmt, ...)	\
+	bcm_debug_print(Adapter, Type, SubType, dbg_level, fmt, ##__VA_ARGS__)
+
+#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level,	\
+				buffer, bufferlen)			\
+	bcm_debug_print_buffer(Adapter, Type, SubType, dbg_level,	\
+				buffer, bufferlen)
+#define BCM_SHOW_DEBUG_BITMAP(Adapter)					\
+	bcm_show_debug_bitmap(Adapter)
 
 #endif
 
diff --git a/drivers/staging/bcm/Makefile b/drivers/staging/bcm/Makefile
index 652b7f8..85b134d 100644
--- a/drivers/staging/bcm/Makefile
+++ b/drivers/staging/bcm/Makefile
@@ -7,6 +7,6 @@ obj-$(CONFIG_BCM_WIMAX) +=	bcm_wimax.o
 bcm_wimax-y :=  InterfaceDld.o InterfaceIdleMode.o InterfaceInit.o InterfaceRx.o \
 		InterfaceIsr.o InterfaceMisc.o InterfaceTx.o \
 		CmHost.o IPv6Protocol.o Qos.o Transmit.o\
-		Bcmnet.o DDRInit.o HandleControlPacket.o\
+		Debug.o Bcmnet.o DDRInit.o HandleControlPacket.o\
 		LeakyBucket.o Misc.o sort.o Bcmchar.o hostmibs.o PHSModule.o\
 		led_control.o nvm.o vendorspecificextn.o
-- 
1.7.9.5


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

* Re: [PATCH V3] [staging] bcm: Replace the BCM_DEBUG_* and BCM_SHOW_* macros with functions
  2012-05-29 11:07 [PATCH V3] [staging] bcm: Replace the BCM_DEBUG_* and BCM_SHOW_* macros with functions Devendra Naga
@ 2012-05-29 13:45 ` Joe Perches
  2012-05-29 15:20   ` devendra.aaru
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2012-05-29 13:45 UTC (permalink / raw)
  To: Devendra Naga
  Cc: Greg Kroah-Hartman, Eric Dumazet, Kevin McKinney, devel, linux-kernel

On Tue, 2012-05-29 at 16:37 +0530, Devendra Naga wrote:
[]
> diff --git a/drivers/staging/bcm/Debug.c b/drivers/staging/bcm/Debug.c
[]
> +void bcm_debug_print(PMINI_ADAPTER Adapter, int Type, int SubType,
> +			int dbg_level, const char *fmt, ...)
> +{
> +	struct va_format vaf;
> +	va_list args;
> +	UINT debug_level = Adapter->stDebugState.debug_level;
> +
> +	va_start(args, fmt);
> +
> +	vaf.fmt = fmt;
> +	vaf.va = &args;
> +
> +	if (DBG_TYPE_PRINTK == Type)
> +		pr_info("%s: %pV", __func__, &vaf);

func

> +	else if (Adapter &&
> +		(dbg_level & DBG_LVL_BITMASK) <= debug_level &&
> +		(Type & Adapter->stDebugState.type) &&
> +		(SubType & Adapter->stDebugState.subtype[Type])) {
> +		if (dbg_level & DBG_NO_FUNC_PRINT)
> +			printk(KERN_DEBUG "%pV" , &vaf);
> +		else
> +			printk(KERN_DEBUG "%s: %pV", __func__, &vaf);

func

> +	}
> +
> +	va_end(args);
> +}
> +
> +void bcm_debug_print_buffer(PMINI_ADAPTER Adapter, int Type, int SubType,
> +			    int dbg_level, const void *buffer, size_t bufferlen)
> +{
> +	if (DBG_TYPE_PRINTK == Type ||
> +	   (Adapter &&
> +	   (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level &&
> +	   (Type & Adapter->stDebugState.type) &&
> +	   (SubType & Adapter->stDebugState.subtype[Type]))) {
> +		printk(KERN_DEBUG "%s:\n", __func__);

func

> +		print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET,
> +			       16, 1, buffer, bufferlen, false);
> +	}
> +}

[]

> diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h
[]
> +struct _MINI_ADAPTER;
> +
> +__printf(5, 6)
> +
> +void bcm_debug_print(struct _MINI_ADAPTER *Adapter, int Type, int SubType,
> +			int dbg_level, const char *fmt, ...);

No blank line between __printf and prototype

> +void bcm_debug_print_buffer(struct _MINI_ADAPTER *Adapter, int Type, int SubType,
> +			int dbg_level, const void *buffer, size_t bufferlen);
> +void bcm_show_debug_bitmap(struct _MINI_ADAPTER *Adapter);
> +
> +#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, fmt, ...)	\
> +	bcm_debug_print(Adapter, Type, SubType, dbg_level, fmt, ##__VA_ARGS__)
> +
> +#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level,	\
> +				buffer, bufferlen)			\
> +	bcm_debug_print_buffer(Adapter, Type, SubType, dbg_level,	\
> +				buffer, bufferlen)
> +#define BCM_SHOW_DEBUG_BITMAP(Adapter)					\
> +	bcm_show_debug_bitmap(Adapter)

Turns out to keep the same behavior, you need to add
a const char *func argument to these functions and
change the macros to pass __func__.
 



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

* Re: [PATCH V3] [staging] bcm: Replace the BCM_DEBUG_* and BCM_SHOW_* macros with functions
  2012-05-29 13:45 ` Joe Perches
@ 2012-05-29 15:20   ` devendra.aaru
  0 siblings, 0 replies; 3+ messages in thread
From: devendra.aaru @ 2012-05-29 15:20 UTC (permalink / raw)
  To: Joe Perches
  Cc: Greg Kroah-Hartman, Eric Dumazet, Kevin McKinney, devel, linux-kernel

Hi Joe,

On Tue, May 29, 2012 at 7:15 PM, Joe Perches <joe@perches.com> wrote:
>> diff --git a/drivers/staging/bcm/Debug.c b/drivers/staging/bcm/Debug.c
> []
>> +void bcm_debug_print(PMINI_ADAPTER Adapter, int Type, int SubType,
>> +                     int dbg_level, const char *fmt, ...)
>> +{
>> +     struct va_format vaf;
>> +     va_list args;
>> +     UINT debug_level = Adapter->stDebugState.debug_level;
>> +
>> +     va_start(args, fmt);
>> +
>> +     vaf.fmt = fmt;
>> +     vaf.va = &args;
>> +
>> +     if (DBG_TYPE_PRINTK == Type)
>> +             pr_info("%s: %pV", __func__, &vaf);
>
> func
>
>> +     else if (Adapter &&
>> +             (dbg_level & DBG_LVL_BITMASK) <= debug_level &&
>> +             (Type & Adapter->stDebugState.type) &&
>> +             (SubType & Adapter->stDebugState.subtype[Type])) {
>> +             if (dbg_level & DBG_NO_FUNC_PRINT)
>> +                     printk(KERN_DEBUG "%pV" , &vaf);
>> +             else
>> +                     printk(KERN_DEBUG "%s: %pV", __func__, &vaf);
>
> func
>
>> +     }
>> +
>> +     va_end(args);
>> +}
>> +
>> +void bcm_debug_print_buffer(PMINI_ADAPTER Adapter, int Type, int SubType,
>> +                         int dbg_level, const void *buffer, size_t bufferlen)
>> +{
>> +     if (DBG_TYPE_PRINTK == Type ||
>> +        (Adapter &&
>> +        (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level &&
>> +        (Type & Adapter->stDebugState.type) &&
>> +        (SubType & Adapter->stDebugState.subtype[Type]))) {
>> +             printk(KERN_DEBUG "%s:\n", __func__);
>
> func
>
>> +             print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET,
>> +                            16, 1, buffer, bufferlen, false);
>> +     }
>> +}
>
> []
>
>> diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h
> []
>> +struct _MINI_ADAPTER;
>> +
>> +__printf(5, 6)
>> +
>> +void bcm_debug_print(struct _MINI_ADAPTER *Adapter, int Type, int SubType,
>> +                     int dbg_level, const char *fmt, ...);
>
> No blank line between __printf and prototype
>
>> +void bcm_debug_print_buffer(struct _MINI_ADAPTER *Adapter, int Type, int SubType,
>> +                     int dbg_level, const void *buffer, size_t bufferlen);
>> +void bcm_show_debug_bitmap(struct _MINI_ADAPTER *Adapter);
>> +
>> +#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, fmt, ...) \
>> +     bcm_debug_print(Adapter, Type, SubType, dbg_level, fmt, ##__VA_ARGS__)
>> +
>> +#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level,    \
>> +                             buffer, bufferlen)                      \
>> +     bcm_debug_print_buffer(Adapter, Type, SubType, dbg_level,       \
>> +                             buffer, bufferlen)
>> +#define BCM_SHOW_DEBUG_BITMAP(Adapter)                                       \
>> +     bcm_show_debug_bitmap(Adapter)
>
> Turns out to keep the same behavior, you need to add
> a const char *func argument to these functions and
> change the macros to pass __func__.
>
>
>
Ok. so what i am doing now is wrong as its a function, and __func__
gives the dbg function name, instead the called function since we
changed it to functions rather from Macros.

Ok, i will send out new changes.

Thanks,
Devendra.

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

end of thread, other threads:[~2012-05-29 15:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-29 11:07 [PATCH V3] [staging] bcm: Replace the BCM_DEBUG_* and BCM_SHOW_* macros with functions Devendra Naga
2012-05-29 13:45 ` Joe Perches
2012-05-29 15:20   ` devendra.aaru

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.