Skip to contentSkip to conversation

ALSA: es1968: precedence bug in snd_es1968_tea575x_get_pins()

PATCH Applied Dan Carpenter 4 participants 5 messages Nov 13, 2012 – Nov 14, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
I don't have a way to test this.

sound/pci/es1968.c +8 -3
index 50169bc..7266020 100644
@@ -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)
Applied
#1 lore raw

At Tue, 13 Nov 2012 10:44:54 +0300,

Quoted 7 lines · Dan Carpenter

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.

Thanks, applied now.

Takashi

Quoted 26 lines

---
I don't have a way to test this.

sound/pci/es1968.c +8 -3
index 50169bc..7266020 100644
@@ -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)
#2 lore raw
In reply to Dan Carpenter
Quoted 4 lines · Dan Carpenter

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.

[]

sound/pci/es1968.c

Quoted 1 line
sound/pci/es1968.c +0 -0

[]

Quoted 5 lines
sound/pci/es1968.c +0 -1
@@ -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);
-

sound/pci/es1968.c static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea) · line 2591

Quoted 10 lines
sound/pci/es1968.c +8 -2
-	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);
#3 lore raw
Quoted 17 lines · Joe Perches
Quoted 4 lines · Dan Carpenter

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.

[]

sound/pci/es1968.c

Quoted 1 line
sound/pci/es1968.c +0 -0

[]

Quoted 9 lines
sound/pci/es1968.c +2 -3
@@ -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;
+
Quoted 8 lines

sound/pci/es1968.c static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea) · line 2591

Quoted 6 lines
sound/pci/es1968.c +6 -0
+	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.

Quoted 5 lines

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

#4 lore raw
In reply to Dan Carpenter
Quoted 8 lines · 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.

---
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.

Quoted 28 lines
sound/pci/es1968.c +8 -3
index 50169bc..7266020 100644
@@ -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/

Signature · 1 line
Ondrej Zary