2010-11-04 10:49:26

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [1/3] futex: fix compiler warnings in exit_robust_list

Hey Darren,

On Wed, Oct 27, 2010 at 09:54:24PM -0000, Darren Hart wrote:
> The following commit introduced a compiler warning:
>
> Commit 1dcc41bb037533839753df983d31778b30b67d93
> futex: Change 3rd arg of fetch_robust_entry() to unsigned int*
>
> The following archs/compiler versions all report:
> kernel/futex.c: In function ‘exit_robust_list’:
> kernel/futex.c:2492: warning: ‘next_pi’ may be used uninitialized in this function
>
> x86_64
> gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
> gcc (GCC) 4.4.4 20100630 (Red Hat 4.4.4-10)
> gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
>
> sh
> sh-linux-gnu-gcc (Sourcery G++ Lite 4.3-143) 4.3.3
You can add

arm
arm-1136jfs-linux-gnueabi-gcc (OSELAS.Toolchain-1.99.3) 4.3.2

if you want.

>
> The code path really can't result in next_pi pi being unitialized (or should
> not), but let's keep the build clean. Assign next_pi = 0 to avoid the warnings.
>
> Signed-off-by: Darren Hart <[email protected]>
> Tested-by: Matt Fleming <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> CC: Eric Dumazet <[email protected]>
> CC: John Kacur <[email protected]>
>
> ---
> kernel/futex.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/futex.c b/kernel/futex.c
> index a118bf1..78715cb 100644
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -2489,7 +2489,7 @@ void exit_robust_list(struct task_struct *curr)
> {
> struct robust_list_head __user *head = curr->robust_list;
> struct robust_list __user *entry, *next_entry, *pending;
> - unsigned int limit = ROBUST_LIST_LIMIT, pi, next_pi, pip;
> + unsigned int limit = ROBUST_LIST_LIMIT, pi, next_pi = 0, pip;
I'd prefer

+ unsigned int limit = ROBUST_LIST_LIMIT, pi, uninitialized_var(next_pi), pip;

(modulo line length). This makes your change more explicit.

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |


2010-11-04 19:00:58

by Darren Hart

[permalink] [raw]
Subject: [PATCH V2] futex: fix compiler warnings in exit_robust_list

The following commit introduced a compiler warning:

Commit 1dcc41bb037533839753df983d31778b30b67d93
futex: Change 3rd arg of fetch_robust_entry() to unsigned int*

The following archs/compiler versions all report:
kernel/futex.c: In function ‘exit_robust_list’:
kernel/futex.c:2492: warning: ‘next_pi’ may be used uninitialized in this function

x86_64
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
gcc (GCC) 4.4.4 20100630 (Red Hat 4.4.4-10)
gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5

sh
sh-linux-gnu-gcc (Sourcery G++ Lite 4.3-143) 4.3.3

arm
arm-1136jfs-linux-gnueabi-gcc (OSELAS.Toolchain-1.99.3) 4.3.2

The code path really can't result in next_pi being unitialized (or should
not), but let's keep the build clean. Annotate next_pi as an uninitialized_var.

V2: Implement Uwe's suggestion to use uninitialized_var()

Signed-off-by: Darren Hart <[email protected]>
Tested-by: Matt Fleming <[email protected]>
Tested-by: Uwe Kleine-König <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
CC: Eric Dumazet <[email protected]>
CC: John Kacur <[email protected]>
---
kernel/futex.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 6c683b3..40a8777 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2489,7 +2489,8 @@ void exit_robust_list(struct task_struct *curr)
{
struct robust_list_head __user *head = curr->robust_list;
struct robust_list __user *entry, *next_entry, *pending;
- unsigned int limit = ROBUST_LIST_LIMIT, pi, next_pi, pip;
+ unsigned int limit = ROBUST_LIST_LIMIT, pi, pip;
+ unsigned int uninitialized_var(next_pi);
unsigned long futex_offset;
int rc;

--
1.7.1

2010-11-10 12:21:24

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH V2] futex: fix compiler warnings in exit_robust_list

On Thu, 4 Nov 2010, Darren Hart wrote:

> The following commit introduced a compiler warning:
>
> Commit 1dcc41bb037533839753df983d31778b30b67d93
> futex: Change 3rd arg of fetch_robust_entry() to unsigned int*

This makes not really sense. That commit changed "int *pi" to
"unsigned int *pi" which did not introduce the warning by any
means. It's gcc being stupid, in fact it should have warned before
that change already.

And your patch is incomplete as it forgot to fix the same problem in
futex_compat.c

/me fixes