All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: rawmidi: introduce SNDRV_RAWMIDI_IOCTL_USER_PVERSION
@ 2021-09-20  8:35 ` Jaroslav Kysela
  0 siblings, 0 replies; 4+ messages in thread
From: Jaroslav Kysela @ 2021-09-20  8:35 UTC (permalink / raw)
  To: ALSA development; +Cc: Takashi Iwai, David Henningsson, stable

The new framing mode causes the user space regression, because
the alsa-lib code does not initialize the reserved space in
the params structure when the device is opened.

This change adds SNDRV_RAWMIDI_IOCTL_USER_PVERSION like we
do for the PCM interface for the protocol acknowledgment.

Cc: David Henningsson <coding@diwic.se>
Cc: <stable@vger.kernel.org>
Fixes: 08fdced60ca0 ("ALSA: rawmidi: Add framing mode")
BugLink: https://github.com/alsa-project/alsa-lib/issues/178
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 include/sound/rawmidi.h     | 1 +
 include/uapi/sound/asound.h | 1 +
 sound/core/rawmidi.c        | 9 +++++++++
 3 files changed, 11 insertions(+)

diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
index 989e1517332d..7a08ed2acd60 100644
--- a/include/sound/rawmidi.h
+++ b/include/sound/rawmidi.h
@@ -98,6 +98,7 @@ struct snd_rawmidi_file {
 	struct snd_rawmidi *rmidi;
 	struct snd_rawmidi_substream *input;
 	struct snd_rawmidi_substream *output;
+	unsigned int user_pversion;	/* supported protocol version */
 };
 
 struct snd_rawmidi_str {
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index 1d84ec9db93b..f906e50a7919 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -784,6 +784,7 @@ struct snd_rawmidi_status {
 
 #define SNDRV_RAWMIDI_IOCTL_PVERSION	_IOR('W', 0x00, int)
 #define SNDRV_RAWMIDI_IOCTL_INFO	_IOR('W', 0x01, struct snd_rawmidi_info)
+#define SNDRV_RAWMIDI_IOCTL_USER_PVERSION _IOW('A', 0x02, int)
 #define SNDRV_RAWMIDI_IOCTL_PARAMS	_IOWR('W', 0x10, struct snd_rawmidi_params)
 #define SNDRV_RAWMIDI_IOCTL_STATUS	_IOWR('W', 0x20, struct snd_rawmidi_status)
 #define SNDRV_RAWMIDI_IOCTL_DROP	_IOW('W', 0x30, int)
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 6c0a4a67ad2e..6f30231bdb88 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -873,12 +873,21 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long
 			return -EINVAL;
 		}
 	}
+	case SNDRV_RAWMIDI_IOCTL_USER_PVERSION:
+		if (get_user(rfile->user_pversion, (unsigned int __user *)arg))
+			return -EFAULT;
+		return 0;
+
 	case SNDRV_RAWMIDI_IOCTL_PARAMS:
 	{
 		struct snd_rawmidi_params params;
 
 		if (copy_from_user(&params, argp, sizeof(struct snd_rawmidi_params)))
 			return -EFAULT;
+		if (rfile->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 2)) {
+			params.mode = 0;
+			memset(params.reserved, 0, sizeof(params.reserved));
+		}
 		switch (params.stream) {
 		case SNDRV_RAWMIDI_STREAM_OUTPUT:
 			if (rfile->output == NULL)
-- 
2.31.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ALSA: rawmidi: introduce SNDRV_RAWMIDI_IOCTL_USER_PVERSION
@ 2021-09-20  8:35 ` Jaroslav Kysela
  0 siblings, 0 replies; 4+ messages in thread
From: Jaroslav Kysela @ 2021-09-20  8:35 UTC (permalink / raw)
  To: ALSA development; +Cc: Takashi Iwai, Jaroslav Kysela, David Henningsson, stable

The new framing mode causes the user space regression, because
the alsa-lib code does not initialize the reserved space in
the params structure when the device is opened.

This change adds SNDRV_RAWMIDI_IOCTL_USER_PVERSION like we
do for the PCM interface for the protocol acknowledgment.

Cc: David Henningsson <coding@diwic.se>
Cc: <stable@vger.kernel.org>
Fixes: 08fdced60ca0 ("ALSA: rawmidi: Add framing mode")
BugLink: https://github.com/alsa-project/alsa-lib/issues/178
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 include/sound/rawmidi.h     | 1 +
 include/uapi/sound/asound.h | 1 +
 sound/core/rawmidi.c        | 9 +++++++++
 3 files changed, 11 insertions(+)

diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
index 989e1517332d..7a08ed2acd60 100644
--- a/include/sound/rawmidi.h
+++ b/include/sound/rawmidi.h
@@ -98,6 +98,7 @@ struct snd_rawmidi_file {
 	struct snd_rawmidi *rmidi;
 	struct snd_rawmidi_substream *input;
 	struct snd_rawmidi_substream *output;
+	unsigned int user_pversion;	/* supported protocol version */
 };
 
 struct snd_rawmidi_str {
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index 1d84ec9db93b..f906e50a7919 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -784,6 +784,7 @@ struct snd_rawmidi_status {
 
 #define SNDRV_RAWMIDI_IOCTL_PVERSION	_IOR('W', 0x00, int)
 #define SNDRV_RAWMIDI_IOCTL_INFO	_IOR('W', 0x01, struct snd_rawmidi_info)
+#define SNDRV_RAWMIDI_IOCTL_USER_PVERSION _IOW('A', 0x02, int)
 #define SNDRV_RAWMIDI_IOCTL_PARAMS	_IOWR('W', 0x10, struct snd_rawmidi_params)
 #define SNDRV_RAWMIDI_IOCTL_STATUS	_IOWR('W', 0x20, struct snd_rawmidi_status)
 #define SNDRV_RAWMIDI_IOCTL_DROP	_IOW('W', 0x30, int)
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 6c0a4a67ad2e..6f30231bdb88 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -873,12 +873,21 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long
 			return -EINVAL;
 		}
 	}
+	case SNDRV_RAWMIDI_IOCTL_USER_PVERSION:
+		if (get_user(rfile->user_pversion, (unsigned int __user *)arg))
+			return -EFAULT;
+		return 0;
+
 	case SNDRV_RAWMIDI_IOCTL_PARAMS:
 	{
 		struct snd_rawmidi_params params;
 
 		if (copy_from_user(&params, argp, sizeof(struct snd_rawmidi_params)))
 			return -EFAULT;
+		if (rfile->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 2)) {
+			params.mode = 0;
+			memset(params.reserved, 0, sizeof(params.reserved));
+		}
 		switch (params.stream) {
 		case SNDRV_RAWMIDI_STREAM_OUTPUT:
 			if (rfile->output == NULL)
-- 
2.31.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: rawmidi: introduce SNDRV_RAWMIDI_IOCTL_USER_PVERSION
  2021-09-20  8:35 ` Jaroslav Kysela
  (?)
@ 2021-09-20 16:42 ` David Henningsson
  2021-09-20 17:22   ` Jaroslav Kysela
  -1 siblings, 1 reply; 4+ messages in thread
From: David Henningsson @ 2021-09-20 16:42 UTC (permalink / raw)
  To: Jaroslav Kysela, ALSA development; +Cc: Takashi Iwai, stable


On 2021-09-20 10:35, Jaroslav Kysela wrote:
> The new framing mode causes the user space regression, because
> the alsa-lib code does not initialize the reserved space in
> the params structure when the device is opened.
>
> This change adds SNDRV_RAWMIDI_IOCTL_USER_PVERSION like we
> do for the PCM interface for the protocol acknowledgment.
>
> Cc: David Henningsson <coding@diwic.se>
> Cc: <stable@vger.kernel.org>
> Fixes: 08fdced60ca0 ("ALSA: rawmidi: Add framing mode")
> BugLink: https://github.com/alsa-project/alsa-lib/issues/178
> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
> ---
>   include/sound/rawmidi.h     | 1 +
>   include/uapi/sound/asound.h | 1 +
>   sound/core/rawmidi.c        | 9 +++++++++
>   3 files changed, 11 insertions(+)
>
> diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
> index 989e1517332d..7a08ed2acd60 100644
> --- a/include/sound/rawmidi.h
> +++ b/include/sound/rawmidi.h
> @@ -98,6 +98,7 @@ struct snd_rawmidi_file {
>   	struct snd_rawmidi *rmidi;
>   	struct snd_rawmidi_substream *input;
>   	struct snd_rawmidi_substream *output;
> +	unsigned int user_pversion;	/* supported protocol version */
>   };
>   
>   struct snd_rawmidi_str {
> diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
> index 1d84ec9db93b..f906e50a7919 100644
> --- a/include/uapi/sound/asound.h
> +++ b/include/uapi/sound/asound.h
> @@ -784,6 +784,7 @@ struct snd_rawmidi_status {
>   
>   #define SNDRV_RAWMIDI_IOCTL_PVERSION	_IOR('W', 0x00, int)
>   #define SNDRV_RAWMIDI_IOCTL_INFO	_IOR('W', 0x01, struct snd_rawmidi_info)
> +#define SNDRV_RAWMIDI_IOCTL_USER_PVERSION _IOW('A', 0x02, int)

How come it's not 'W' here but 'A' instead?

Looks good otherwise, given a quick glance. It'll need a corresponding 
alsa-lib patch to actually call SNDRV_RAWMIDI_IOCTL_USER_PVERSION.

Thanks for helping to sort this out.

// David


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: rawmidi: introduce SNDRV_RAWMIDI_IOCTL_USER_PVERSION
  2021-09-20 16:42 ` David Henningsson
@ 2021-09-20 17:22   ` Jaroslav Kysela
  0 siblings, 0 replies; 4+ messages in thread
From: Jaroslav Kysela @ 2021-09-20 17:22 UTC (permalink / raw)
  To: David Henningsson, ALSA development; +Cc: Takashi Iwai, stable

On 20. 09. 21 18:42, David Henningsson wrote:
> 
> On 2021-09-20 10:35, Jaroslav Kysela wrote:
>> The new framing mode causes the user space regression, because
>> the alsa-lib code does not initialize the reserved space in
>> the params structure when the device is opened.
>>
>> This change adds SNDRV_RAWMIDI_IOCTL_USER_PVERSION like we
>> do for the PCM interface for the protocol acknowledgment.
>>
>> Cc: David Henningsson <coding@diwic.se>
>> Cc: <stable@vger.kernel.org>
>> Fixes: 08fdced60ca0 ("ALSA: rawmidi: Add framing mode")
>> BugLink: https://github.com/alsa-project/alsa-lib/issues/178
>> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
>> ---
>>   include/sound/rawmidi.h     | 1 +
>>   include/uapi/sound/asound.h | 1 +
>>   sound/core/rawmidi.c        | 9 +++++++++
>>   3 files changed, 11 insertions(+)
>>
>> diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
>> index 989e1517332d..7a08ed2acd60 100644
>> --- a/include/sound/rawmidi.h
>> +++ b/include/sound/rawmidi.h
>> @@ -98,6 +98,7 @@ struct snd_rawmidi_file {
>>   	struct snd_rawmidi *rmidi;
>>   	struct snd_rawmidi_substream *input;
>>   	struct snd_rawmidi_substream *output;
>> +	unsigned int user_pversion;	/* supported protocol version */
>>   };
>>   
>>   struct snd_rawmidi_str {
>> diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
>> index 1d84ec9db93b..f906e50a7919 100644
>> --- a/include/uapi/sound/asound.h
>> +++ b/include/uapi/sound/asound.h
>> @@ -784,6 +784,7 @@ struct snd_rawmidi_status {
>>   
>>   #define SNDRV_RAWMIDI_IOCTL_PVERSION	_IOR('W', 0x00, int)
>>   #define SNDRV_RAWMIDI_IOCTL_INFO	_IOR('W', 0x01, struct snd_rawmidi_info)
>> +#define SNDRV_RAWMIDI_IOCTL_USER_PVERSION _IOW('A', 0x02, int)
> 
> How come it's not 'W' here but 'A' instead?

Good catch. I sent v2 of this patch with this correction. Thank you.

https://lore.kernel.org/alsa-devel/20210920171850.154186-1-perex@perex.cz/

					Jaroslav

> 
> Looks good otherwise, given a quick glance. It'll need a corresponding 
> alsa-lib patch to actually call SNDRV_RAWMIDI_IOCTL_USER_PVERSION.
> 
> Thanks for helping to sort this out.
> 
> // David
> 


-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-20 22:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20  8:35 [PATCH] ALSA: rawmidi: introduce SNDRV_RAWMIDI_IOCTL_USER_PVERSION Jaroslav Kysela
2021-09-20  8:35 ` Jaroslav Kysela
2021-09-20 16:42 ` David Henningsson
2021-09-20 17:22   ` Jaroslav Kysela

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.