Commit feae1ef1 authored by Roland Dreier's avatar Roland Dreier Committed by Jonathan Corbet

IB/umad: BKL is not needed for ib_umad_open()

Remove explicit lock_kernel() calls and document why the code is safe.
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent 5b2d281a
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <linux/semaphore.h> #include <linux/semaphore.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -778,23 +777,33 @@ static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, ...@@ -778,23 +777,33 @@ static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd,
} }
#endif #endif
/*
* ib_umad_open() does not need the BKL:
*
* - umad_port[] accesses are protected by port_lock, the
* ib_umad_port structures are properly reference counted, and
* everything else is purely local to the file being created, so
* races against other open calls are not a problem;
* - the ioctl method does not affect any global state outside of the
* file structure being operated on;
* - the port is added to umad_port[] as the last part of module
* initialization so the open method will either immediately run
* -ENXIO, or all required initialization will be done.
*/
static int ib_umad_open(struct inode *inode, struct file *filp) static int ib_umad_open(struct inode *inode, struct file *filp)
{ {
struct ib_umad_port *port; struct ib_umad_port *port;
struct ib_umad_file *file; struct ib_umad_file *file;
int ret = 0; int ret = 0;
lock_kernel();
spin_lock(&port_lock); spin_lock(&port_lock);
port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE]; port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE];
if (port) if (port)
kref_get(&port->umad_dev->ref); kref_get(&port->umad_dev->ref);
spin_unlock(&port_lock); spin_unlock(&port_lock);
if (!port) { if (!port)
unlock_kernel();
return -ENXIO; return -ENXIO;
}
mutex_lock(&port->file_mutex); mutex_lock(&port->file_mutex);
...@@ -823,7 +832,6 @@ static int ib_umad_open(struct inode *inode, struct file *filp) ...@@ -823,7 +832,6 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
out: out:
mutex_unlock(&port->file_mutex); mutex_unlock(&port->file_mutex);
unlock_kernel();
return ret; return ret;
} }
......
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