2009-12-15 22:04:31

by Roel Kluin

[permalink] [raw]
Subject: [PATCH] sound/oss/pss: Fix test of unsigned in pss_reset_dsp() and pss_download_boot()

limit and jiffies are unsigned so the test does not work.

Signed-off-by: Roel Kluin <[email protected]>
---
Found using coccinelle: http://coccinelle.lip6.fr/

diff --git a/sound/oss/pss.c b/sound/oss/pss.c
index 83f5ee2..9325f4d 100644
--- a/sound/oss/pss.c
+++ b/sound/oss/pss.c
@@ -269,7 +269,7 @@ static int pss_reset_dsp(pss_confdata * devc)
unsigned long i, limit = jiffies + HZ/10;

outw(0x2000, REG(PSS_CONTROL));
- for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
+ for (i = 0; i < 32768 && (limit >= jiffies); i++)
inw(REG(PSS_CONTROL));
outw(0x0000, REG(PSS_CONTROL));
return 1;
@@ -369,11 +369,11 @@ static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size
outw(0, REG(PSS_DATA));

limit = jiffies + HZ/10;
- for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
+ for (i = 0; i < 32768 && (limit >= jiffies); i++)
val = inw(REG(PSS_STATUS));

limit = jiffies + HZ/10;
- for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
+ for (i = 0; i < 32768 && (limit >= jiffies); i++)
{
val = inw(REG(PSS_STATUS));
if (val & 0x4000)


2009-12-16 12:00:41

by Takashi Iwai

[permalink] [raw]
Subject: Re: [PATCH] sound/oss/pss: Fix test of unsigned in pss_reset_dsp() and pss_download_boot()

At Tue, 15 Dec 2009 23:06:18 +0100,
Roel Kluin wrote:
>
> limit and jiffies are unsigned so the test does not work.
>
> Signed-off-by: Roel Kluin <[email protected]>
> ---
> Found using coccinelle: http://coccinelle.lip6.fr/
>
> diff --git a/sound/oss/pss.c b/sound/oss/pss.c
> index 83f5ee2..9325f4d 100644
> --- a/sound/oss/pss.c
> +++ b/sound/oss/pss.c
> @@ -269,7 +269,7 @@ static int pss_reset_dsp(pss_confdata * devc)
> unsigned long i, limit = jiffies + HZ/10;
>
> outw(0x2000, REG(PSS_CONTROL));
> - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
> + for (i = 0; i < 32768 && (limit >= jiffies); i++)

No, it should use time_after_eq(limit, jiffies) instead.


thanks,

Takashi

2009-12-16 15:52:54

by Roel Kluin

[permalink] [raw]
Subject: Re: [PATCH] sound/oss/pss: Fix test of unsigned in pss_reset_dsp() and pss_download_boot()

limit and jiffies are unsigned so the test did not work.

Signed-off-by: Roel Kluin <[email protected]>
---
Found using coccinelle: http://coccinelle.lip6.fr/

>> - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
>> + for (i = 0; i < 32768 && (limit >= jiffies); i++)
>
> No, it should use time_after_eq(limit, jiffies) instead.
>
>
> thanks,
>
> Takashi
>

Ok,

diff --git a/sound/oss/pss.c b/sound/oss/pss.c
index 83f5ee2..e19dd5d 100644
--- a/sound/oss/pss.c
+++ b/sound/oss/pss.c
@@ -269,7 +269,7 @@ static int pss_reset_dsp(pss_confdata * devc)
unsigned long i, limit = jiffies + HZ/10;

outw(0x2000, REG(PSS_CONTROL));
- for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
+ for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
inw(REG(PSS_CONTROL));
outw(0x0000, REG(PSS_CONTROL));
return 1;
@@ -369,11 +369,11 @@ static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size
outw(0, REG(PSS_DATA));

limit = jiffies + HZ/10;
- for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
+ for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
val = inw(REG(PSS_STATUS));

limit = jiffies + HZ/10;
- for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
+ for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
{
val = inw(REG(PSS_STATUS));
if (val & 0x4000)

2009-12-17 00:23:40

by Troy Kisky

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH] sound/oss/pss: Fix test of unsigned in pss_reset_dsp() and pss_download_boot()

Roel Kluin wrote:
> limit and jiffies are unsigned so the test does not work.
>
> Signed-off-by: Roel Kluin <[email protected]>
> ---
> Found using coccinelle: http://coccinelle.lip6.fr/
>
> diff --git a/sound/oss/pss.c b/sound/oss/pss.c
> index 83f5ee2..9325f4d 100644
> --- a/sound/oss/pss.c
> +++ b/sound/oss/pss.c
> @@ -269,7 +269,7 @@ static int pss_reset_dsp(pss_confdata * devc)
> unsigned long i, limit = jiffies + HZ/10;
>
> outw(0x2000, REG(PSS_CONTROL));
> - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)

I think
for (i = 0; i < 32768 && ( (int)(limit-jiffies) >= 0); i++)

works better when jiffies wrap

> + for (i = 0; i < 32768 && (limit >= jiffies); i++)
> inw(REG(PSS_CONTROL));
> outw(0x0000, REG(PSS_CONTROL));
> return 1;
> @@ -369,11 +369,11 @@ static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size
> outw(0, REG(PSS_DATA));
>
> limit = jiffies + HZ/10;
> - for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
> + for (i = 0; i < 32768 && (limit >= jiffies); i++)
> val = inw(REG(PSS_STATUS));
>
> limit = jiffies + HZ/10;
> - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
> + for (i = 0; i < 32768 && (limit >= jiffies); i++)
> {
> val = inw(REG(PSS_STATUS));
> if (val & 0x4000)
> _______________________________________________
> Alsa-devel mailing list
> [email protected]
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>

2009-12-17 06:47:42

by Takashi Iwai

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH] sound/oss/pss: Fix test of unsigned in pss_reset_dsp() and pss_download_boot()

At Wed, 16 Dec 2009 17:23:03 -0700,
Troy Kisky wrote:
>
> Roel Kluin wrote:
> > limit and jiffies are unsigned so the test does not work.
> >
> > Signed-off-by: Roel Kluin <[email protected]>
> > ---
> > Found using coccinelle: http://coccinelle.lip6.fr/
> >
> > diff --git a/sound/oss/pss.c b/sound/oss/pss.c
> > index 83f5ee2..9325f4d 100644
> > --- a/sound/oss/pss.c
> > +++ b/sound/oss/pss.c
> > @@ -269,7 +269,7 @@ static int pss_reset_dsp(pss_confdata * devc)
> > unsigned long i, limit = jiffies + HZ/10;
> >
> > outw(0x2000, REG(PSS_CONTROL));
> > - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
>
> I think
> for (i = 0; i < 32768 && ( (int)(limit-jiffies) >= 0); i++)
>
> works better when jiffies wrap

Yes, and time_after_eq() takes care of it nicely :)


Takashi

2009-12-17 11:36:26

by Takashi Iwai

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH] sound/oss/pss: Fix test of unsigned in pss_reset_dsp() and pss_download_boot()

At Wed, 16 Dec 2009 16:54:43 +0100,
Roel Kluin wrote:
>
> limit and jiffies are unsigned so the test did not work.
>
> Signed-off-by: Roel Kluin <[email protected]>
> ---
> Found using coccinelle: http://coccinelle.lip6.fr/
>
> >> - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
> >> + for (i = 0; i < 32768 && (limit >= jiffies); i++)
> >
> > No, it should use time_after_eq(limit, jiffies) instead.
> >
> >
> > thanks,
> >
> > Takashi
> >
>
> Ok,

Applied now. Thanks.


Takashi

>
> diff --git a/sound/oss/pss.c b/sound/oss/pss.c
> index 83f5ee2..e19dd5d 100644
> --- a/sound/oss/pss.c
> +++ b/sound/oss/pss.c
> @@ -269,7 +269,7 @@ static int pss_reset_dsp(pss_confdata * devc)
> unsigned long i, limit = jiffies + HZ/10;
>
> outw(0x2000, REG(PSS_CONTROL));
> - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
> + for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
> inw(REG(PSS_CONTROL));
> outw(0x0000, REG(PSS_CONTROL));
> return 1;
> @@ -369,11 +369,11 @@ static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size
> outw(0, REG(PSS_DATA));
>
> limit = jiffies + HZ/10;
> - for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
> + for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
> val = inw(REG(PSS_STATUS));
>
> limit = jiffies + HZ/10;
> - for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
> + for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
> {
> val = inw(REG(PSS_STATUS));
> if (val & 0x4000)
> _______________________________________________
> Alsa-devel mailing list
> [email protected]
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>