2014-07-17 13:26:55

by Andrey Utkin

[permalink] [raw]
Subject: [PATCH 1/3] arch/metag/kernel/cachepart.c: fix failure check

[linux-3.16-rc5/arch/metag/kernel/cachepart.c:102]: (style) Checking if unsigned variable 'thread_cache_size' is less than zero.

Source code is

if (thread_cache_size < 0)
pr_emerg("Can't read %s cache size\n",
cache_type ? "DCACHE" : "ICACHE");

but

unsigned int thread_cache_size;

Function get_thread_cache_size returns an error code
as (unsigned int) -1.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80361
Reported-by: David Binderman <[email protected]>
Signed-off-by: Andrey Utkin <[email protected]>
---
arch/metag/kernel/cachepart.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/metag/kernel/cachepart.c b/arch/metag/kernel/cachepart.c
index 0a2385f..b137034 100644
--- a/arch/metag/kernel/cachepart.c
+++ b/arch/metag/kernel/cachepart.c
@@ -99,7 +99,7 @@ void check_for_cache_aliasing(int thread_id)
for (cache_type = ICACHE; cache_type <= DCACHE; cache_type++) {
thread_cache_size =
get_thread_cache_size(cache_type, thread_id);
- if (thread_cache_size < 0)
+ if (thread_cache_size == (unsigned int)-1)
pr_emerg("Can't read %s cache size\n",
cache_type ? "DCACHE" : "ICACHE");
else if (thread_cache_size == 0)
--
1.8.5.5


2014-07-17 14:25:15

by Andrey Utkin

[permalink] [raw]
Subject: Re: [PATCH 1/3] arch/metag/kernel/cachepart.c: fix failure check

2014-07-17 16:26 GMT+03:00 Andrey Utkin <[email protected]>:
> --- a/arch/metag/kernel/cachepart.c
> +++ b/arch/metag/kernel/cachepart.c
> @@ -99,7 +99,7 @@ void check_for_cache_aliasing(int thread_id)
> for (cache_type = ICACHE; cache_type <= DCACHE; cache_type++) {
> thread_cache_size =
> get_thread_cache_size(cache_type, thread_id);
> - if (thread_cache_size < 0)
> + if (thread_cache_size == (unsigned int)-1)

If it would be better, i can resubmit with addition of signed
variable, like there: https://patchwork.kernel.org/patch/4575881/

--
Andrey Utkin

2014-07-17 14:58:15

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 1/3] arch/metag/kernel/cachepart.c: fix failure check

On Thu, Jul 17, 2014 at 04:26:26PM +0300, Andrey Utkin wrote:
> [linux-3.16-rc5/arch/metag/kernel/cachepart.c:102]: (style) Checking if unsigned variable 'thread_cache_size' is less than zero.
>
> Source code is
>
> if (thread_cache_size < 0)
> pr_emerg("Can't read %s cache size\n",
> cache_type ? "DCACHE" : "ICACHE");
>
> but
>
> unsigned int thread_cache_size;
>
> Function get_thread_cache_size returns an error code
> as (unsigned int) -1.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80361
> Reported-by: David Binderman <[email protected]>
> Signed-off-by: Andrey Utkin <[email protected]>
> ---
> arch/metag/kernel/cachepart.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/metag/kernel/cachepart.c b/arch/metag/kernel/cachepart.c
> index 0a2385f..b137034 100644
> --- a/arch/metag/kernel/cachepart.c
> +++ b/arch/metag/kernel/cachepart.c
> @@ -99,7 +99,7 @@ void check_for_cache_aliasing(int thread_id)
> for (cache_type = ICACHE; cache_type <= DCACHE; cache_type++) {
> thread_cache_size =
> get_thread_cache_size(cache_type, thread_id);
> - if (thread_cache_size < 0)
> + if (thread_cache_size == (unsigned int)-1)

Oh, wow. Every single variable in this file is an unsigned int. :P

We should just make this int. The values of thread_cache_size do not
go that high.

regards,
dan carpenter

2014-07-17 15:58:18

by Andrey Utkin

[permalink] [raw]
Subject: [PATCH] arch/metag/kernel/cachepart.c: fix failure check

[linux-3.16-rc5/arch/metag/kernel/cachepart.c:102]: (style) Checking if
unsigned variable 'thread_cache_size' is less than zero.

Source code is

if (thread_cache_size < 0)
pr_emerg("Can't read %s cache size\n",
cache_type ? "DCACHE" : "ICACHE");

but

unsigned int thread_cache_size;

Function get_thread_cache_size returns an error code
as (unsigned int) -1.

Changed get_thread_cache_size() to return signed int, and its result is stored
into signed int variable.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80361
Reported-by: David Binderman <[email protected]>
Signed-off-by: Andrey Utkin <[email protected]>
---
arch/metag/kernel/cachepart.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/metag/kernel/cachepart.c b/arch/metag/kernel/cachepart.c
index 0a2385f..04b7d4f 100644
--- a/arch/metag/kernel/cachepart.c
+++ b/arch/metag/kernel/cachepart.c
@@ -55,7 +55,7 @@ unsigned int get_global_icache_size(void)
return (get_icache_size() * ((temp >> SYSC_xCPARTG_AND_S) + 1)) >> 4;
}

-static unsigned int get_thread_cache_size(unsigned int cache, int thread_id)
+static int get_thread_cache_size(unsigned int cache, int thread_id)
{
unsigned int cache_size;
unsigned int t_cache_part;
@@ -94,7 +94,7 @@ static unsigned int get_thread_cache_size(unsigned int cache, int thread_id)

void check_for_cache_aliasing(int thread_id)
{
- unsigned int thread_cache_size;
+ int thread_cache_size;
unsigned int cache_type;
for (cache_type = ICACHE; cache_type <= DCACHE; cache_type++) {
thread_cache_size =
--
1.8.5.5

2014-07-18 09:45:39

by James Hogan

[permalink] [raw]
Subject: Re: [PATCH] arch/metag/kernel/cachepart.c: fix failure check

On 17/07/14 16:58, Andrey Utkin wrote:
> [linux-3.16-rc5/arch/metag/kernel/cachepart.c:102]: (style) Checking if
> unsigned variable 'thread_cache_size' is less than zero.
>
> Source code is
>
> if (thread_cache_size < 0)
> pr_emerg("Can't read %s cache size\n",
> cache_type ? "DCACHE" : "ICACHE");
>
> but
>
> unsigned int thread_cache_size;
>
> Function get_thread_cache_size returns an error code
> as (unsigned int) -1.
>
> Changed get_thread_cache_size() to return signed int, and its result is stored
> into signed int variable.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80361
> Reported-by: David Binderman <[email protected]>
> Signed-off-by: Andrey Utkin <[email protected]>

Thanks, applied!

Cheers
James

> ---
> arch/metag/kernel/cachepart.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/metag/kernel/cachepart.c b/arch/metag/kernel/cachepart.c
> index 0a2385f..04b7d4f 100644
> --- a/arch/metag/kernel/cachepart.c
> +++ b/arch/metag/kernel/cachepart.c
> @@ -55,7 +55,7 @@ unsigned int get_global_icache_size(void)
> return (get_icache_size() * ((temp >> SYSC_xCPARTG_AND_S) + 1)) >> 4;
> }
>
> -static unsigned int get_thread_cache_size(unsigned int cache, int thread_id)
> +static int get_thread_cache_size(unsigned int cache, int thread_id)
> {
> unsigned int cache_size;
> unsigned int t_cache_part;
> @@ -94,7 +94,7 @@ static unsigned int get_thread_cache_size(unsigned int cache, int thread_id)
>
> void check_for_cache_aliasing(int thread_id)
> {
> - unsigned int thread_cache_size;
> + int thread_cache_size;
> unsigned int cache_type;
> for (cache_type = ICACHE; cache_type <= DCACHE; cache_type++) {
> thread_cache_size =
>