Commit ddfb908d authored by Stefan Richter's avatar Stefan Richter

ieee1394: raw1394: narrow down the state_mutex protected region

Refactor the ioctl dispatcher in order to move a fraction of it out of
the section which is serialized by fi->state_mutex.  This is not so much
about performance but more about self-documentation:  The mutex_lock()/
mutex_unlock() calls are now closer to the data accesses which the mutex
protects, i.e. to the iso_state switch.
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent 10963ea1
...@@ -2556,102 +2556,106 @@ static int raw1394_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -2556,102 +2556,106 @@ static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
return ret; return ret;
} }
/* ioctl is only used for rawiso operations */ static long raw1394_ioctl_inactive(struct file_info *fi, unsigned int cmd,
static long do_raw1394_ioctl(struct file *file, unsigned int cmd, void __user *argp)
unsigned long arg) {
switch (cmd) {
case RAW1394_IOC_ISO_XMIT_INIT:
return raw1394_iso_xmit_init(fi, argp);
case RAW1394_IOC_ISO_RECV_INIT:
return raw1394_iso_recv_init(fi, argp);
default:
return -EINVAL;
}
}
static long raw1394_ioctl_recv(struct file_info *fi, unsigned int cmd,
unsigned long arg)
{ {
struct file_info *fi = file->private_data;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
switch (fi->iso_state) { switch (cmd) {
case RAW1394_ISO_INACTIVE: case RAW1394_IOC_ISO_RECV_START:{
switch (cmd) { int args[3];
case RAW1394_IOC_ISO_XMIT_INIT:
return raw1394_iso_xmit_init(fi, argp); if (copy_from_user(&args[0], argp, sizeof(args)))
case RAW1394_IOC_ISO_RECV_INIT: return -EFAULT;
return raw1394_iso_recv_init(fi, argp); return hpsb_iso_recv_start(fi->iso_handle,
default: args[0], args[1], args[2]);
break;
} }
break; case RAW1394_IOC_ISO_XMIT_RECV_STOP:
case RAW1394_ISO_RECV: hpsb_iso_stop(fi->iso_handle);
switch (cmd) { return 0;
case RAW1394_IOC_ISO_RECV_START:{ case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
/* copy args from user-space */ return hpsb_iso_recv_listen_channel(fi->iso_handle, arg);
int args[3]; case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
if (copy_from_user return hpsb_iso_recv_unlisten_channel(fi->iso_handle, arg);
(&args[0], argp, sizeof(args))) case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
return -EFAULT; u64 mask;
return hpsb_iso_recv_start(fi->iso_handle,
args[0], args[1], if (copy_from_user(&mask, argp, sizeof(mask)))
args[2]); return -EFAULT;
} return hpsb_iso_recv_set_channel_mask(fi->iso_handle,
case RAW1394_IOC_ISO_XMIT_RECV_STOP: mask);
hpsb_iso_stop(fi->iso_handle);
return 0;
case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
return hpsb_iso_recv_listen_channel(fi->iso_handle,
arg);
case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
arg);
case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
/* copy the u64 from user-space */
u64 mask;
if (copy_from_user(&mask, argp, sizeof(mask)))
return -EFAULT;
return hpsb_iso_recv_set_channel_mask(fi->
iso_handle,
mask);
}
case RAW1394_IOC_ISO_GET_STATUS:
return raw1394_iso_get_status(fi, argp);
case RAW1394_IOC_ISO_RECV_PACKETS:
return raw1394_iso_recv_packets(fi, argp);
case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
return hpsb_iso_recv_release_packets(fi->iso_handle,
arg);
case RAW1394_IOC_ISO_RECV_FLUSH:
return hpsb_iso_recv_flush(fi->iso_handle);
case RAW1394_IOC_ISO_SHUTDOWN:
raw1394_iso_shutdown(fi);
return 0;
case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
queue_rawiso_event(fi);
return 0;
} }
break; case RAW1394_IOC_ISO_GET_STATUS:
case RAW1394_ISO_XMIT: return raw1394_iso_get_status(fi, argp);
switch (cmd) { case RAW1394_IOC_ISO_RECV_PACKETS:
case RAW1394_IOC_ISO_XMIT_START:{ return raw1394_iso_recv_packets(fi, argp);
/* copy two ints from user-space */ case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
int args[2]; return hpsb_iso_recv_release_packets(fi->iso_handle, arg);
if (copy_from_user case RAW1394_IOC_ISO_RECV_FLUSH:
(&args[0], argp, sizeof(args))) return hpsb_iso_recv_flush(fi->iso_handle);
return -EFAULT; case RAW1394_IOC_ISO_SHUTDOWN:
return hpsb_iso_xmit_start(fi->iso_handle, raw1394_iso_shutdown(fi);
args[0], args[1]); return 0;
} case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
case RAW1394_IOC_ISO_XMIT_SYNC: queue_rawiso_event(fi);
return hpsb_iso_xmit_sync(fi->iso_handle); return 0;
case RAW1394_IOC_ISO_XMIT_RECV_STOP: default:
hpsb_iso_stop(fi->iso_handle); return -EINVAL;
return 0; }
case RAW1394_IOC_ISO_GET_STATUS: }
return raw1394_iso_get_status(fi, argp);
case RAW1394_IOC_ISO_XMIT_PACKETS: static long raw1394_ioctl_xmit(struct file_info *fi, unsigned int cmd,
return raw1394_iso_send_packets(fi, argp); void __user *argp)
case RAW1394_IOC_ISO_SHUTDOWN: {
raw1394_iso_shutdown(fi); switch (cmd) {
return 0; case RAW1394_IOC_ISO_XMIT_START:{
case RAW1394_IOC_ISO_QUEUE_ACTIVITY: int args[2];
queue_rawiso_event(fi);
return 0; if (copy_from_user(&args[0], argp, sizeof(args)))
return -EFAULT;
return hpsb_iso_xmit_start(fi->iso_handle,
args[0], args[1]);
} }
break; case RAW1394_IOC_ISO_XMIT_SYNC:
return hpsb_iso_xmit_sync(fi->iso_handle);
case RAW1394_IOC_ISO_XMIT_RECV_STOP:
hpsb_iso_stop(fi->iso_handle);
return 0;
case RAW1394_IOC_ISO_GET_STATUS:
return raw1394_iso_get_status(fi, argp);
case RAW1394_IOC_ISO_XMIT_PACKETS:
return raw1394_iso_send_packets(fi, argp);
case RAW1394_IOC_ISO_SHUTDOWN:
raw1394_iso_shutdown(fi);
return 0;
case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
queue_rawiso_event(fi);
return 0;
default: default:
break; return -EINVAL;
} }
}
/* ioctl is only used for rawiso operations */
static long raw1394_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
struct file_info *fi = file->private_data;
void __user *argp = (void __user *)arg;
long ret;
/* state-independent commands */ /* state-independent commands */
switch(cmd) { switch(cmd) {
...@@ -2661,18 +2665,25 @@ static long do_raw1394_ioctl(struct file *file, unsigned int cmd, ...@@ -2661,18 +2665,25 @@ static long do_raw1394_ioctl(struct file *file, unsigned int cmd,
break; break;
} }
return -EINVAL; mutex_lock(&fi->state_mutex);
}
static long raw1394_ioctl(struct file *file, unsigned int cmd, switch (fi->iso_state) {
unsigned long arg) case RAW1394_ISO_INACTIVE:
{ ret = raw1394_ioctl_inactive(fi, cmd, argp);
struct file_info *fi = file->private_data; break;
long ret; case RAW1394_ISO_RECV:
ret = raw1394_ioctl_recv(fi, cmd, arg);
break;
case RAW1394_ISO_XMIT:
ret = raw1394_ioctl_xmit(fi, cmd, argp);
break;
default:
ret = -EINVAL;
break;
}
mutex_lock(&fi->state_mutex);
ret = do_raw1394_ioctl(file, cmd, arg);
mutex_unlock(&fi->state_mutex); mutex_unlock(&fi->state_mutex);
return ret; return ret;
} }
...@@ -2710,7 +2721,7 @@ static long raw1394_iso_xmit_recv_packets32(struct file *file, unsigned int cmd, ...@@ -2710,7 +2721,7 @@ static long raw1394_iso_xmit_recv_packets32(struct file *file, unsigned int cmd,
!copy_from_user(&infos32, &arg->infos, sizeof infos32)) { !copy_from_user(&infos32, &arg->infos, sizeof infos32)) {
infos = compat_ptr(infos32); infos = compat_ptr(infos32);
if (!copy_to_user(&dst->infos, &infos, sizeof infos)) if (!copy_to_user(&dst->infos, &infos, sizeof infos))
err = do_raw1394_ioctl(file, cmd, (unsigned long)dst); err = raw1394_ioctl(file, cmd, (unsigned long)dst);
} }
return err; return err;
} }
...@@ -2734,7 +2745,6 @@ static long raw1394_compat_ioctl(struct file *file, ...@@ -2734,7 +2745,6 @@ static long raw1394_compat_ioctl(struct file *file,
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
long err; long err;
mutex_lock(&fi->state_mutex);
switch (cmd) { switch (cmd) {
/* These requests have same format as long as 'int' has same size. */ /* These requests have same format as long as 'int' has same size. */
case RAW1394_IOC_ISO_RECV_INIT: case RAW1394_IOC_ISO_RECV_INIT:
...@@ -2751,7 +2761,7 @@ static long raw1394_compat_ioctl(struct file *file, ...@@ -2751,7 +2761,7 @@ static long raw1394_compat_ioctl(struct file *file,
case RAW1394_IOC_ISO_GET_STATUS: case RAW1394_IOC_ISO_GET_STATUS:
case RAW1394_IOC_ISO_SHUTDOWN: case RAW1394_IOC_ISO_SHUTDOWN:
case RAW1394_IOC_ISO_QUEUE_ACTIVITY: case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
err = do_raw1394_ioctl(file, cmd, arg); err = raw1394_ioctl(file, cmd, arg);
break; break;
/* These request have different format. */ /* These request have different format. */
case RAW1394_IOC_ISO_RECV_PACKETS32: case RAW1394_IOC_ISO_RECV_PACKETS32:
...@@ -2767,7 +2777,6 @@ static long raw1394_compat_ioctl(struct file *file, ...@@ -2767,7 +2777,6 @@ static long raw1394_compat_ioctl(struct file *file,
err = -EINVAL; err = -EINVAL;
break; break;
} }
mutex_unlock(&fi->state_mutex);
return err; return err;
} }
......
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