public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable
@ 2013-01-14 21:47 Cong Ding
  2013-01-16 10:57 ` Ralf Baechle
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Ding @ 2013-01-14 21:47 UTC (permalink / raw)
  To: Ralf Baechle, Jim Quinlan, linux-mips, linux-kernel; +Cc: Cong Ding

the variable dummy is used without initialization.

Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
 arch/mips/cavium-octeon/executive/cvmx-l2c.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/cavium-octeon/executive/cvmx-l2c.c b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
index 9f883bf..d7e07af 100644
--- a/arch/mips/cavium-octeon/executive/cvmx-l2c.c
+++ b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
@@ -286,7 +286,7 @@ uint64_t cvmx_l2c_read_perf(uint32_t counter)
 static void fault_in(uint64_t addr, int len)
 {
 	volatile char *ptr;
-	volatile char dummy;
+	volatile char dummy = 0;
 	/*
 	 * Adjust addr and length so we get all cache lines even for
 	 * small ranges spanning two cache lines.
-- 
1.7.9.5


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

* Re: [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable
  2013-01-14 21:47 [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable Cong Ding
@ 2013-01-16 10:57 ` Ralf Baechle
  2013-01-16 17:56   ` David Daney
  2013-01-16 18:09   ` Geert Uytterhoeven
  0 siblings, 2 replies; 4+ messages in thread
From: Ralf Baechle @ 2013-01-16 10:57 UTC (permalink / raw)
  To: Cong Ding; +Cc: Jim Quinlan, linux-mips, linux-kernel, David Daney

On Mon, Jan 14, 2013 at 10:47:03PM +0100, Cong Ding wrote:

> the variable dummy is used without initialization.

Interesting - I wonder how you found this one.  My compiler (gcc 4.7)
doesn't warn about this one.

Nor does gcc notice that the whole summing up business is wasted efford.

So here's my counter proposal.  It works because ptr is a volatile pointer
so the compiler will always dereference it even if the returned value is
not being used.  The resulting code is a bit smaller.

  Ralf

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

 arch/mips/cavium-octeon/executive/cvmx-l2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/cavium-octeon/executive/cvmx-l2c.c b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
index 9f883bf..ec3e059 100644
--- a/arch/mips/cavium-octeon/executive/cvmx-l2c.c
+++ b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
@@ -286,7 +286,7 @@ uint64_t cvmx_l2c_read_perf(uint32_t counter)
 static void fault_in(uint64_t addr, int len)
 {
 	volatile char *ptr;
-	volatile char dummy;
+
 	/*
 	 * Adjust addr and length so we get all cache lines even for
 	 * small ranges spanning two cache lines.
@@ -300,7 +300,7 @@ static void fault_in(uint64_t addr, int len)
 	 */
 	CVMX_DCACHE_INVALIDATE;
 	while (len > 0) {
-		dummy += *ptr;
+		*ptr;
 		len -= CVMX_CACHE_LINE_SIZE;
 		ptr += CVMX_CACHE_LINE_SIZE;
 	}

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

* Re: [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable
  2013-01-16 10:57 ` Ralf Baechle
@ 2013-01-16 17:56   ` David Daney
  2013-01-16 18:09   ` Geert Uytterhoeven
  1 sibling, 0 replies; 4+ messages in thread
From: David Daney @ 2013-01-16 17:56 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Cong Ding, Jim Quinlan, linux-mips, linux-kernel

On 01/16/2013 02:57 AM, Ralf Baechle wrote:
> On Mon, Jan 14, 2013 at 10:47:03PM +0100, Cong Ding wrote:
>
>> the variable dummy is used without initialization.
>
> Interesting - I wonder how you found this one.  My compiler (gcc 4.7)
> doesn't warn about this one.
>

I get no warnings either.  So I wonder what the point of churning up the 
code is.

David Daney

> Nor does gcc notice that the whole summing up business is wasted efford.
>
> So here's my counter proposal.  It works because ptr is a volatile pointer
> so the compiler will always dereference it even if the returned value is
> not being used.  The resulting code is a bit smaller.
>
>    Ralf
>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
>
>   arch/mips/cavium-octeon/executive/cvmx-l2c.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/mips/cavium-octeon/executive/cvmx-l2c.c b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
> index 9f883bf..ec3e059 100644
> --- a/arch/mips/cavium-octeon/executive/cvmx-l2c.c
> +++ b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
> @@ -286,7 +286,7 @@ uint64_t cvmx_l2c_read_perf(uint32_t counter)
>   static void fault_in(uint64_t addr, int len)
>   {
>   	volatile char *ptr;
> -	volatile char dummy;
> +
>   	/*
>   	 * Adjust addr and length so we get all cache lines even for
>   	 * small ranges spanning two cache lines.
> @@ -300,7 +300,7 @@ static void fault_in(uint64_t addr, int len)
>   	 */
>   	CVMX_DCACHE_INVALIDATE;
>   	while (len > 0) {
> -		dummy += *ptr;
> +		*ptr;
>   		len -= CVMX_CACHE_LINE_SIZE;
>   		ptr += CVMX_CACHE_LINE_SIZE;
>   	}
>
>
>



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

* Re: [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable
  2013-01-16 10:57 ` Ralf Baechle
  2013-01-16 17:56   ` David Daney
@ 2013-01-16 18:09   ` Geert Uytterhoeven
  1 sibling, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2013-01-16 18:09 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: Cong Ding, Jim Quinlan, linux-mips, linux-kernel, David Daney

On Wed, Jan 16, 2013 at 11:57 AM, Ralf Baechle <ralf@linux-mips.org> wrote:
> On Mon, Jan 14, 2013 at 10:47:03PM +0100, Cong Ding wrote:
>
>> the variable dummy is used without initialization.
>
> Interesting - I wonder how you found this one.  My compiler (gcc 4.7)
> doesn't warn about this one.

Probably older gcc does.

> Nor does gcc notice that the whole summing up business is wasted efford.
>
> So here's my counter proposal.  It works because ptr is a volatile pointer
> so the compiler will always dereference it even if the returned value is
> not being used.  The resulting code is a bit smaller.
>
>   Ralf
>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
>
>  arch/mips/cavium-octeon/executive/cvmx-l2c.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/mips/cavium-octeon/executive/cvmx-l2c.c b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
> index 9f883bf..ec3e059 100644
> --- a/arch/mips/cavium-octeon/executive/cvmx-l2c.c
> +++ b/arch/mips/cavium-octeon/executive/cvmx-l2c.c
> @@ -286,7 +286,7 @@ uint64_t cvmx_l2c_read_perf(uint32_t counter)
>  static void fault_in(uint64_t addr, int len)
>  {
>         volatile char *ptr;
> -       volatile char dummy;
> +
>         /*
>          * Adjust addr and length so we get all cache lines even for
>          * small ranges spanning two cache lines.
> @@ -300,7 +300,7 @@ static void fault_in(uint64_t addr, int len)
>          */
>         CVMX_DCACHE_INVALIDATE;
>         while (len > 0) {
> -               dummy += *ptr;
> +               *ptr;

Alternatively, to make clearer what's intended:
  - drop the "volatile" from "ptr" and from the cast when assigning to it,
  - use "ACCESS_ONCE(*ptr)" instead of "*ptr".

>                 len -= CVMX_CACHE_LINE_SIZE;
>                 ptr += CVMX_CACHE_LINE_SIZE;
>         }

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2013-01-16 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-14 21:47 [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable Cong Ding
2013-01-16 10:57 ` Ralf Baechle
2013-01-16 17:56   ` David Daney
2013-01-16 18:09   ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox