public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Fix wrong loop bound in flush_cache() when "size" is zero.
@ 2011-08-08  8:07 Yao Cheng
  2011-08-08 12:23 ` Sergei Shtylyov
  0 siblings, 1 reply; 4+ messages in thread
From: Yao Cheng @ 2011-08-08  8:07 UTC (permalink / raw)
  To: u-boot

The issue is found when calling flush_cache() with zero "size" argument.
The bound of loop is miscalculated in this case and flush_cache() enters a wrong flushing loop.
To fix this issue I skipped the operations when "size" is found to be zero.

Signed-off-by: Yao Cheng <saturdaycoder@gmail.com>
Cc: Shinya Kuribayashi <skuribay@pobox.com >
---
 arch/mips/cpu/mips32/cpu.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/mips/cpu/mips32/cpu.c b/arch/mips/cpu/mips32/cpu.c
index 3ae397c..1bf0094 100644
--- a/arch/mips/cpu/mips32/cpu.c
+++ b/arch/mips/cpu/mips32/cpu.c
@@ -52,6 +52,11 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 void flush_cache(ulong start_addr, ulong size)
 {
+  /* aend will be miscalculated when size is zero, so we need return here */
+  if (size == 0) {
+    return;
+  }
+
 	unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
 	unsigned long addr = start_addr & ~(lsize - 1);
 	unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
-- 
1.7.4.1

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

* [U-Boot] [PATCH] Fix wrong loop bound in flush_cache() when "size" is zero.
  2011-08-08  8:07 [U-Boot] [PATCH] Fix wrong loop bound in flush_cache() when "size" is zero Yao Cheng
@ 2011-08-08 12:23 ` Sergei Shtylyov
  2011-08-08 13:55   ` Saturday Coder
  2011-08-08 20:04   ` Scott Wood
  0 siblings, 2 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2011-08-08 12:23 UTC (permalink / raw)
  To: u-boot

Hello.

On 08-08-2011 12:07, Yao Cheng wrote:

> The issue is found when calling flush_cache() with zero "size" argument.
> The bound of loop is miscalculated in this case and flush_cache() enters a wrong flushing loop.
> To fix this issue I skipped the operations when "size" is found to be zero.

> Signed-off-by: Yao Cheng<saturdaycoder@gmail.com>
> Cc: Shinya Kuribayashi<skuribay@pobox.com>
> ---
>   arch/mips/cpu/mips32/cpu.c |    5 +++++
>   1 files changed, 5 insertions(+), 0 deletions(-)

> diff --git a/arch/mips/cpu/mips32/cpu.c b/arch/mips/cpu/mips32/cpu.c
> index 3ae397c..1bf0094 100644
> --- a/arch/mips/cpu/mips32/cpu.c
> +++ b/arch/mips/cpu/mips32/cpu.c
> @@ -52,6 +52,11 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>
>   void flush_cache(ulong start_addr, ulong size)
>   {
> +  /* aend will be miscalculated when size is zero, so we need return here */
> +  if (size == 0) {
> +    return;
> +  }
 > +

    Please indent with tabs, not spaces. Also, doesn't this code generate 
warning (code before declarations)?

>   	unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
>   	unsigned long addr = start_addr&  ~(lsize - 1);
>   	unsigned long aend = (start_addr + size - 1)&  ~(lsize - 1);

WBR, Sergei

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

* [U-Boot] [PATCH] Fix wrong loop bound in flush_cache() when "size" is zero.
  2011-08-08 12:23 ` Sergei Shtylyov
@ 2011-08-08 13:55   ` Saturday Coder
  2011-08-08 20:04   ` Scott Wood
  1 sibling, 0 replies; 4+ messages in thread
From: Saturday Coder @ 2011-08-08 13:55 UTC (permalink / raw)
  To: u-boot

Hi Sergei, thanks for your comments.
I will submit the patch v2.

2011/8/8 Sergei Shtylyov <sshtylyov@mvista.com>

> Hello.
>
>
> On 08-08-2011 12:07, Yao Cheng wrote:
>
>  The issue is found when calling flush_cache() with zero "size" argument.
>> The bound of loop is miscalculated in this case and flush_cache() enters a
>> wrong flushing loop.
>> To fix this issue I skipped the operations when "size" is found to be
>> zero.
>>
>
>  Signed-off-by: Yao Cheng<saturdaycoder@gmail.com>
>> Cc: Shinya Kuribayashi<skuribay@pobox.com**>
>> ---
>>  arch/mips/cpu/mips32/cpu.c |    5 +++++
>>  1 files changed, 5 insertions(+), 0 deletions(-)
>>
>
>  diff --git a/arch/mips/cpu/mips32/cpu.c b/arch/mips/cpu/mips32/cpu.c
>> index 3ae397c..1bf0094 100644
>> --- a/arch/mips/cpu/mips32/cpu.c
>> +++ b/arch/mips/cpu/mips32/cpu.c
>> @@ -52,6 +52,11 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char
>> * const argv[])
>>
>>  void flush_cache(ulong start_addr, ulong size)
>>  {
>> +  /* aend will be miscalculated when size is zero, so we need return here
>> */
>> +  if (size == 0) {
>> +    return;
>> +  }
>>
> > +
>
>   Please indent with tabs, not spaces. Also, doesn't this code generate
> warning (code before declarations)?
>
>
>         unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
>>        unsigned long addr = start_addr&  ~(lsize - 1);
>>        unsigned long aend = (start_addr + size - 1)&  ~(lsize - 1);
>>
>
> WBR, Sergei
>

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

* [U-Boot] [PATCH] Fix wrong loop bound in flush_cache() when "size" is zero.
  2011-08-08 12:23 ` Sergei Shtylyov
  2011-08-08 13:55   ` Saturday Coder
@ 2011-08-08 20:04   ` Scott Wood
  1 sibling, 0 replies; 4+ messages in thread
From: Scott Wood @ 2011-08-08 20:04 UTC (permalink / raw)
  To: u-boot

On 08/08/2011 07:23 AM, Sergei Shtylyov wrote:
>     Please indent with tabs, not spaces. Also, doesn't this code generate 
> warning (code before declarations)?

Only with -Wdeclaration-after-statement, which U-boot doesn't set.

-Scott

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

end of thread, other threads:[~2011-08-08 20:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-08  8:07 [U-Boot] [PATCH] Fix wrong loop bound in flush_cache() when "size" is zero Yao Cheng
2011-08-08 12:23 ` Sergei Shtylyov
2011-08-08 13:55   ` Saturday Coder
2011-08-08 20:04   ` Scott Wood

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