Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *   32bit -> 64bit ioctl wrapper for PCM API
0004  *   Copyright (c) by Takashi Iwai <tiwai@suse.de>
0005  */
0006 
0007 /* This file included from pcm_native.c */
0008 
0009 #include <linux/compat.h>
0010 #include <linux/slab.h>
0011 
0012 static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
0013                       s32 __user *src)
0014 {
0015     snd_pcm_sframes_t delay;
0016     int err;
0017 
0018     err = snd_pcm_delay(substream, &delay);
0019     if (err)
0020         return err;
0021     if (put_user(delay, src))
0022         return -EFAULT;
0023     return 0;
0024 }
0025 
0026 static int snd_pcm_ioctl_rewind_compat(struct snd_pcm_substream *substream,
0027                        u32 __user *src)
0028 {
0029     snd_pcm_uframes_t frames;
0030     int err;
0031 
0032     if (get_user(frames, src))
0033         return -EFAULT;
0034     err = snd_pcm_rewind(substream, frames);
0035     if (put_user(err, src))
0036         return -EFAULT;
0037     return err < 0 ? err : 0;
0038 }
0039 
0040 static int snd_pcm_ioctl_forward_compat(struct snd_pcm_substream *substream,
0041                        u32 __user *src)
0042 {
0043     snd_pcm_uframes_t frames;
0044     int err;
0045 
0046     if (get_user(frames, src))
0047         return -EFAULT;
0048     err = snd_pcm_forward(substream, frames);
0049     if (put_user(err, src))
0050         return -EFAULT;
0051     return err < 0 ? err : 0;
0052 }
0053 
0054 struct snd_pcm_hw_params32 {
0055     u32 flags;
0056     struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - SNDRV_PCM_HW_PARAM_FIRST_MASK + 1]; /* this must be identical */
0057     struct snd_mask mres[5];    /* reserved masks */
0058     struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
0059     struct snd_interval ires[9];    /* reserved intervals */
0060     u32 rmask;
0061     u32 cmask;
0062     u32 info;
0063     u32 msbits;
0064     u32 rate_num;
0065     u32 rate_den;
0066     u32 fifo_size;
0067     unsigned char reserved[64];
0068 };
0069 
0070 struct snd_pcm_sw_params32 {
0071     s32 tstamp_mode;
0072     u32 period_step;
0073     u32 sleep_min;
0074     u32 avail_min;
0075     u32 xfer_align;
0076     u32 start_threshold;
0077     u32 stop_threshold;
0078     u32 silence_threshold;
0079     u32 silence_size;
0080     u32 boundary;
0081     u32 proto;
0082     u32 tstamp_type;
0083     unsigned char reserved[56];
0084 };
0085 
0086 static int snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream *substream,
0087                       struct snd_pcm_sw_params32 __user *src)
0088 {
0089     struct snd_pcm_sw_params params;
0090     snd_pcm_uframes_t boundary;
0091     int err;
0092 
0093     memset(&params, 0, sizeof(params));
0094     if (get_user(params.tstamp_mode, &src->tstamp_mode) ||
0095         get_user(params.period_step, &src->period_step) ||
0096         get_user(params.sleep_min, &src->sleep_min) ||
0097         get_user(params.avail_min, &src->avail_min) ||
0098         get_user(params.xfer_align, &src->xfer_align) ||
0099         get_user(params.start_threshold, &src->start_threshold) ||
0100         get_user(params.stop_threshold, &src->stop_threshold) ||
0101         get_user(params.silence_threshold, &src->silence_threshold) ||
0102         get_user(params.silence_size, &src->silence_size) ||
0103         get_user(params.tstamp_type, &src->tstamp_type) ||
0104         get_user(params.proto, &src->proto))
0105         return -EFAULT;
0106     /*
0107      * Check silent_size parameter.  Since we have 64bit boundary,
0108      * silence_size must be compared with the 32bit boundary.
0109      */
0110     boundary = recalculate_boundary(substream->runtime);
0111     if (boundary && params.silence_size >= boundary)
0112         params.silence_size = substream->runtime->boundary;
0113     err = snd_pcm_sw_params(substream, &params);
0114     if (err < 0)
0115         return err;
0116     if (boundary && put_user(boundary, &src->boundary))
0117         return -EFAULT;
0118     return err;
0119 }
0120 
0121 struct snd_pcm_channel_info32 {
0122     u32 channel;
0123     u32 offset;
0124     u32 first;
0125     u32 step;
0126 };
0127 
0128 static int snd_pcm_ioctl_channel_info_compat(struct snd_pcm_substream *substream,
0129                          struct snd_pcm_channel_info32 __user *src)
0130 {
0131     struct snd_pcm_channel_info info;
0132     int err;
0133 
0134     if (get_user(info.channel, &src->channel) ||
0135         get_user(info.offset, &src->offset) ||
0136         get_user(info.first, &src->first) ||
0137         get_user(info.step, &src->step))
0138         return -EFAULT;
0139     err = snd_pcm_channel_info(substream, &info);
0140     if (err < 0)
0141         return err;
0142     if (put_user(info.channel, &src->channel) ||
0143         put_user(info.offset, &src->offset) ||
0144         put_user(info.first, &src->first) ||
0145         put_user(info.step, &src->step))
0146         return -EFAULT;
0147     return err;
0148 }
0149 
0150 #ifdef CONFIG_X86_X32_ABI
0151 /* X32 ABI has the same struct as x86-64 for snd_pcm_channel_info */
0152 static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream,
0153                      struct snd_pcm_channel_info __user *src);
0154 #define snd_pcm_ioctl_channel_info_x32(s, p)    \
0155     snd_pcm_channel_info_user(s, p)
0156 #endif /* CONFIG_X86_X32_ABI */
0157 
0158 struct compat_snd_pcm_status64 {
0159     snd_pcm_state_t state;
0160     u8 rsvd[4]; /* alignment */
0161     s64 trigger_tstamp_sec;
0162     s64 trigger_tstamp_nsec;
0163     s64 tstamp_sec;
0164     s64 tstamp_nsec;
0165     u32 appl_ptr;
0166     u32 hw_ptr;
0167     s32 delay;
0168     u32 avail;
0169     u32 avail_max;
0170     u32 overrange;
0171     snd_pcm_state_t suspended_state;
0172     u32 audio_tstamp_data;
0173     s64 audio_tstamp_sec;
0174     s64 audio_tstamp_nsec;
0175     s64 driver_tstamp_sec;
0176     s64 driver_tstamp_nsec;
0177     u32 audio_tstamp_accuracy;
0178     unsigned char reserved[52-4*sizeof(s64)];
0179 } __packed;
0180 
0181 static int snd_pcm_status_user_compat64(struct snd_pcm_substream *substream,
0182                     struct compat_snd_pcm_status64 __user *src,
0183                     bool ext)
0184 {
0185     struct snd_pcm_status64 status;
0186     struct compat_snd_pcm_status64 compat_status64;
0187     int err;
0188 
0189     memset(&status, 0, sizeof(status));
0190     memset(&compat_status64, 0, sizeof(compat_status64));
0191     /*
0192      * with extension, parameters are read/write,
0193      * get audio_tstamp_data from user,
0194      * ignore rest of status structure
0195      */
0196     if (ext && get_user(status.audio_tstamp_data,
0197                 (u32 __user *)(&src->audio_tstamp_data)))
0198         return -EFAULT;
0199     err = snd_pcm_status64(substream, &status);
0200     if (err < 0)
0201         return err;
0202 
0203     if (clear_user(src, sizeof(*src)))
0204         return -EFAULT;
0205 
0206     compat_status64 = (struct compat_snd_pcm_status64) {
0207         .state = status.state,
0208         .trigger_tstamp_sec = status.trigger_tstamp_sec,
0209         .trigger_tstamp_nsec = status.trigger_tstamp_nsec,
0210         .tstamp_sec = status.tstamp_sec,
0211         .tstamp_nsec = status.tstamp_nsec,
0212         .appl_ptr = status.appl_ptr,
0213         .hw_ptr = status.hw_ptr,
0214         .delay = status.delay,
0215         .avail = status.avail,
0216         .avail_max = status.avail_max,
0217         .overrange = status.overrange,
0218         .suspended_state = status.suspended_state,
0219         .audio_tstamp_data = status.audio_tstamp_data,
0220         .audio_tstamp_sec = status.audio_tstamp_sec,
0221         .audio_tstamp_nsec = status.audio_tstamp_nsec,
0222         .driver_tstamp_sec = status.audio_tstamp_sec,
0223         .driver_tstamp_nsec = status.audio_tstamp_nsec,
0224         .audio_tstamp_accuracy = status.audio_tstamp_accuracy,
0225     };
0226 
0227     if (copy_to_user(src, &compat_status64, sizeof(compat_status64)))
0228         return -EFAULT;
0229 
0230     return err;
0231 }
0232 
0233 /* both for HW_PARAMS and HW_REFINE */
0234 static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream,
0235                       int refine, 
0236                       struct snd_pcm_hw_params32 __user *data32)
0237 {
0238     struct snd_pcm_hw_params *data;
0239     struct snd_pcm_runtime *runtime;
0240     int err;
0241 
0242     runtime = substream->runtime;
0243     if (!runtime)
0244         return -ENOTTY;
0245 
0246     data = kmalloc(sizeof(*data), GFP_KERNEL);
0247     if (!data)
0248         return -ENOMEM;
0249 
0250     /* only fifo_size (RO from userspace) is different, so just copy all */
0251     if (copy_from_user(data, data32, sizeof(*data32))) {
0252         err = -EFAULT;
0253         goto error;
0254     }
0255 
0256     if (refine)
0257         err = snd_pcm_hw_refine(substream, data);
0258     else
0259         err = snd_pcm_hw_params(substream, data);
0260     if (err < 0)
0261         goto error;
0262     if (copy_to_user(data32, data, sizeof(*data32)) ||
0263         put_user(data->fifo_size, &data32->fifo_size)) {
0264         err = -EFAULT;
0265         goto error;
0266     }
0267 
0268     if (! refine) {
0269         unsigned int new_boundary = recalculate_boundary(runtime);
0270         if (new_boundary)
0271             runtime->boundary = new_boundary;
0272     }
0273  error:
0274     kfree(data);
0275     return err;
0276 }
0277 
0278 
0279 /*
0280  */
0281 struct snd_xferi32 {
0282     s32 result;
0283     u32 buf;
0284     u32 frames;
0285 };
0286 
0287 static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream,
0288                       int dir, struct snd_xferi32 __user *data32)
0289 {
0290     compat_caddr_t buf;
0291     u32 frames;
0292     int err;
0293 
0294     if (! substream->runtime)
0295         return -ENOTTY;
0296     if (substream->stream != dir)
0297         return -EINVAL;
0298     if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
0299         return -EBADFD;
0300 
0301     if (get_user(buf, &data32->buf) ||
0302         get_user(frames, &data32->frames))
0303         return -EFAULT;
0304 
0305     if (dir == SNDRV_PCM_STREAM_PLAYBACK)
0306         err = snd_pcm_lib_write(substream, compat_ptr(buf), frames);
0307     else
0308         err = snd_pcm_lib_read(substream, compat_ptr(buf), frames);
0309     if (err < 0)
0310         return err;
0311     /* copy the result */
0312     if (put_user(err, &data32->result))
0313         return -EFAULT;
0314     return 0;
0315 }
0316 
0317 
0318 /* snd_xfern needs remapping of bufs */
0319 struct snd_xfern32 {
0320     s32 result;
0321     u32 bufs;  /* this is void **; */
0322     u32 frames;
0323 };
0324 
0325 /*
0326  * xfern ioctl nees to copy (up to) 128 pointers on stack.
0327  * although we may pass the copied pointers through f_op->ioctl, but the ioctl
0328  * handler there expands again the same 128 pointers on stack, so it is better
0329  * to handle the function (calling pcm_readv/writev) directly in this handler.
0330  */
0331 static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
0332                       int dir, struct snd_xfern32 __user *data32)
0333 {
0334     compat_caddr_t buf;
0335     compat_caddr_t __user *bufptr;
0336     u32 frames;
0337     void __user **bufs;
0338     int err, ch, i;
0339 
0340     if (! substream->runtime)
0341         return -ENOTTY;
0342     if (substream->stream != dir)
0343         return -EINVAL;
0344     if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
0345         return -EBADFD;
0346 
0347     ch = substream->runtime->channels;
0348     if (ch > 128)
0349         return -EINVAL;
0350     if (get_user(buf, &data32->bufs) ||
0351         get_user(frames, &data32->frames))
0352         return -EFAULT;
0353     bufptr = compat_ptr(buf);
0354     bufs = kmalloc_array(ch, sizeof(void __user *), GFP_KERNEL);
0355     if (bufs == NULL)
0356         return -ENOMEM;
0357     for (i = 0; i < ch; i++) {
0358         u32 ptr;
0359         if (get_user(ptr, bufptr)) {
0360             kfree(bufs);
0361             return -EFAULT;
0362         }
0363         bufs[i] = compat_ptr(ptr);
0364         bufptr++;
0365     }
0366     if (dir == SNDRV_PCM_STREAM_PLAYBACK)
0367         err = snd_pcm_lib_writev(substream, bufs, frames);
0368     else
0369         err = snd_pcm_lib_readv(substream, bufs, frames);
0370     if (err >= 0) {
0371         if (put_user(err, &data32->result))
0372             err = -EFAULT;
0373     }
0374     kfree(bufs);
0375     return err;
0376 }
0377 
0378 #ifdef CONFIG_X86_X32_ABI
0379 /* X32 ABI has 64bit timespec and 64bit alignment */
0380 struct snd_pcm_mmap_status_x32 {
0381     snd_pcm_state_t state;
0382     s32 pad1;
0383     u32 hw_ptr;
0384     u32 pad2; /* alignment */
0385     s64 tstamp_sec;
0386     s64 tstamp_nsec;
0387     snd_pcm_state_t suspended_state;
0388     s32 pad3;
0389     s64 audio_tstamp_sec;
0390     s64 audio_tstamp_nsec;
0391 } __packed;
0392 
0393 struct snd_pcm_mmap_control_x32 {
0394     u32 appl_ptr;
0395     u32 avail_min;
0396 };
0397 
0398 struct snd_pcm_sync_ptr_x32 {
0399     u32 flags;
0400     u32 rsvd; /* alignment */
0401     union {
0402         struct snd_pcm_mmap_status_x32 status;
0403         unsigned char reserved[64];
0404     } s;
0405     union {
0406         struct snd_pcm_mmap_control_x32 control;
0407         unsigned char reserved[64];
0408     } c;
0409 } __packed;
0410 
0411 static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream,
0412                       struct snd_pcm_sync_ptr_x32 __user *src)
0413 {
0414     struct snd_pcm_runtime *runtime = substream->runtime;
0415     volatile struct snd_pcm_mmap_status *status;
0416     volatile struct snd_pcm_mmap_control *control;
0417     u32 sflags;
0418     struct snd_pcm_mmap_control scontrol;
0419     struct snd_pcm_mmap_status sstatus;
0420     snd_pcm_uframes_t boundary;
0421     int err;
0422 
0423     if (snd_BUG_ON(!runtime))
0424         return -EINVAL;
0425 
0426     if (get_user(sflags, &src->flags) ||
0427         get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
0428         get_user(scontrol.avail_min, &src->c.control.avail_min))
0429         return -EFAULT;
0430     if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
0431         err = snd_pcm_hwsync(substream);
0432         if (err < 0)
0433             return err;
0434     }
0435     status = runtime->status;
0436     control = runtime->control;
0437     boundary = recalculate_boundary(runtime);
0438     if (!boundary)
0439         boundary = 0x7fffffff;
0440     snd_pcm_stream_lock_irq(substream);
0441     /* FIXME: we should consider the boundary for the sync from app */
0442     if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
0443         control->appl_ptr = scontrol.appl_ptr;
0444     else
0445         scontrol.appl_ptr = control->appl_ptr % boundary;
0446     if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
0447         control->avail_min = scontrol.avail_min;
0448     else
0449         scontrol.avail_min = control->avail_min;
0450     sstatus.state = status->state;
0451     sstatus.hw_ptr = status->hw_ptr % boundary;
0452     sstatus.tstamp = status->tstamp;
0453     sstatus.suspended_state = status->suspended_state;
0454     sstatus.audio_tstamp = status->audio_tstamp;
0455     snd_pcm_stream_unlock_irq(substream);
0456     if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
0457         snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
0458     if (put_user(sstatus.state, &src->s.status.state) ||
0459         put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) ||
0460         put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) ||
0461         put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) ||
0462         put_user(sstatus.suspended_state, &src->s.status.suspended_state) ||
0463         put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) ||
0464         put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) ||
0465         put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
0466         put_user(scontrol.avail_min, &src->c.control.avail_min))
0467         return -EFAULT;
0468 
0469     return 0;
0470 }
0471 #endif /* CONFIG_X86_X32_ABI */
0472 
0473 #ifdef __BIG_ENDIAN
0474 typedef char __pad_before_u32[4];
0475 typedef char __pad_after_u32[0];
0476 #else
0477 typedef char __pad_before_u32[0];
0478 typedef char __pad_after_u32[4];
0479 #endif
0480 
0481 /* PCM 2.0.15 API definition had a bug in mmap control; it puts the avail_min
0482  * at the wrong offset due to a typo in padding type.
0483  * The bug hits only 32bit.
0484  * A workaround for incorrect read/write is needed only in 32bit compat mode.
0485  */
0486 struct __snd_pcm_mmap_control64_buggy {
0487     __pad_before_u32 __pad1;
0488     __u32 appl_ptr;
0489     __pad_before_u32 __pad2;    /* SiC! here is the bug */
0490     __pad_before_u32 __pad3;
0491     __u32 avail_min;
0492     __pad_after_uframe __pad4;
0493 };
0494 
0495 static int snd_pcm_ioctl_sync_ptr_buggy(struct snd_pcm_substream *substream,
0496                     struct snd_pcm_sync_ptr __user *_sync_ptr)
0497 {
0498     struct snd_pcm_runtime *runtime = substream->runtime;
0499     struct snd_pcm_sync_ptr sync_ptr;
0500     struct __snd_pcm_mmap_control64_buggy *sync_cp;
0501     volatile struct snd_pcm_mmap_status *status;
0502     volatile struct snd_pcm_mmap_control *control;
0503     int err;
0504 
0505     memset(&sync_ptr, 0, sizeof(sync_ptr));
0506     sync_cp = (struct __snd_pcm_mmap_control64_buggy *)&sync_ptr.c.control;
0507     if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags)))
0508         return -EFAULT;
0509     if (copy_from_user(sync_cp, &(_sync_ptr->c.control), sizeof(*sync_cp)))
0510         return -EFAULT;
0511     status = runtime->status;
0512     control = runtime->control;
0513     if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
0514         err = snd_pcm_hwsync(substream);
0515         if (err < 0)
0516             return err;
0517     }
0518     snd_pcm_stream_lock_irq(substream);
0519     if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) {
0520         err = pcm_lib_apply_appl_ptr(substream, sync_cp->appl_ptr);
0521         if (err < 0) {
0522             snd_pcm_stream_unlock_irq(substream);
0523             return err;
0524         }
0525     } else {
0526         sync_cp->appl_ptr = control->appl_ptr;
0527     }
0528     if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
0529         control->avail_min = sync_cp->avail_min;
0530     else
0531         sync_cp->avail_min = control->avail_min;
0532     sync_ptr.s.status.state = status->state;
0533     sync_ptr.s.status.hw_ptr = status->hw_ptr;
0534     sync_ptr.s.status.tstamp = status->tstamp;
0535     sync_ptr.s.status.suspended_state = status->suspended_state;
0536     sync_ptr.s.status.audio_tstamp = status->audio_tstamp;
0537     snd_pcm_stream_unlock_irq(substream);
0538     if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL))
0539         snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
0540     if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr)))
0541         return -EFAULT;
0542     return 0;
0543 }
0544 
0545 /*
0546  */
0547 enum {
0548     SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32),
0549     SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32),
0550     SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32),
0551     SNDRV_PCM_IOCTL_STATUS_COMPAT32 = _IOR('A', 0x20, struct snd_pcm_status32),
0552     SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32 = _IOWR('A', 0x24, struct snd_pcm_status32),
0553     SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32),
0554     SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32),
0555     SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32),
0556     SNDRV_PCM_IOCTL_FORWARD32 = _IOW('A', 0x49, u32),
0557     SNDRV_PCM_IOCTL_WRITEI_FRAMES32 = _IOW('A', 0x50, struct snd_xferi32),
0558     SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32),
0559     SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32),
0560     SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32),
0561     SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64),
0562     SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64),
0563 #ifdef CONFIG_X86_X32_ABI
0564     SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info),
0565     SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32),
0566 #endif /* CONFIG_X86_X32_ABI */
0567 };
0568 
0569 static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
0570 {
0571     struct snd_pcm_file *pcm_file;
0572     struct snd_pcm_substream *substream;
0573     void __user *argp = compat_ptr(arg);
0574 
0575     pcm_file = file->private_data;
0576     if (! pcm_file)
0577         return -ENOTTY;
0578     substream = pcm_file->substream;
0579     if (! substream)
0580         return -ENOTTY;
0581 
0582     /*
0583      * When PCM is used on 32bit mode, we need to disable
0584      * mmap of the old PCM status/control records because
0585      * of the size incompatibility.
0586      */
0587     pcm_file->no_compat_mmap = 1;
0588 
0589     switch (cmd) {
0590     case SNDRV_PCM_IOCTL_PVERSION:
0591     case SNDRV_PCM_IOCTL_INFO:
0592     case SNDRV_PCM_IOCTL_TSTAMP:
0593     case SNDRV_PCM_IOCTL_TTSTAMP:
0594     case SNDRV_PCM_IOCTL_USER_PVERSION:
0595     case SNDRV_PCM_IOCTL_HWSYNC:
0596     case SNDRV_PCM_IOCTL_PREPARE:
0597     case SNDRV_PCM_IOCTL_RESET:
0598     case SNDRV_PCM_IOCTL_START:
0599     case SNDRV_PCM_IOCTL_DROP:
0600     case SNDRV_PCM_IOCTL_DRAIN:
0601     case SNDRV_PCM_IOCTL_PAUSE:
0602     case SNDRV_PCM_IOCTL_HW_FREE:
0603     case SNDRV_PCM_IOCTL_RESUME:
0604     case SNDRV_PCM_IOCTL_XRUN:
0605     case SNDRV_PCM_IOCTL_LINK:
0606     case SNDRV_PCM_IOCTL_UNLINK:
0607     case __SNDRV_PCM_IOCTL_SYNC_PTR32:
0608         return snd_pcm_common_ioctl(file, substream, cmd, argp);
0609     case __SNDRV_PCM_IOCTL_SYNC_PTR64:
0610 #ifdef CONFIG_X86_X32_ABI
0611         if (in_x32_syscall())
0612             return snd_pcm_ioctl_sync_ptr_x32(substream, argp);
0613 #endif /* CONFIG_X86_X32_ABI */
0614         return snd_pcm_ioctl_sync_ptr_buggy(substream, argp);
0615     case SNDRV_PCM_IOCTL_HW_REFINE32:
0616         return snd_pcm_ioctl_hw_params_compat(substream, 1, argp);
0617     case SNDRV_PCM_IOCTL_HW_PARAMS32:
0618         return snd_pcm_ioctl_hw_params_compat(substream, 0, argp);
0619     case SNDRV_PCM_IOCTL_SW_PARAMS32:
0620         return snd_pcm_ioctl_sw_params_compat(substream, argp);
0621     case SNDRV_PCM_IOCTL_STATUS_COMPAT32:
0622         return snd_pcm_status_user32(substream, argp, false);
0623     case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32:
0624         return snd_pcm_status_user32(substream, argp, true);
0625     case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
0626         return snd_pcm_ioctl_channel_info_compat(substream, argp);
0627     case SNDRV_PCM_IOCTL_WRITEI_FRAMES32:
0628         return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
0629     case SNDRV_PCM_IOCTL_READI_FRAMES32:
0630         return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
0631     case SNDRV_PCM_IOCTL_WRITEN_FRAMES32:
0632         return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
0633     case SNDRV_PCM_IOCTL_READN_FRAMES32:
0634         return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
0635     case SNDRV_PCM_IOCTL_DELAY32:
0636         return snd_pcm_ioctl_delay_compat(substream, argp);
0637     case SNDRV_PCM_IOCTL_REWIND32:
0638         return snd_pcm_ioctl_rewind_compat(substream, argp);
0639     case SNDRV_PCM_IOCTL_FORWARD32:
0640         return snd_pcm_ioctl_forward_compat(substream, argp);
0641     case SNDRV_PCM_IOCTL_STATUS_COMPAT64:
0642         return snd_pcm_status_user_compat64(substream, argp, false);
0643     case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64:
0644         return snd_pcm_status_user_compat64(substream, argp, true);
0645 #ifdef CONFIG_X86_X32_ABI
0646     case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32:
0647         return snd_pcm_ioctl_channel_info_x32(substream, argp);
0648 #endif /* CONFIG_X86_X32_ABI */
0649     }
0650 
0651     return -ENOIOCTLCMD;
0652 }