[ofa-general] Re: [PATCH] Fix wrong dbg output and gcc warning when INFINIBAND_NES_DEBUG is not set

Nikanth Karthikesan knikanth at suse.de
Thu Apr 9 00:14:06 PDT 2009


On Wednesday 08 April 2009 22:51:51 Roland Dreier wrote:
>  > +	nes_debug(NES_DBG_CM, "Unable to find listener for %xI4:%x\n",
>  > +		  cpu_to_be32(dst_addr), dst_port);
>
> Have you tested this?  It seems like it will print the IP address as a
> (possibly byte-reversed) hex value followed by the literal string "I4"
> rather than printing it as a formatted IP address.
>

No. Just Build tested.

> The problem you seem to be trying to solve is an unused variable warning
> when nes debugging is not enabled, but I don't think you can do it by
> removing the tmp_addr variable.  The most robust solution would probably
> to change the definition of nes_debug() so it appears to gcc to use all
> its parameters even when debugging is disabled.  You could look at
> drivers/net/mlx4/mlx4.h for an example of one way to do that.
>

Ah got it. Didnt know about the printk format %pI4. Sorry. Here are 3 different
patches to silence gcc warning when nes debugging is not enabled. Please apply
one of them. :) Thanks for your patience.

Thanks
Nikanth

1. Using __attribute__((unused))


Silence gcc warning for unused variable when INFINIBAND_NES_DEBUG is not set.

Signed-off-by: Nikanth Karthikesan <knikanth at suse.de>

---

diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
index 5242515..a772bf0 100644
--- a/drivers/infiniband/hw/nes/nes_cm.c
+++ b/drivers/infiniband/hw/nes/nes_cm.c
@@ -859,7 +859,7 @@ static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
 {
 	unsigned long flags;
 	struct nes_cm_listener *listen_node;
-	__be32 tmp_addr = cpu_to_be32(dst_addr);
+	__be32 __attribute__((unused)) tmp_addr = cpu_to_be32(dst_addr);
 
 	/* walk list and find cm_node associated with this session ID */
 	spin_lock_irqsave(&cm_core->listen_list_lock, flags);




2. Using your suggested approach.

Silence gcc warning for unused variable when INFINIBAND_NES_DEBUG is not set.

Signed-off-by: Nikanth Karthikesan <knikanth at suse.de>

---


diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
index 04b12ad..4c4dcf8 100644
--- a/drivers/infiniband/hw/nes/nes.h
+++ b/drivers/infiniband/hw/nes/nes.h
@@ -136,27 +136,31 @@
 #define NES_DBG_ALL         0xffffffff
 
 #ifdef CONFIG_INFINIBAND_NES_DEBUG
+
+#define INFINIBAND_NES_DEBUG (1)
+#define NES_EVENT_TIMEOUT   1200000
+
+#else
+
+#define INFINIBAND_NES_DEBUG (0)
+#define NES_EVENT_TIMEOUT   100000
+
+#endif
+
 #define nes_debug(level, fmt, args...) \
 do { \
-	if (level & nes_debug_level) \
+	if (INFINIBAND_NES_DEBUG && (level & nes_debug_level)) \
 		printk(KERN_ERR PFX "%s[%u]: " fmt, __func__, __LINE__, ##args); \
 } while (0)
 
 #define assert(expr) \
 do { \
-	if (!(expr)) { \
+	if (INFINIBAND_NES_DEBUG && !(expr)) { \
 		printk(KERN_ERR PFX "Assertion failed! %s, %s, %s, line %d\n", \
 			   #expr, __FILE__, __func__, __LINE__); \
 	} \
 } while (0)
 
-#define NES_EVENT_TIMEOUT   1200000
-#else
-#define nes_debug(level, fmt, args...)
-#define assert(expr)          do {} while (0)
-
-#define NES_EVENT_TIMEOUT   100000
-#endif
 
 #include "nes_hw.h"
 #include "nes_verbs.h"



3. Just dont define the unused variable.

Silence gcc warning for unused variable when INFINIBAND_NES_DEBUG is not set.

Signed-off-by: Nikanth Karthikesan <knikanth at suse.de>

---

diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
index 5242515..449d28d 100644
--- a/drivers/infiniband/hw/nes/nes_cm.c
+++ b/drivers/infiniband/hw/nes/nes_cm.c
@@ -859,7 +859,9 @@ static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
 {
 	unsigned long flags;
 	struct nes_cm_listener *listen_node;
+#ifdef CONFIG_INFINIBAND_NES_DEBUG
 	__be32 tmp_addr = cpu_to_be32(dst_addr);
+#endif
 
 	/* walk list and find cm_node associated with this session ID */
 	spin_lock_irqsave(&cm_core->listen_list_lock, flags);




More information about the general mailing list