Skip to contentSkip to conversation

ASoC: ops: Check bounds for second channel in snd_soc_put_volsw_sx()

PATCH New Sasha Levin 1 participant 4 messages Jun 29, 2023

Subsystems (4)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

PATCH 1/4 ASoC: ops: Check bounds for second channel in snd_soc_put_volsw_sx()

From: Mark Brown <[email protected]>

[ Upstream commit 97eea946b93961fffd29448dcda7398d0d51c4b2 ]

The bounds checks in snd_soc_put_volsw_sx() are only being applied to the first channel, meaning it is possible to write out of bounds values to the second channel in stereo controls. Add appropriate checks.

---
 sound/soc/soc-ops.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/soc/soc-ops.c +6 -0
index 81c9ecfa7c7f9..63c0e61b17541 100644
@@ -465,6 +465,12 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
 	if (snd_soc_volsw_is_stereo(mc)) {
 		val_mask = mask << rshift;
 		val2 = (ucontrol->value.integer.value[1] + min) & mask;
+
+		if (mc->platform_max && val2 > mc->platform_max)
+			return -EINVAL;
+		if (val2 > max)
+			return -EINVAL;
+
 		val2 = val2 << rshift;
 
 		err = snd_soc_component_update_bits(component, reg2, val_mask,
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 2/4 can: sja1000: fix size of OCR_MODE_MASK define

From: Heiko Schocher <[email protected]>

[ Upstream commit 26e8f6a75248247982458e8237b98c9fb2ffcf9d ]

bitfield mode in ocr register has only 2 bits not 3, so correct the OCR_MODE_MASK define.

---
 include/linux/can/platform/sja1000.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/can/platform/sja1000.h +1 -1
index 5755ae5a47122..6a869682c1207 100644
@@ -14,7 +14,7 @@
 #define OCR_MODE_TEST     0x01
 #define OCR_MODE_NORMAL   0x02
 #define OCR_MODE_CLOCK    0x03
-#define OCR_MODE_MASK     0x07
+#define OCR_MODE_MASK     0x03
 #define OCR_TX0_INVERT    0x04
 #define OCR_TX0_PULLDOWN  0x08
 #define OCR_TX0_PULLUP    0x10
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH 3/4 can: mcba_usb: Fix termination command argument

In reply to Sasha Levin

From: Yasushi SHOJI <[email protected]>

[ Upstream commit 1a8e3bd25f1e789c8154e11ea24dc3ec5a4c1da0 ]

Microchip USB Analyzer can activate the internal termination resistors by setting the "termination" option ON, or OFF to to deactivate them. As I've observed, both with my oscilloscope and captured USB packets below, you must send "0" to turn it ON, and "1" to turn it OFF.

From the schematics in the user's guide, I can confirm that you must drive the CAN_RES signal LOW "0" to activate the resistors.

Reverse the argument value of usb_msg.termination to fix this.

These are the two commands sequence, ON then OFF.

Quoted 7 lines
No.     Time           Source                Destination           Protocol Length Info
      1 0.000000       host                  1.3.1                 USB      46     URB_BULK out

Frame 1: 46 bytes on wire (368 bits), 46 bytes captured (368 bits) USB URB
Leftover Capture Data: a80000000000000000000000000000000000a8

Quoted 6 lines
No.     Time           Source                Destination           Protocol Length Info
      2 4.372547       host                  1.3.1                 USB      46     URB_BULK out

Frame 2: 46 bytes on wire (368 bits), 46 bytes captured (368 bits) USB URB
Leftover Capture Data: a80100000000000000000000000000000000a9

---
 drivers/net/can/usb/mcba_usb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/can/usb/mcba_usb.c +7 -3
index f7c3fc3dabfe4..01ef5cabdc11e 100644
@@ -58,6 +58,10 @@
 #define MCBA_VER_REQ_USB 1
 #define MCBA_VER_REQ_CAN 2
 
+/* Drive the CAN_RES signal LOW "0" to activate R24 and R25 */
+#define MCBA_VER_TERMINATION_ON 0
+#define MCBA_VER_TERMINATION_OFF 1
+
 #define MCBA_SIDL_EXID_MASK 0x8
 #define MCBA_DLC_MASK 0xf
 #define MCBA_DLC_RTR_MASK 0x40
@@ -480,7 +484,7 @@ static void mcba_usb_process_ka_usb(struct mcba_priv *priv,
 		priv->usb_ka_first_pass = false;
 	}
 
-	if (msg->termination_state)
+	if (msg->termination_state == MCBA_VER_TERMINATION_ON)
 		priv->can.termination = MCBA_TERMINATION_ENABLED;
 	else
 		priv->can.termination = MCBA_TERMINATION_DISABLED;
@@ -800,9 +804,9 @@ static int mcba_set_termination(struct net_device *netdev, u16 term)
 	};
 
 	if (term == MCBA_TERMINATION_ENABLED)
-		usb_msg.termination = 1;
+		usb_msg.termination = MCBA_VER_TERMINATION_ON;
 	else
-		usb_msg.termination = 0;
+		usb_msg.termination = MCBA_VER_TERMINATION_OFF;
 
 	mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
 
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH 4/4 net: loopback: use NET_NAME_PREDICTABLE for name_assign_type

In reply to Sasha Levin

From: Rasmus Villemoes <[email protected]>

[ Upstream commit 31d929de5a112ee1b977a89c57de74710894bbbf ]

When the name_assign_type attribute was introduced (commit 685343fc3ba6, "net: add name_assign_type netdev attribute"), the loopback device was explicitly mentioned as one which would make use of NET_NAME_PREDICTABLE:

The name_assign_type attribute gives hints where the interface name of a given net-device comes from. These values are currently defined:
...
NET_NAME_PREDICTABLE:
The ifname has been assigned by the kernel in a predictable way that is guaranteed to avoid reuse and always be the same for a given device. Examples include statically created devices like the loopback device [...]

Switch to that so that reading /sys/class/net/lo/name_assign_type produces something sensible instead of returning -EINVAL.

---
 drivers/net/loopback.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/loopback.c +1 -1
index 30612497643c0..daef41ce23492 100644
@@ -206,7 +206,7 @@ static __net_init int loopback_net_init(struct net *net)
 	int err;
 
 	err = -ENOMEM;
-	dev = alloc_netdev(0, "lo", NET_NAME_UNKNOWN, loopback_setup);
+	dev = alloc_netdev(0, "lo", NET_NAME_PREDICTABLE, loopback_setup);
 	if (!dev)
 		goto out;
 
Signature · 1 line
2.39.2