Skip to contentSkip to conversation

x86: k8.h reference to node in node_to_k8_nb_misc for !CONFIG_K8_NB

PATCH In review Jaswinder Singh Rajput 2 participants 5 messages Apr 14, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: k8.h reference to node in node_to_k8_nb_misc for !CONFIG_K8_NB

Add reference to node in node_to_k8_nb_misc for !CONFIG_K8_NB to make compiler happy.

So fixes compiler warnings:
arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘show_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:712: warning: unused variable ‘node’ arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘store_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:739: warning: unused variable ‘node’

---
 arch/x86/include/asm/k8.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/include/asm/k8.h +1 -1
index c23b3d1..c81e4ee 100644
@@ -16,7 +16,7 @@ extern int k8_scan_nodes(unsigned long start, unsigned long end);
 #define node_to_k8_nb_misc(node) \
 	(node < num_k8_northbridges) ? k8_northbridges[node] : NULL
 #else
-#define node_to_k8_nb_misc(node) NULL
+#define node_to_k8_nb_misc(node) (node) ? NULL : NULL
 #endif
 
 
Signature · 1 line
1.6.0.6
#1 lore raw
Quoted 18 lines · Jaswinder Singh Rajput

Add reference to node in node_to_k8_nb_misc for !CONFIG_K8_NB to make compiler happy.

So fixes compiler warnings:
arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘show_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:712: warning: unused variable ‘node’ arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘store_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:739: warning: unused variable ‘node’

---
 arch/x86/include/asm/k8.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/include/asm/k8.h +0 -0
index c23b3d1..c81e4ee 100644

arch/x86/include/asm/k8.h extern int k8_scan_nodes(unsigned long start, unsigned long end); · line 20

Quoted 6 lines
arch/x86/include/asm/k8.h +1 -1
@@ -16,7 +16,7 @@ extern int k8_scan_nodes(unsigned long start, unsigned long end);
 #define node_to_k8_nb_misc(node) \
 	(node < num_k8_northbridges) ? k8_northbridges[node] : NULL
 #else
-#define node_to_k8_nb_misc(node) NULL
+#define node_to_k8_nb_misc(node) (node) ? NULL : NULL
 #endif

Ugh, that's very ugly. I gave you a proper solution:

Quoted 7 lines
Quoted 7 lines

The typical way to solve this is to add a dummy:

	(void)(cpu)

use to the 'cpu' parameter to the macro definition - or, (which is a much better solution), to convert it to an inline function.

Ingo

#2 lore raw
Quoted 15 lines · Ingo Molnar
Quoted 13 lines · Jaswinder Singh Rajput

Add reference to node in node_to_k8_nb_misc for !CONFIG_K8_NB to make compiler happy.

So fixes compiler warnings:
arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘show_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:712: warning: unused variable ‘node’ arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘store_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:739: warning: unused variable ‘node’

---
 arch/x86/include/asm/k8.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 22 lines

arch/x86/include/asm/k8.h extern int k8_scan_nodes(unsigned long start, unsigned long end); · line 20

Quoted 11 lines
arch/x86/include/asm/k8.h +1 -1
index c23b3d1..c81e4ee 100644
@@ -16,7 +16,7 @@ extern int k8_scan_nodes(unsigned long start, unsigned long end);
 #define node_to_k8_nb_misc(node) \
 	(node < num_k8_northbridges) ? k8_northbridges[node] : NULL
 #else
-#define node_to_k8_nb_misc(node) NULL
+#define node_to_k8_nb_misc(node) (node) ? NULL : NULL
 #endif

Ugh, that's very ugly. I gave you a proper solution:

Quoted 7 lines
Quoted 7 lines

The typical way to solve this is to add a dummy:

	(void)(cpu)

use to the 'cpu' parameter to the macro definition - or, (which is a much better solution), to convert it to an inline function.

Subject: [PATCH] x86: cpu/cacheinfo.c reference to node for node_to_k8_nb_misc for !CONFIG_K8_NB

Add reference to node for node_to_k8_nb_misc for !CONFIG_K8_NB to make compiler happy.

And fixes:
arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘show_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:712: warning: unused variable ‘node’ arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘store_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:739: warning: unused variable ‘node’

---
 arch/x86/kernel/cpu/intel_cacheinfo.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -0
index 789efe2..4414c92 100644
@@ -719,6 +719,7 @@ static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
 	if (!dev)
 		return -EINVAL;
 
+	(void)(node);
 	pci_read_config_dword(dev, 0x1BC + index * 4, &reg);
 	return sprintf(buf, "%x\n", reg);
 }
@@ -755,6 +756,7 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 
 	val |= 0xc0000000;
 
+	(void)(node);
 	pci_read_config_dword(dev, 0x58, &scrubber);
 	scrubber &= ~0x1f000000;
 	pci_write_config_dword(dev, 0x58, scrubber);
Signature · 1 line
1.6.0.6
#3 lore raw
Quoted 59 lines · Jaswinder Singh Rajput
Quoted 15 lines · Ingo Molnar
Quoted 13 lines · Jaswinder Singh Rajput

Add reference to node in node_to_k8_nb_misc for !CONFIG_K8_NB to make compiler happy.

So fixes compiler warnings:
arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘show_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:712: warning: unused variable ‘node’ arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘store_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:739: warning: unused variable ‘node’

---
 arch/x86/include/asm/k8.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 22 lines

arch/x86/include/asm/k8.h extern int k8_scan_nodes(unsigned long start, unsigned long end); · line 20

Quoted 11 lines
arch/x86/include/asm/k8.h +1 -1
index c23b3d1..c81e4ee 100644
@@ -16,7 +16,7 @@ extern int k8_scan_nodes(unsigned long start, unsigned long end);
 #define node_to_k8_nb_misc(node) \
 	(node < num_k8_northbridges) ? k8_northbridges[node] : NULL
 #else
-#define node_to_k8_nb_misc(node) NULL
+#define node_to_k8_nb_misc(node) (node) ? NULL : NULL
 #endif

Ugh, that's very ugly. I gave you a proper solution:

Quoted 7 lines
Quoted 7 lines

The typical way to solve this is to add a dummy:

	(void)(cpu)

use to the 'cpu' parameter to the macro definition - or, (which is a much better solution), to convert it to an inline function.

Subject: [PATCH] x86: cpu/cacheinfo.c reference to node for node_to_k8_nb_misc for !CONFIG_K8_NB

Add reference to node for node_to_k8_nb_misc for !CONFIG_K8_NB to make compiler happy.

And fixes:
arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘show_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:712: warning: unused variable ‘node’ arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘store_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:739: warning: unused variable ‘node’

---
 arch/x86/kernel/cpu/intel_cacheinfo.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +0 -0
index 789efe2..4414c92 100644

arch/x86/kernel/cpu/intel_cacheinfo.c static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf, · line 722

Quoted 4 lines
arch/x86/kernel/cpu/intel_cacheinfo.c +1 -0
@@ -719,6 +719,7 @@ static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
 	if (!dev)
 		return -EINVAL;
 
+	(void)(node);

No, we should fix the node_to_k8_nb_misc() primitive.

I.e. convert node_to_k8_nb_misc() from a macro to an inline function. Same end result in terms of emitted instructions, but the compiler now knows that 'node' is really used.

With a macro the preprocessor hid this fact from the compiler, so the compiler only saw this in essence:

        int node = 0;
        struct pci_dev *dev;

and thought that 'node' was unused. Hence it emitted a warning. This is one reason why macros are bad - they hide program logic from the compiler.

Ingo

#4 lore raw
Quoted 7 lines · Ingo Molnar

I.e. convert node_to_k8_nb_misc() from a macro to an inline function. Same end result in terms of emitted instructions, but the compiler now knows that 'node' is really used.

With a macro the preprocessor hid this fact from the compiler, so the compiler only saw this in essence:

Quoted 7 lines
        int node = 0;
        struct pci_dev *dev;

and thought that 'node' was unused. Hence it emitted a warning. This is one reason why macros are bad - they hide program logic from the compiler.

Subject: [PATCH] x86: k8 convert node_to_k8_nb_misc() from a macro to an inline function

Converting node_to_k8_nb_misc() from a macro to an inline function makes complier happy for !CONFIG_K8_NB so fixes compiler warnings:
arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘show_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:712: warning: unused variable ‘node’ arch/x86/kernel/cpu/intel_cacheinfo.c: In function ‘store_cache_disable’:
arch/x86/kernel/cpu/intel_cacheinfo.c:739: warning: unused variable ‘node’

Thanks to Ingo for the guidance.

---
 arch/x86/include/asm/k8.h |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/include/asm/k8.h +8 -3
index c23b3d1..c2d1f3b 100644
@@ -13,10 +13,15 @@ extern void k8_flush_garts(void);
 extern int k8_scan_nodes(unsigned long start, unsigned long end);
 
 #ifdef CONFIG_K8_NB
-#define node_to_k8_nb_misc(node) \
-	(node < num_k8_northbridges) ? k8_northbridges[node] : NULL
+static inline struct pci_dev *node_to_k8_nb_misc(int node)
+{
+	return (node < num_k8_northbridges) ? k8_northbridges[node] : NULL;
+}
 #else
-#define node_to_k8_nb_misc(node) NULL
+static inline struct pci_dev *node_to_k8_nb_misc(int node)
+{
+	return NULL;
+}
 #endif
 
 
Signature · 1 line
1.6.0.6