Commit 02e1bc89 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] sparse: sound compat ioctls annotations

	Trivial annotations + typo fix in _snd_ioctl32_hwdep_dsp_image()
(we want to copy 32bit structure from userland, convert it to native one
and do normal ioctl on it; see the first changed line below for what's
really happening...)
parent 1a3d7727
...@@ -37,16 +37,16 @@ struct sndrv_hwdep_dsp_image32 { ...@@ -37,16 +37,16 @@ struct sndrv_hwdep_dsp_image32 {
static int _snd_ioctl32_hwdep_dsp_image(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl) static int _snd_ioctl32_hwdep_dsp_image(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)
{ {
struct sndrv_hwdep_dsp_image data; struct sndrv_hwdep_dsp_image data;
struct sndrv_hwdep_dsp_image data32; struct sndrv_hwdep_dsp_image32 data32;
mm_segment_t oldseg; mm_segment_t oldseg;
int err; int err;
if (copy_from_user(&data32, (void*)arg, sizeof(data32))) if (copy_from_user(&data32, (void __user *)arg, sizeof(data32)))
return -EFAULT; return -EFAULT;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.index = data32.index; data.index = data32.index;
memcpy(data.name, data32.name, sizeof(data.name)); memcpy(data.name, data32.name, sizeof(data.name));
data.image = A(data32.image); data.image = compat_ptr(data32.image);
data.length = data32.length; data.length = data32.length;
data.driver_data = data32.driver_data; data.driver_data = data32.driver_data;
oldseg = get_fs(); oldseg = get_fs();
......
...@@ -109,14 +109,14 @@ static int _snd_ioctl32_ctl_elem_list(unsigned int fd, unsigned int cmd, unsigne ...@@ -109,14 +109,14 @@ static int _snd_ioctl32_ctl_elem_list(unsigned int fd, unsigned int cmd, unsigne
mm_segment_t oldseg; mm_segment_t oldseg;
int err; int err;
if (copy_from_user(&data32, (void*)arg, sizeof(data32))) if (copy_from_user(&data32, (void __user *)arg, sizeof(data32)))
return -EFAULT; return -EFAULT;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.offset = data32.offset; data.offset = data32.offset;
data.space = data32.space; data.space = data32.space;
data.used = data32.used; data.used = data32.used;
data.count = data32.count; data.count = data32.count;
data.pids = A(data32.pids); data.pids = compat_ptr(data32.pids);
oldseg = get_fs(); oldseg = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)&data); err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)&data);
...@@ -129,7 +129,7 @@ static int _snd_ioctl32_ctl_elem_list(unsigned int fd, unsigned int cmd, unsigne ...@@ -129,7 +129,7 @@ static int _snd_ioctl32_ctl_elem_list(unsigned int fd, unsigned int cmd, unsigne
data32.used = data.used; data32.used = data.used;
data32.count = data.count; data32.count = data.count;
//data.pids = data.pids; //data.pids = data.pids;
if (copy_to_user((void*)arg, &data32, sizeof(data32))) if (copy_to_user((void __user *)arg, &data32, sizeof(data32)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -175,7 +175,7 @@ static int _snd_ioctl32_ctl_elem_info(unsigned int fd, unsigned int cmd, unsigne ...@@ -175,7 +175,7 @@ static int _snd_ioctl32_ctl_elem_info(unsigned int fd, unsigned int cmd, unsigne
int err; int err;
mm_segment_t oldseg; mm_segment_t oldseg;
if (copy_from_user(&data32, (void*)arg, sizeof(data32))) if (copy_from_user(&data32, (void __user *)arg, sizeof(data32)))
return -EFAULT; return -EFAULT;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.id = data32.id; data.id = data32.id;
...@@ -216,7 +216,7 @@ static int _snd_ioctl32_ctl_elem_info(unsigned int fd, unsigned int cmd, unsigne ...@@ -216,7 +216,7 @@ static int _snd_ioctl32_ctl_elem_info(unsigned int fd, unsigned int cmd, unsigne
default: default:
break; break;
} }
if (copy_to_user((void*)arg, &data32, sizeof(data32))) if (copy_to_user((void __user *)arg, &data32, sizeof(data32)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -291,7 +291,7 @@ static int _snd_ioctl32_ctl_elem_value(unsigned int fd, unsigned int cmd, unsign ...@@ -291,7 +291,7 @@ static int _snd_ioctl32_ctl_elem_value(unsigned int fd, unsigned int cmd, unsign
goto __end; goto __end;
} }
if (copy_from_user(data32, (void*)arg, sizeof(*data32))) { if (copy_from_user(data32, (void __user *)arg, sizeof(*data32))) {
err = -EFAULT; err = -EFAULT;
goto __end; goto __end;
} }
...@@ -299,7 +299,7 @@ static int _snd_ioctl32_ctl_elem_value(unsigned int fd, unsigned int cmd, unsign ...@@ -299,7 +299,7 @@ static int _snd_ioctl32_ctl_elem_value(unsigned int fd, unsigned int cmd, unsign
data->id = data32->id; data->id = data32->id;
data->indirect = data32->indirect; data->indirect = data32->indirect;
if (data->indirect) /* FIXME: this is not correct for long arrays */ if (data->indirect) /* FIXME: this is not correct for long arrays */
data->value.integer.value_ptr = (void*)TO_PTR(data32->value.integer.value_ptr); data->value.integer.value_ptr = compat_ptr(data32->value.integer.value_ptr);
type = get_ctl_type(file, &data->id); type = get_ctl_type(file, &data->id);
if (type < 0) { if (type < 0) {
err = type; err = type;
...@@ -367,7 +367,7 @@ static int _snd_ioctl32_ctl_elem_value(unsigned int fd, unsigned int cmd, unsign ...@@ -367,7 +367,7 @@ static int _snd_ioctl32_ctl_elem_value(unsigned int fd, unsigned int cmd, unsign
} }
} }
err = 0; err = 0;
if (copy_to_user((void*)arg, data32, sizeof(*data32))) if (copy_to_user((void __user *)arg, data32, sizeof(*data32)))
err = -EFAULT; err = -EFAULT;
__end: __end:
if (data32) if (data32)
......
...@@ -26,19 +26,10 @@ ...@@ -26,19 +26,10 @@
#ifndef __ALSA_IOCTL32_H #ifndef __ALSA_IOCTL32_H
#define __ALSA_IOCTL32_H #define __ALSA_IOCTL32_H
#ifndef A #include <linux/compat.h>
#ifdef CONFIG_PPC64
#include <asm/ppc32.h>
#else
/* x86-64, sparc64 */
#define A(__x) ((void *)(unsigned long)(__x))
#endif
#endif
#define TO_PTR(x) A(x)
#define COPY(x) (dst->x = src->x) #define COPY(x) (dst->x = src->x)
#define CPTR(x) (dst->x = (typeof(dst->x))A(src->x)) #define CPTR(x) (dst->x = compat_ptr(src->x))
#define convert_from_32(type, dstp, srcp)\ #define convert_from_32(type, dstp, srcp)\
{\ {\
...@@ -62,7 +53,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long ...@@ -62,7 +53,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long
struct sndrv_##type data;\ struct sndrv_##type data;\
mm_segment_t oldseg;\ mm_segment_t oldseg;\
int err;\ int err;\
if (copy_from_user(&data32, (void*)arg, sizeof(data32)))\ if (copy_from_user(&data32, (void __user *)arg, sizeof(data32)))\
return -EFAULT;\ return -EFAULT;\
memset(&data, 0, sizeof(data));\ memset(&data, 0, sizeof(data));\
convert_from_32(type, &data, &data32);\ convert_from_32(type, &data, &data32);\
...@@ -74,7 +65,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long ...@@ -74,7 +65,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long
return err;\ return err;\
if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\ if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
convert_to_32(type, &data32, &data);\ convert_to_32(type, &data32, &data);\
if (copy_to_user((void*)arg, &data32, sizeof(data32)))\ if (copy_to_user((void __user *)arg, &data32, sizeof(data32)))\
return -EFAULT;\ return -EFAULT;\
}\ }\
return 0;\ return 0;\
...@@ -93,7 +84,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long ...@@ -93,7 +84,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long
err = -ENOMEM; \ err = -ENOMEM; \
goto __end; \ goto __end; \
}\ }\
if (copy_from_user(data32, (void*)arg, sizeof(*data32))) { \ if (copy_from_user(data32, (void __user *)arg, sizeof(*data32))) { \
err = -EFAULT; \ err = -EFAULT; \
goto __end; \ goto __end; \
}\ }\
...@@ -108,7 +99,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long ...@@ -108,7 +99,7 @@ static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long
err = 0;\ err = 0;\
if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\ if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
convert_to_32(type, data32, data);\ convert_to_32(type, data32, data);\
if (copy_to_user((void*)arg, data32, sizeof(*data32)))\ if (copy_to_user((void __user *)arg, data32, sizeof(*data32)))\
err = -EFAULT;\ err = -EFAULT;\
}\ }\
__end:\ __end:\
......
...@@ -189,11 +189,11 @@ static int _snd_ioctl32_xferi(unsigned int fd, unsigned int cmd, unsigned long a ...@@ -189,11 +189,11 @@ static int _snd_ioctl32_xferi(unsigned int fd, unsigned int cmd, unsigned long a
mm_segment_t oldseg; mm_segment_t oldseg;
int err; int err;
if (copy_from_user(&data32, (void*)arg, sizeof(data32))) if (copy_from_user(&data32, (void __user *)arg, sizeof(data32)))
return -EFAULT; return -EFAULT;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.result = data32.result; data.result = data32.result;
data.buf = A(data32.buf); data.buf = compat_ptr(data32.buf);
data.frames = data32.frames; data.frames = data32.frames;
oldseg = get_fs(); oldseg = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
...@@ -203,7 +203,7 @@ static int _snd_ioctl32_xferi(unsigned int fd, unsigned int cmd, unsigned long a ...@@ -203,7 +203,7 @@ static int _snd_ioctl32_xferi(unsigned int fd, unsigned int cmd, unsigned long a
return err; return err;
/* copy the result */ /* copy the result */
data32.result = data.result; data32.result = data.result;
if (copy_to_user((void*)arg, &data32, sizeof(data32))) if (copy_to_user((void __user *)arg, &data32, sizeof(data32)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -226,10 +226,11 @@ static int _snd_ioctl32_xfern(unsigned int fd, unsigned int cmd, unsigned long a ...@@ -226,10 +226,11 @@ static int _snd_ioctl32_xfern(unsigned int fd, unsigned int cmd, unsigned long a
{ {
snd_pcm_file_t *pcm_file; snd_pcm_file_t *pcm_file;
snd_pcm_substream_t *substream; snd_pcm_substream_t *substream;
struct sndrv_xfern32 data32, *srcptr = (struct sndrv_xfern32*)arg; struct sndrv_xfern32 data32;
void **bufs = NULL; struct sndrv_xfern32 __user *srcptr = (void __user *)arg;
void __user **bufs = NULL;
int err = 0, ch, i; int err = 0, ch, i;
u32 *bufptr; u32 __user *bufptr;
mm_segment_t oldseg; mm_segment_t oldseg;
/* FIXME: need to check whether fop->ioctl is sane */ /* FIXME: need to check whether fop->ioctl is sane */
...@@ -256,7 +257,7 @@ static int _snd_ioctl32_xfern(unsigned int fd, unsigned int cmd, unsigned long a ...@@ -256,7 +257,7 @@ static int _snd_ioctl32_xfern(unsigned int fd, unsigned int cmd, unsigned long a
if (get_user(data32.frames, &srcptr->frames)) if (get_user(data32.frames, &srcptr->frames))
return -EFAULT; return -EFAULT;
__get_user(data32.bufs, &srcptr->bufs); __get_user(data32.bufs, &srcptr->bufs);
bufptr = (u32*)TO_PTR(data32.bufs); bufptr = compat_ptr(data32.bufs);
bufs = kmalloc(sizeof(void *) * 128, GFP_KERNEL); bufs = kmalloc(sizeof(void *) * 128, GFP_KERNEL);
if (bufs == NULL) if (bufs == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -264,7 +265,7 @@ static int _snd_ioctl32_xfern(unsigned int fd, unsigned int cmd, unsigned long a ...@@ -264,7 +265,7 @@ static int _snd_ioctl32_xfern(unsigned int fd, unsigned int cmd, unsigned long a
u32 ptr; u32 ptr;
if (get_user(ptr, bufptr)) if (get_user(ptr, bufptr))
return -EFAULT; return -EFAULT;
bufs[ch] = (void*)TO_PTR(ptr); bufs[ch] = compat_ptr(ptr);
bufptr++; bufptr++;
} }
oldseg = get_fs(); oldseg = get_fs();
...@@ -355,7 +356,7 @@ static int _snd_ioctl32_pcm_hw_params_old(unsigned int fd, unsigned int cmd, uns ...@@ -355,7 +356,7 @@ static int _snd_ioctl32_pcm_hw_params_old(unsigned int fd, unsigned int cmd, uns
err = -ENOMEM; err = -ENOMEM;
goto __end; goto __end;
} }
if (copy_from_user(data32, (void*)arg, sizeof(*data32))) { if (copy_from_user(data32, (void __user *)arg, sizeof(*data32))) {
err = -EFAULT; err = -EFAULT;
goto __end; goto __end;
} }
...@@ -368,7 +369,7 @@ static int _snd_ioctl32_pcm_hw_params_old(unsigned int fd, unsigned int cmd, uns ...@@ -368,7 +369,7 @@ static int _snd_ioctl32_pcm_hw_params_old(unsigned int fd, unsigned int cmd, uns
goto __end; goto __end;
snd_pcm_hw_convert_to_old_params(data32, data); snd_pcm_hw_convert_to_old_params(data32, data);
err = 0; err = 0;
if (copy_to_user((void*)arg, data32, sizeof(*data32))) if (copy_to_user((void __user *)arg, data32, sizeof(*data32)))
err = -EFAULT; err = -EFAULT;
__end: __end:
if (data) if (data)
......
...@@ -1055,7 +1055,7 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf, size_t c ...@@ -1055,7 +1055,7 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf, size_t c
} else { } else {
#if defined(CONFIG_SND_BIT32_EMUL) || defined(CONFIG_SND_BIT32_EMUL_MODULE) #if defined(CONFIG_SND_BIT32_EMUL) || defined(CONFIG_SND_BIT32_EMUL_MODULE)
if (client->convert32 && snd_seq_ev_is_varusr(&event)) { if (client->convert32 && snd_seq_ev_is_varusr(&event)) {
void *ptr = (void*)A(event.data.raw32.d[1]); void *ptr = compat_ptr(event.data.raw32.d[1]);
event.data.ext.ptr = ptr; event.data.ext.ptr = ptr;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment