Skip to contentSkip to conversation

ALSA: usb-audio: Use __le16 for 16bit USB descriptor fields

PATCH New Takashi Iwai 1 participant 2 messages Jun 5, 2023

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

PATCH 1/2 ALSA: usb-audio: Use __le16 for 16bit USB descriptor fields

Use proper notion for 16bit values for fixing the sparse warnings.

---
 include/linux/usb/midi-v2.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/usb/midi-v2.h +3 -3
index ebbffcae0417..16f09d959a2d 100644
@@ -73,7 +73,7 @@ struct usb_ms20_gr_trm_block_header_descriptor {
 	__u8  bLength;			/* 5 */
 	__u8  bDescriptorType;		/* USB_DT_CS_GR_TRM_BLOCK */
 	__u8  bDescriptorSubtype;	/* USB_MS_GR_TRM_BLOCK_HEADER */
-	__u16 wTotalLength;		/* Total number of bytes */
+	__le16 wTotalLength;		/* Total number of bytes */
 } __packed;
 
 /* 5.4.2.1 Group Terminal Block Descriptor */
@@ -87,8 +87,8 @@ struct usb_ms20_gr_trm_block_descriptor {
 	__u8  nNumGroupTrm;		/* Number of member Group Terminals spanned */
 	__u8  iBlockItem;		/* String ID of Block item */
 	__u8  bMIDIProtocol;		/* Default MIDI protocol */
-	__u16 wMaxInputBandwidth;	/* Max input bandwidth capability in 4kB/s */
-	__u16 wMaxOutputBandwidth;	/* Max output bandwidth capability in 4kB/s */
+	__le16 wMaxInputBandwidth;	/* Max input bandwidth capability in 4kB/s */
+	__le16 wMaxOutputBandwidth;	/* Max output bandwidth capability in 4kB/s */
 } __packed;
 
 #endif /* __LINUX_USB_MIDI_V2_H */
Signature · 1 line
2.35.3
#1 lore raw

PATCH 2/2 ALSA: seq: Avoid confusion of aligned read size

Currently the read event packet size in snd_seq_read() is defined by client->midi_version value that is guaranteed to be zero if UMP isn't enabled. But the static analyzer doesn't know of the fact, and it still suspects as if it were leading to a potential overflow.

Add the more explicit check of CONFIG_SND_SEQ_UMP to determine the aligned_size value for avoiding the confusion.

---
 sound/core/seq/seq_clientmgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/seq/seq_clientmgr.c +1 -1
index 948ae45e0cc3..e3f9ea67d019 100644
@@ -451,7 +451,7 @@ static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count,
 	err = 0;
 	snd_seq_fifo_lock(fifo);
 
-	if (client->midi_version > 0)
+	if (IS_ENABLED(CONFIG_SND_SEQ_UMP) && client->midi_version > 0)
 		aligned_size = sizeof(struct snd_seq_ump_event);
 	else
 		aligned_size = sizeof(struct snd_seq_event);
Signature · 1 line
2.35.3