2012-11-13 07:46:32

by Dan Carpenter

[permalink] [raw]
Subject: [patch] ALSA: es1968: precedence bug in snd_es1968_tea575x_get_pins()

I don't think this works as intended. '|' higher precedence than ?: so
the bitwize OR "0 | (val & STR_MOST)" is a no-op.

I have re-written it to be more clear.

Signed-off-by: Dan Carpenter <[email protected]>
---
I don't have a way to test this.

diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 50169bc..7266020 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -2581,9 +2581,14 @@ static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea)
struct es1968 *chip = tea->private_data;
unsigned long io = chip->io_port + GPIO_DATA;
u16 val = inw(io);
-
- return (val & STR_DATA) ? TEA575X_DATA : 0 |
- (val & STR_MOST) ? TEA575X_MOST : 0;
+ u8 ret;
+
+ ret = 0;
+ if (val & STR_DATA)
+ ret |= TEA575X_DATA;
+ if (val & STR_MOST)
+ ret |= TEA575X_MOST;
+ return ret;
}

static void snd_es1968_tea575x_set_direction(struct snd_tea575x *tea, bool output)


2012-11-13 07:53:05

by Takashi Iwai

[permalink] [raw]
Subject: Re: [patch] ALSA: es1968: precedence bug in snd_es1968_tea575x_get_pins()

At Tue, 13 Nov 2012 10:44:54 +0300,
Dan Carpenter wrote:
>
> I don't think this works as intended. '|' higher precedence than ?: so
> the bitwize OR "0 | (val & STR_MOST)" is a no-op.
>
> I have re-written it to be more clear.
>
> Signed-off-by: Dan Carpenter <[email protected]>

Thanks, applied now.


Takashi

> ---
> I don't have a way to test this.
>
> diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
> index 50169bc..7266020 100644
> --- a/sound/pci/es1968.c
> +++ b/sound/pci/es1968.c
> @@ -2581,9 +2581,14 @@ static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea)
> struct es1968 *chip = tea->private_data;
> unsigned long io = chip->io_port + GPIO_DATA;
> u16 val = inw(io);
> -
> - return (val & STR_DATA) ? TEA575X_DATA : 0 |
> - (val & STR_MOST) ? TEA575X_MOST : 0;
> + u8 ret;
> +
> + ret = 0;
> + if (val & STR_DATA)
> + ret |= TEA575X_DATA;
> + if (val & STR_MOST)
> + ret |= TEA575X_MOST;
> + return ret;
> }
>
> static void snd_es1968_tea575x_set_direction(struct snd_tea575x *tea, bool output)
>

2012-11-13 08:03:10

by Joe Perches

[permalink] [raw]
Subject: Re: [patch] ALSA: es1968: precedence bug in snd_es1968_tea575x_get_pins()

On Tue, 2012-11-13 at 10:44 +0300, Dan Carpenter wrote:
> I don't think this works as intended. '|' higher precedence than ?: so
> the bitwize OR "0 | (val & STR_MOST)" is a no-op.
>
> I have re-written it to be more clear.
[]
> diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
[]
> @@ -2581,9 +2581,14 @@ static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea)
> struct es1968 *chip = tea->private_data;
> unsigned long io = chip->io_port + GPIO_DATA;
> u16 val = inw(io);
> -
> - return (val & STR_DATA) ? TEA575X_DATA : 0 |
> - (val & STR_MOST) ? TEA575X_MOST : 0;
> + u8 ret;
> +
> + ret = 0;
> + if (val & STR_DATA)
> + ret |= TEA575X_DATA;
> + if (val & STR_MOST)
> + ret |= TEA575X_MOST;
> + return ret;

Cute. smatch I presume? Tools are useful.

Moving the close parentheses is a pretty common style too

return (val & STR_DATA ? TEA575X_DATA : 0) |
(val & STR_MOST ? TEA575X_MOST : 0);

2012-11-14 08:29:18

by Dan Carpenter

[permalink] [raw]
Subject: Re: [patch] ALSA: es1968: precedence bug in snd_es1968_tea575x_get_pins()

On Tue, Nov 13, 2012 at 12:03:10AM -0800, Joe Perches wrote:
> On Tue, 2012-11-13 at 10:44 +0300, Dan Carpenter wrote:
> > I don't think this works as intended. '|' higher precedence than ?: so
> > the bitwize OR "0 | (val & STR_MOST)" is a no-op.
> >
> > I have re-written it to be more clear.
> []
> > diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
> []
> > @@ -2581,9 +2581,14 @@ static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea)
> > struct es1968 *chip = tea->private_data;
> > unsigned long io = chip->io_port + GPIO_DATA;
> > u16 val = inw(io);
> > -
> > - return (val & STR_DATA) ? TEA575X_DATA : 0 |
> > - (val & STR_MOST) ? TEA575X_MOST : 0;
> > + u8 ret;
> > +
> > + ret = 0;
> > + if (val & STR_DATA)
> > + ret |= TEA575X_DATA;
> > + if (val & STR_MOST)
> > + ret |= TEA575X_MOST;
> > + return ret;
>
> Cute. smatch I presume? Tools are useful.

Yep. This is a smatch thing.

>
> Moving the close parentheses is a pretty common style too
>
> return (val & STR_DATA ? TEA575X_DATA : 0) |
> (val & STR_MOST ? TEA575X_MOST : 0);

That would work as well, of course. I don't have a strong
preference either way.

regards,
dan carpenter

2012-11-14 21:25:47

by Ondrej Zary

[permalink] [raw]
Subject: Re: [patch] ALSA: es1968: precedence bug in snd_es1968_tea575x_get_pins()

On Tuesday 13 November 2012 08:44:54 Dan Carpenter wrote:
> I don't think this works as intended. '|' higher precedence than ?: so
> the bitwize OR "0 | (val & STR_MOST)" is a no-op.
>
> I have re-written it to be more clear.
>
> Signed-off-by: Dan Carpenter <[email protected]>
> ---
> I don't have a way to test this.

Thanks for the patch. I tested it and it works.

The same way as without the patch...weird. DATA pin reading works because
that's required for the chip detection. Stereo indication (MOST pin) works
too.

>
> diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
> index 50169bc..7266020 100644
> --- a/sound/pci/es1968.c
> +++ b/sound/pci/es1968.c
> @@ -2581,9 +2581,14 @@ static u8 snd_es1968_tea575x_get_pins(struct
> snd_tea575x *tea) struct es1968 *chip = tea->private_data;
> unsigned long io = chip->io_port + GPIO_DATA;
> u16 val = inw(io);
> -
> - return (val & STR_DATA) ? TEA575X_DATA : 0 |
> - (val & STR_MOST) ? TEA575X_MOST : 0;
> + u8 ret;
> +
> + ret = 0;
> + if (val & STR_DATA)
> + ret |= TEA575X_DATA;
> + if (val & STR_MOST)
> + ret |= TEA575X_MOST;
> + return ret;
> }
>
> static void snd_es1968_tea575x_set_direction(struct snd_tea575x *tea, bool
> output) --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/


--
Ondrej Zary