diff mbox

[Qemu,devel] msf2: Remove dead code reported by Coverity

Message ID 1508176489-9002-1-git-send-email-sundeep.lkml@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

sundeep subbaraya Oct. 16, 2017, 5:54 p.m. UTC
Fixed incorrect frame size mask, validated maximum frame
size in spi_write and removed dead code.

Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
---
 hw/ssi/mss-spi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Peter Maydell Oct. 17, 2017, 3:28 p.m. UTC | #1
On 16 October 2017 at 18:54, Subbaraya Sundeep <sundeep.lkml@gmail.com> wrote:
> Fixed incorrect frame size mask, validated maximum frame
> size in spi_write and removed dead code.
>
> Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
> ---
>  hw/ssi/mss-spi.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/hw/ssi/mss-spi.c b/hw/ssi/mss-spi.c
> index 5a8e308..1e49cbc 100644
> --- a/hw/ssi/mss-spi.c
> +++ b/hw/ssi/mss-spi.c
> @@ -76,9 +76,10 @@
>  #define C_BIGFIFO            (1 << 29)
>  #define C_RESET              (1 << 31)
>
> -#define FRAMESZ_MASK         0x1F
> +#define FRAMESZ_MASK         0x3F
>  #define FMCOUNT_MASK         0x00FFFF00
>  #define FMCOUNT_SHIFT        8
> +#define FRAMESZ_MAX          32
>
>  static void txfifo_reset(MSSSpiState *s)
>  {
> @@ -106,8 +107,6 @@ static void set_fifodepth(MSSSpiState *s)
>          s->fifo_depth = 16;
>      } else if (size <= 32) {

Shouldn't this just be "} else {" now ?

>          s->fifo_depth = 8;
> -    } else {
> -        s->fifo_depth = 4;
>      }
>  }

thanks
-- PMM
sundeep subbaraya Oct. 18, 2017, 3:15 a.m. UTC | #2
Hi Peter,

On Tue, Oct 17, 2017 at 8:58 PM, Peter Maydell <peter.maydell@linaro.org>
wrote:

> On 16 October 2017 at 18:54, Subbaraya Sundeep <sundeep.lkml@gmail.com>
> wrote:
> > Fixed incorrect frame size mask, validated maximum frame
> > size in spi_write and removed dead code.
> >
> > Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
> > ---
> >  hw/ssi/mss-spi.c | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/hw/ssi/mss-spi.c b/hw/ssi/mss-spi.c
> > index 5a8e308..1e49cbc 100644
> > --- a/hw/ssi/mss-spi.c
> > +++ b/hw/ssi/mss-spi.c
> > @@ -76,9 +76,10 @@
> >  #define C_BIGFIFO            (1 << 29)
> >  #define C_RESET              (1 << 31)
> >
> > -#define FRAMESZ_MASK         0x1F
> > +#define FRAMESZ_MASK         0x3F
> >  #define FMCOUNT_MASK         0x00FFFF00
> >  #define FMCOUNT_SHIFT        8
> > +#define FRAMESZ_MAX          32
> >
> >  static void txfifo_reset(MSSSpiState *s)
> >  {
> > @@ -106,8 +107,6 @@ static void set_fifodepth(MSSSpiState *s)
> >          s->fifo_depth = 16;
> >      } else if (size <= 32) {
>
> Shouldn't this just be "} else {" now ?
>
> Yes. I will send v2.

Thanks,
Sundeep

>          s->fifo_depth = 8;
> > -    } else {
> > -        s->fifo_depth = 4;
> >      }
> >  }
>
> thanks
> -- PMM
>
sundeep subbaraya Oct. 18, 2017, 3:23 a.m. UTC | #3
Hi Peter,

On Wed, Oct 18, 2017 at 8:45 AM, sundeep subbaraya <sundeep.lkml@gmail.com>
wrote:

> Hi Peter,
>
> On Tue, Oct 17, 2017 at 8:58 PM, Peter Maydell <peter.maydell@linaro.org>
> wrote:
>
>> On 16 October 2017 at 18:54, Subbaraya Sundeep <sundeep.lkml@gmail.com>
>> wrote:
>> > Fixed incorrect frame size mask, validated maximum frame
>> > size in spi_write and removed dead code.
>> >
>> > Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
>> > ---
>> >  hw/ssi/mss-spi.c | 8 +++++---
>> >  1 file changed, 5 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/hw/ssi/mss-spi.c b/hw/ssi/mss-spi.c
>> > index 5a8e308..1e49cbc 100644
>> > --- a/hw/ssi/mss-spi.c
>> > +++ b/hw/ssi/mss-spi.c
>> > @@ -76,9 +76,10 @@
>> >  #define C_BIGFIFO            (1 << 29)
>> >  #define C_RESET              (1 << 31)
>> >
>> > -#define FRAMESZ_MASK         0x1F
>> > +#define FRAMESZ_MASK         0x3F
>> >  #define FMCOUNT_MASK         0x00FFFF00
>> >  #define FMCOUNT_SHIFT        8
>> > +#define FRAMESZ_MAX          32
>> >
>> >  static void txfifo_reset(MSSSpiState *s)
>> >  {
>> > @@ -106,8 +107,6 @@ static void set_fifodepth(MSSSpiState *s)
>> >          s->fifo_depth = 16;
>> >      } else if (size <= 32) {
>>
>> Shouldn't this just be "} else {" now ?
>>
>> Yes. I will send v2.
>

Also I will log guest error if frame size is greater than 32.

Thanks,
Sundeep


>
> Thanks,
> Sundeep
>
> >          s->fifo_depth = 8;
>> > -    } else {
>> > -        s->fifo_depth = 4;
>> >      }
>> >  }
>>
>> thanks
>> -- PMM
>>
>
>
diff mbox

Patch

diff --git a/hw/ssi/mss-spi.c b/hw/ssi/mss-spi.c
index 5a8e308..1e49cbc 100644
--- a/hw/ssi/mss-spi.c
+++ b/hw/ssi/mss-spi.c
@@ -76,9 +76,10 @@ 
 #define C_BIGFIFO            (1 << 29)
 #define C_RESET              (1 << 31)
 
-#define FRAMESZ_MASK         0x1F
+#define FRAMESZ_MASK         0x3F
 #define FMCOUNT_MASK         0x00FFFF00
 #define FMCOUNT_SHIFT        8
+#define FRAMESZ_MAX          32
 
 static void txfifo_reset(MSSSpiState *s)
 {
@@ -106,8 +107,6 @@  static void set_fifodepth(MSSSpiState *s)
         s->fifo_depth = 16;
     } else if (size <= 32) {
         s->fifo_depth = 8;
-    } else {
-        s->fifo_depth = 4;
     }
 }
 
@@ -301,6 +300,9 @@  static void spi_write(void *opaque, hwaddr addr,
         if (s->enabled) {
             break;
         }
+        if ((value & FRAMESZ_MASK) > FRAMESZ_MAX) {
+            break;
+        }
         s->regs[R_SPI_DFSIZE] = value;
         break;