Re: [PATCH 8/8] ALSA: add new 32-bit layout for snd_pcm_mmap_status/control

From: Arnd Bergmann
Date: Tue Apr 24 2018 - 09:27:39 EST


On Tue, Apr 24, 2018 at 2:06 PM, Baolin Wang <baolin.wang@xxxxxxxxxx> wrote:

> @@ -544,6 +543,8 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l
> case SNDRV_PCM_IOCTL_XRUN:
> case SNDRV_PCM_IOCTL_LINK:
> case SNDRV_PCM_IOCTL_UNLINK:
> + case __SNDRV_PCM_IOCTL_SYNC_PTR32:
> + case __SNDRV_PCM_IOCTL_SYNC_PTR64:
> return snd_pcm_common_ioctl(file, substream, cmd, argp);
> case SNDRV_PCM_IOCTL_HW_REFINE32:
> return snd_pcm_ioctl_hw_params_compat(substream, 1, argp);
> @@ -555,8 +556,6 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l
> return snd_pcm_status_user32(substream, argp, false);
> case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32:
> return snd_pcm_status_user32(substream, argp, true);
> - case SNDRV_PCM_IOCTL_SYNC_PTR32:
> - return snd_pcm_ioctl_sync_ptr_compat(substream, argp);
> case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
> return snd_pcm_ioctl_channel_info_compat(substream, argp);
> case SNDRV_PCM_IOCTL_WRITEI_FRAMES32:

I found a bug here while doing some more testing on my own patch:
__SNDRV_PCM_IOCTL_SYNC_PTR64 has the same value as
SNDRV_PCM_IOCTL_SYNC_PTR_X32, so we get a duplicate case
error when CONFIG_X86_X32 is enabled. We still need both handlers,
so the fix I came up with is:

diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
index 51a9447442f3..dbeeae50fb8d 100644
--- a/sound/core/pcm_compat.c
+++ b/sound/core/pcm_compat.c
@@ -543,8 +543,13 @@ static long snd_pcm_ioctl_compat(struct file
*file, unsigned int cmd, unsigned l
case SNDRV_PCM_IOCTL_XRUN:
case SNDRV_PCM_IOCTL_LINK:
case SNDRV_PCM_IOCTL_UNLINK:
- case __SNDRV_PCM_IOCTL_SYNC_PTR32:
case __SNDRV_PCM_IOCTL_SYNC_PTR64:
+#ifdef CONFIG_X86_X32
+ if (in_x32_syscall())
+ return snd_pcm_ioctl_sync_ptr_x32(substream, argp);
+ /* fallthru */
+#endif /* CONFIG_X86_X32 */
+ case __SNDRV_PCM_IOCTL_SYNC_PTR32:
return snd_pcm_common_ioctl(file, substream, cmd, argp);
case SNDRV_PCM_IOCTL_HW_REFINE32:
return snd_pcm_ioctl_hw_params_compat(substream, 1, argp);
@@ -577,8 +582,6 @@ static long snd_pcm_ioctl_compat(struct file
*file, unsigned int cmd, unsigned l
case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64:
return snd_pcm_status_user_compat64(substream, argp, true);
#ifdef CONFIG_X86_X32
- case SNDRV_PCM_IOCTL_SYNC_PTR_X32:
- return snd_pcm_ioctl_sync_ptr_x32(substream, argp);
case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32:
return snd_pcm_ioctl_channel_info_x32(substream, argp);
#endif /* CONFIG_X86_X32 */