| To: | Ralf Baechle <ralf@linux-mips.org> |
|---|---|
| Subject: | Re: [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable |
| From: | Geert Uytterhoeven <geert@linux-m68k.org> |
| Date: | Wed, 16 Jan 2013 19:09:18 +0100 |
| Cc: | Cong Ding <dinggnu@gmail.com>, Jim Quinlan <jim2101024@gmail.com>, linux-mips@linux-mips.org, linux-kernel@vger.kernel.org, David Daney <ddaney@caviumnetworks.com> |
| Dkim-signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=0tg41AYSFwqmwHoR+CxX34iOehT9wdxGIcF1UqVPI5c=; b=szvLsjEVRYhvp88Pr/Xj5NQ7iNGXi1c6fVv+9bZA76KZnDpzyT7SbZowsr3TKl3Xdt sQpC4wfZBrwlRAJWigvuOupI2eX4LDEF+rjHkvBQZGwEr94QF8YCtdNpwFhVo+HNTuVo 9oEiUipk4S9+t1H1reu+J4Teklo7V0kZlIjpyAJScIgDx5dhoVqX7yZuHSqgCvnZbUSL IaO63dbE3V4+tocXovC5Chvn0w8qDfNe+WxdRt7n6V/7J0SXVGUrheOvge71l/xUOkEF 4pu0WHYiEWu/cwwHYdXpeolWIvLstpkAcwavNSzdFwHQ8aWVBNiIKAC/64K0rtLVOeb0 fR4A== |
| In-reply-to: | <20130116105757.GB26569@linux-mips.org> |
| List-archive: | <http://www.linux-mips.org/archives/linux-mips/> |
| List-help: | <mailto:ecartis@linux-mips.org?Subject=help> |
| List-id: | linux-mips <linux-mips.eddie.linux-mips.org> |
| List-owner: | <mailto:ralf@linux-mips.org> |
| List-post: | <mailto:linux-mips@linux-mips.org> |
| List-software: | Ecartis version 1.0.0 |
| List-subscribe: | <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips> |
| List-unsubscribe: | <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips> |
| References: | <1358200025-15994-1-git-send-email-dinggnu@gmail.com> <20130116105757.GB26569@linux-mips.org> |
| Sender: | linux-mips-bounce@linux-mips.org |
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
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable, David Daney |
|---|---|
| Next by Date: | Re: [PATCH] [RFC] Proposed changes to eliminate 'union mips_instruction' type., David Daney |
| Previous by Thread: | Re: [PATCH] mpis: cavium-octeon/executive/cvmx-l2c.c: fix uninitialized variable, David Daney |
| Next by Thread: | [PATCH] [RFC] Proposed changes to eliminate 'union mips_instruction' type., Steven J. Hill |
| Indexes: | [Date] [Thread] [Top] [All Lists] |