kprobes: get rid of distinct type warning
Subsystems (2)
From: Heiko Carstens <[email protected]>
Every time I see this:
kernel/kprobes.c: In function 'register_kretprobe':kernel/kprobes.c:1038: warning: comparison of distinct pointer types lacks a cast
I'm wondering if something changed in common code and we need to do something for s390. Apparently that's not the case. Let's get rid of this annoying warning.
--- kernel/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kprobes.c +1 -1
@@ -1035,7 +1035,7 @@ int __kprobes register_kretprobe(struct/* Pre-allocate memory for max kretprobe instances */ if (rp->maxactive <=0 ) {#ifdef CONFIG_PREEMPT - rp->maxactive =max (10 ,2 *num_possible_cpus ()); + rp->maxactive =max (10U ,2 *num_possible_cpus ());#else rp->maxactive =num_possible_cpus ();#endif
Ananth N Mavinakayanahalli
Acked-byQuoted 7 lines · Heiko Carstens
From: Heiko Carstens <[email protected]>
Every time I see this:
kernel/kprobes.c: In function 'register_kretprobe':kernel/kprobes.c:1038: warning: comparison of distinct pointer types lacks a cast
Quoted 6 lines
I'm wondering if something changed in common code and we need to do something for s390. Apparently that's not the case. Let's get rid of this annoying warning.
Cc Ananth N Mavinakayanahalli <[email protected]>Signed-off-by Heiko Carstens <[email protected]>
Thanks Heiko. I'd tested this on x86 and powerpc and neither throws the warning. No wonder I missed it.
Heiko Carstens
Acked-by Ananth N MavinakayanahalliQuoted 12 lines · Ananth N Mavinakayanahalli
Quoted 11 lines · Heiko Carstens
From: Heiko Carstens <[email protected]>
Every time I see this:
kernel/kprobes.c: In function 'register_kretprobe':kernel/kprobes.c:1038: warning: comparison of distinct pointer types lacks a castI'm wondering if something changed in common code and we need to do something for s390. Apparently that's not the case. Let's get rid of this annoying warning.
Quoted 7 lines
Quoted 2 lines
Cc Ananth N Mavinakayanahalli <[email protected]>Signed-off-by Heiko Carstens <[email protected]>Thanks Heiko. I'd tested this on x86 and powerpc and neither throws the warning. No wonder I missed it.
Of course the patch wouldn't help for CONFIG_PREEMPT and !CONFIG_SMP since we would have a comparison of a signed and and unsigned value again *sigh*.
So here's an updated version that should always work:
Subject: [PATCH] kprobes: get rid of distinct type warning
From: Heiko Carstens <[email protected]>
Every time I see this:
kernel/kprobes.c: In function 'register_kretprobe':kernel/kprobes.c:1038: warning: comparison of distinct pointer types lacks a cast
I'm wondering if something changed in common code and we need to do something for s390. Apparently that's not the case. Let's get rid of this annoying warning.
--- kernel/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kprobes.c +1 -1
@@ -1035,7 +1035,7 @@ int __kprobes register_kretprobe(struct/* Pre-allocate memory for max kretprobe instances */ if (rp->maxactive <=0 ) {#ifdef CONFIG_PREEMPT - rp->maxactive =max (10 ,2 *num_possible_cpus ()); + rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus());#else rp->maxactive =num_possible_cpus ();#endif
[tip:perf/urgent] kprobes: Fix distinct type warning
Commit-ID: c2ef6661ce62e26a8c0978e521fab646128a144b Gitweb: http://git.kernel.org/tip/c2ef6661ce62e26a8c0978e521fab646128a144b Author: Heiko Carstens <[email protected]> AuthorDate: Mon, 21 Dec 2009 13:02:24 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 28 Dec 2009 10:25:31 +0100
kprobes: Fix distinct type warning
Every time I see this:
kernel/kprobes.c: In function 'register_kretprobe':
kernel/kprobes.c:1038: warning: comparison of distinct pointer types lacks a cast
I'm wondering if something changed in common code and we need to do something for s390. Apparently that's not the case. Let's get rid of this annoying warning.
LKML-Reference: <[email protected]>
--- kernel/kprobes.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/kprobes.c +1 -1
@@ -1035,7 +1035,7 @@ int __kprobes register_kretprobe(struct kretprobe *rp)/* Pre-allocate memory for max kretprobe instances */ if (rp->maxactive <=0 ) {#ifdef CONFIG_PREEMPT - rp->maxactive =max (10 ,2 *num_possible_cpus ()); + rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus());#else rp->maxactive =num_possible_cpus ();#endif
Quoted 2 lines · On Mon, 21 Dec 2009 13:02:24 +0100 Heiko Carstens <[email protected]>…
Of course the patch wouldn't help for
CONFIG_PREEMPTand !CONFIG_SMP since we would have a comparison of a signed and and unsigned value again *sigh*.
We should fix that, shouldn't we? Rather than working around it at one caller site.
: #if NR_CPUS > 1
: #define num_online_cpus() cpumask_weight(cpu_online_mask)
: #define num_possible_cpus() cpumask_weight(cpu_possible_mask)
: #define num_present_cpus() cpumask_weight(cpu_present_mask)
: #define num_active_cpus() cpumask_weight(cpu_active_mask)
: #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
: #define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
: #define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
: #define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
: #else
: #define num_online_cpus() 1
: #define num_possible_cpus() 1
: #define num_present_cpus() 1
: #define num_active_cpus() 1
: #define cpu_online(cpu) ((cpu) == 0)
: #define cpu_possible(cpu) ((cpu) == 0)
: #define cpu_present(cpu) ((cpu) == 0)
: #define cpu_active(cpu) ((cpu) == 0)
: #endif
The num_*() "functions" return unsigned on SMP and int on UP. This is wrong.
The cpu_*() "functions" got lucky and return int in both cases.
Personally I think it's neatest if a quantity which can never be negative is held in an unsigned type. Than includes anything starting with "num". But for expediency's sake we could live with making these things consistently return "int".
Alas, changing those four num_*() "functions" to return int on SMP is a pretty wide-reaching change and will probably expose warts.
Quoted 34 lines · Andrew Morton
Quoted 2 lines · On Mon, 21 Dec 2009 13:02:24 +0100 Heiko Carstens <[email protected]>…
Of course the patch wouldn't help for
CONFIG_PREEMPTand !CONFIG_SMP since we would have a comparison of a signed and and unsigned value again *sigh*.We should fix that, shouldn't we? Rather than working around it at one caller site.
: #if
NR_CPUS> 1
: #definenum_online_cpus()cpumask_weight(cpu_online_mask)
: #definenum_possible_cpus()cpumask_weight(cpu_possible_mask)
: #definenum_present_cpus()cpumask_weight(cpu_present_mask)
: #definenum_active_cpus()cpumask_weight(cpu_active_mask)
: #definecpu_online(cpu)cpumask_test_cpu((cpu), cpu_online_mask)
: #definecpu_possible(cpu)cpumask_test_cpu((cpu), cpu_possible_mask)
: #definecpu_present(cpu)cpumask_test_cpu((cpu), cpu_present_mask)
: #definecpu_active(cpu)cpumask_test_cpu((cpu), cpu_active_mask)
: #else
: #definenum_online_cpus()1
: #definenum_possible_cpus()1
: #definenum_present_cpus()1
: #definenum_active_cpus()1
: #definecpu_online(cpu)((cpu) == 0)
: #definecpu_possible(cpu)((cpu) == 0)
: #definecpu_present(cpu)((cpu) == 0)
: #definecpu_active(cpu)((cpu) == 0)
: #endifThe num_*() "functions" return unsigned on SMP and int on UP. This is wrong.
The cpu_*() "functions" got lucky and return int in both cases.
Quoted 7 lines
Personally I think it's neatest if a quantity which can never be negative is held in an unsigned type. Than includes anything starting with "num". But for expediency's sake we could live with making these things consistently return "int".
Alas, changing those four num_*() "functions" to return int on SMP is a pretty wide-reaching change and will probably expose warts.
Looks like there are quite a lot of num_* function usages in the kernel. Some seem to assume they return an int some assume an unsigned int. Don't know if it's worth changing anything here.
Maybe Rusty has an opinion.
Quoted 40 lines · Heiko Carstens
Quoted 39 lines · Andrew Morton
Quoted 2 lines · On Mon, 21 Dec 2009 13:02:24 +0100 Heiko Carstens <[email protected]>…
Of course the patch wouldn't help for
CONFIG_PREEMPTand !CONFIG_SMP since we would have a comparison of a signed and and unsigned value again *sigh*.We should fix that, shouldn't we? Rather than working around it at one caller site.
: #if
NR_CPUS> 1
: #definenum_online_cpus()cpumask_weight(cpu_online_mask)
: #definenum_possible_cpus()cpumask_weight(cpu_possible_mask)
: #definenum_present_cpus()cpumask_weight(cpu_present_mask)
: #definenum_active_cpus()cpumask_weight(cpu_active_mask)
: #definecpu_online(cpu)cpumask_test_cpu((cpu), cpu_online_mask)
: #definecpu_possible(cpu)cpumask_test_cpu((cpu), cpu_possible_mask)
: #definecpu_present(cpu)cpumask_test_cpu((cpu), cpu_present_mask)
: #definecpu_active(cpu)cpumask_test_cpu((cpu), cpu_active_mask)
: #else
: #definenum_online_cpus()1
: #definenum_possible_cpus()1
: #definenum_present_cpus()1
: #definenum_active_cpus()1
: #definecpu_online(cpu)((cpu) == 0)
: #definecpu_possible(cpu)((cpu) == 0)
: #definecpu_present(cpu)((cpu) == 0)
: #definecpu_active(cpu)((cpu) == 0)
: #endifThe num_*() "functions" return unsigned on SMP and int on UP. This is wrong.
The cpu_*() "functions" got lucky and return int in both cases.
Personally I think it's neatest if a quantity which can never be negative is held in an unsigned type. Than includes anything starting with "num". But for expediency's sake we could live with making these things consistently return "int".
Quoted 7 lines
Quoted 2 lines
Alas, changing those four num_*() "functions" to return int on SMP is a pretty wide-reaching change and will probably expose warts.
Looks like there are quite a lot of num_* function usages in the kernel. Some seem to assume they return an int some assume an unsigned int. Don't know if it's worth changing anything here.
Maybe Rusty has an opinion.
If we have to go one way or the other, go with unsigned.
What does such a patch look like?
Thanks,
Rusty.
Quoted 15 lines · Rusty Russell
Quoted 14 lines · Heiko Carstens
Quoted 12 lines · Andrew Morton
The num_*() "functions" return unsigned on SMP and int on UP. This is wrong.
The cpu_*() "functions" got lucky and return int in both cases.
Personally I think it's neatest if a quantity which can never be negative is held in an unsigned type. Than includes anything starting with "num". But for expediency's sake we could live with making these things consistently return "int".
Alas, changing those four num_*() "functions" to return int on SMP is a pretty wide-reaching change and will probably expose warts.
Quoted 8 lines
Quoted 4 lines
Looks like there are quite a lot of num_* function usages in the kernel. Some seem to assume they return an int some assume an unsigned int. Don't know if it's worth changing anything here.
Maybe Rusty has an opinion.If we have to go one way or the other, go with unsigned.
What does such a patch look like?
Something like this, doesn't even trigger new warnings on an !SMP defconfig build:
Subject: [PATCH] cpumask: let num_*_cpus() function always return unsigned values
From: Heiko Carstens <[email protected]>
Dependent on CONFIG_SMP the num_*_cpus() functions return unsigned or signed values.
Let them always return unsigned values to avoid strange casts.
--- include/linux/cpumask.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/cpumask.h +4 -4
@@ -90,10 +90,10 @@ extern const struct cpumask *const cpu_a#define cpu_present (cpu) cpumask_test_cpu((cpu), cpu_present_mask)#define cpu_active (cpu) cpumask_test_cpu((cpu), cpu_active_mask)#else -#define num_online_cpus () 1 -#define num_possible_cpus () 1 -#define num_present_cpus () 1 -#define num_active_cpus () 1 +#define num_online_cpus () 1U +#define num_possible_cpus () 1U +#define num_present_cpus () 1U +#define num_active_cpus () 1U#define cpu_online (cpu) ((cpu) == 0)#define cpu_possible (cpu) ((cpu) == 0)#define cpu_present (cpu) ((cpu) == 0)
Quoted 48 lines · On Tue, 5 Jan 2010 09:40:27 +0100 Heiko Carstens <[email protected]>…
Quoted 15 lines · Rusty Russell
Quoted 14 lines · Heiko Carstens
Quoted 12 lines · Andrew Morton
The num_*() "functions" return unsigned on SMP and int on UP. This is wrong.
The cpu_*() "functions" got lucky and return int in both cases.
Personally I think it's neatest if a quantity which can never be negative is held in an unsigned type. Than includes anything starting with "num". But for expediency's sake we could live with making these things consistently return "int".
Alas, changing those four num_*() "functions" to return int on SMP is a pretty wide-reaching change and will probably expose warts.
Quoted 8 lines
Quoted 4 lines
Looks like there are quite a lot of num_* function usages in the kernel. Some seem to assume they return an int some assume an unsigned int. Don't know if it's worth changing anything here.
Maybe Rusty has an opinion.If we have to go one way or the other, go with unsigned.
What does such a patch look like?
Something like this, doesn't even trigger new warnings on an !SMP defconfig build:
Subject: [PATCH] cpumask: let num_*_cpus() function always return unsigned values
From: Heiko Carstens <[email protected]>
Dependent on
CONFIG_SMPthe num_*_cpus() functions return unsigned or signed values.
Let them always return unsigned values to avoid strange casts.Signed-off-by Heiko Carstens <[email protected]>--- include/linux/cpumask.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/linux/cpumask.h +0
-1@@ -90,10 +90,10 @@ extern const struct cpumask *const cpu_a#define cpu_present (cpu) cpumask_test_cpu((cpu), cpu_present_mask)#define cpu_active (cpu) cpumask_test_cpu((cpu), cpu_active_mask)#else -#define num_online_cpus () 1
include/linux/cpumask.h extern const struct cpumask *const cpu_a · line 99
Quoted 10 lines
include/linux/cpumask.h +4
-3-#define num_possible_cpus () 1 -#define num_present_cpus () 1 -#define num_active_cpus () 1 +#define num_online_cpus () 1U +#define num_possible_cpus () 1U +#define num_present_cpus () 1U +#define num_active_cpus () 1U#define cpu_online (cpu) ((cpu) == 0)#define cpu_possible (cpu) ((cpu) == 0)#define cpu_present (cpu) ((cpu) == 0)
I assume that this fixes the kprobes warning, so
Commit-ID: c2ef6661ce62e26a8c0978e521fab646128a144b Gitweb: http://git.kernel.org/tip/c2ef6661ce62e26a8c0978e521fab646128a144b Author: Heiko Carstens <[email protected]> AuthorDate: Mon, 21 Dec 2009 13:02:24 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 28 Dec 2009 10:25:31 +0100
becomes unneeded?
Quoted 22 lines · Andrew Morton
Quoted 7 lines · On Tue, 5 Jan 2010 09:40:27 +0100 Heiko Carstens <[email protected]>…
include/linux/cpumask.h +0
-1@@ -90,10 +90,10 @@ extern const struct cpumask *const cpu_a#define cpu_present (cpu) cpumask_test_cpu((cpu), cpu_present_mask)#define cpu_active (cpu) cpumask_test_cpu((cpu), cpu_active_mask)#else -#define num_online_cpus () 1include/linux/cpumask.h extern const struct cpumask *const cpu_a · line 99
Quoted 10 lines
include/linux/cpumask.h +4
-3-#define num_possible_cpus () 1 -#define num_present_cpus () 1 -#define num_active_cpus () 1 +#define num_online_cpus () 1U +#define num_possible_cpus () 1U +#define num_present_cpus () 1U +#define num_active_cpus () 1U#define cpu_online (cpu) ((cpu) == 0)#define cpu_possible (cpu) ((cpu) == 0)#define cpu_present (cpu) ((cpu) == 0)I assume that this fixes the kprobes warning, so
Quoted 8 lines
Commit-ID: c2ef6661ce62e26a8c0978e521fab646128a144b Gitweb: http://git.kernel.org/tip/c2ef6661ce62e26a8c0978e521fab646128a144b Author: Heiko Carstens <[email protected]> AuthorDate: Mon, 21 Dec 2009 13:02:24 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 28 Dec 2009 10:25:31 +0100becomes unneeded?
Nah, that would be too easy. The code still compares an int (10) and an unsigned int. The only thing that could be changed with this patch is that max_t isn't needed anymore, so that the patch below would work as well (10U).
But I don't think it's worth it.
kernel/kprobes.c +1 -1
@@ -1035,7 +1035,7 @@ int __kprobes register_kretprobe(struct kretprobe *rp)/* Pre-allocate memory for max kretprobe instances */ if (rp->maxactive <=0 ) {#ifdef CONFIG_PREEMPT - rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus()); + rp->maxactive =max (10U ,2 *num_possible_cpus ());#else rp->maxactive =num_possible_cpus ();#endif