Commit ee848721 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

IB/umad: Avoid additional device reference during open()/close()

ib_umad_init_port_dev() holds the reference of a ib_umad_device instance.
ib_umad_device contains standard core device and cdev.  cdev holds the
reference of its parent core device.  file ops holds the reference to cdev
using core kernel.

Therefore, there is no need to hold additional reference while opening
umad related char devices.

While at it, add comments to bring clarity on releasing references to
ib_umd_device.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 6113cc44
...@@ -989,7 +989,6 @@ static int ib_umad_open(struct inode *inode, struct file *filp) ...@@ -989,7 +989,6 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
goto out; goto out;
} }
ib_umad_dev_get(port->umad_dev);
out: out:
mutex_unlock(&port->file_mutex); mutex_unlock(&port->file_mutex);
return ret; return ret;
...@@ -998,7 +997,6 @@ static int ib_umad_open(struct inode *inode, struct file *filp) ...@@ -998,7 +997,6 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
static int ib_umad_close(struct inode *inode, struct file *filp) static int ib_umad_close(struct inode *inode, struct file *filp)
{ {
struct ib_umad_file *file = filp->private_data; struct ib_umad_file *file = filp->private_data;
struct ib_umad_device *dev = file->port->umad_dev;
struct ib_umad_packet *packet, *tmp; struct ib_umad_packet *packet, *tmp;
int already_dead; int already_dead;
int i; int i;
...@@ -1027,7 +1025,6 @@ static int ib_umad_close(struct inode *inode, struct file *filp) ...@@ -1027,7 +1025,6 @@ static int ib_umad_close(struct inode *inode, struct file *filp)
mutex_unlock(&file->port->file_mutex); mutex_unlock(&file->port->file_mutex);
kfree(file); kfree(file);
ib_umad_dev_put(dev);
return 0; return 0;
} }
...@@ -1077,7 +1074,6 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp) ...@@ -1077,7 +1074,6 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp)
if (ret) if (ret)
goto err_clr_sm_cap; goto err_clr_sm_cap;
ib_umad_dev_get(port->umad_dev);
return 0; return 0;
err_clr_sm_cap: err_clr_sm_cap:
...@@ -1106,7 +1102,6 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp) ...@@ -1106,7 +1102,6 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp)
up(&port->sm_sem); up(&port->sm_sem);
ib_umad_dev_put(port->umad_dev);
return ret; return ret;
} }
...@@ -1283,8 +1278,10 @@ static void ib_umad_kill_port(struct ib_umad_port *port) ...@@ -1283,8 +1278,10 @@ static void ib_umad_kill_port(struct ib_umad_port *port)
mutex_unlock(&port->file_mutex); mutex_unlock(&port->file_mutex);
cdev_device_del(&port->sm_cdev, &port->sm_dev); cdev_device_del(&port->sm_cdev, &port->sm_dev);
/* balances device_initialize() */
put_device(&port->sm_dev); put_device(&port->sm_dev);
cdev_device_del(&port->cdev, &port->dev); cdev_device_del(&port->cdev, &port->dev);
/* balances device_initialize() */
put_device(&port->dev); put_device(&port->dev);
ida_free(&umad_ida, port->dev_num); ida_free(&umad_ida, port->dev_num);
} }
...@@ -1329,6 +1326,7 @@ static void ib_umad_add_one(struct ib_device *device) ...@@ -1329,6 +1326,7 @@ static void ib_umad_add_one(struct ib_device *device)
ib_umad_kill_port(&umad_dev->ports[i - s]); ib_umad_kill_port(&umad_dev->ports[i - s]);
} }
free: free:
/* balances kref_init */
ib_umad_dev_put(umad_dev); ib_umad_dev_put(umad_dev);
} }
...@@ -1344,6 +1342,7 @@ static void ib_umad_remove_one(struct ib_device *device, void *client_data) ...@@ -1344,6 +1342,7 @@ static void ib_umad_remove_one(struct ib_device *device, void *client_data)
if (rdma_cap_ib_mad(device, i + rdma_start_port(device))) if (rdma_cap_ib_mad(device, i + rdma_start_port(device)))
ib_umad_kill_port(&umad_dev->ports[i]); ib_umad_kill_port(&umad_dev->ports[i]);
} }
/* balances kref_init() */
ib_umad_dev_put(umad_dev); ib_umad_dev_put(umad_dev);
} }
......
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