Commit ba8e9310 authored by Roland Dreier's avatar Roland Dreier

[IB] Fail sysfs queries after device is unregistered

We keep IB device structures around until the last sysfs reference is
gone, but we shouldn't ask the low-level driver to do anything after
the LLD unregisters the device.  To handle this, check the reg_state
field and just fail sysfs show() requests if the device has already
been unregistered.
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent d476306f
...@@ -65,6 +65,11 @@ struct port_table_attribute { ...@@ -65,6 +65,11 @@ struct port_table_attribute {
int index; int index;
}; };
static inline int ibdev_is_alive(const struct ib_device *dev)
{
return dev->reg_state == IB_DEV_REGISTERED;
}
static ssize_t port_attr_show(struct kobject *kobj, static ssize_t port_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf) struct attribute *attr, char *buf)
{ {
...@@ -74,6 +79,8 @@ static ssize_t port_attr_show(struct kobject *kobj, ...@@ -74,6 +79,8 @@ static ssize_t port_attr_show(struct kobject *kobj,
if (!port_attr->show) if (!port_attr->show)
return -EIO; return -EIO;
if (!ibdev_is_alive(p->ibdev))
return -ENODEV;
return port_attr->show(p, port_attr, buf); return port_attr->show(p, port_attr, buf);
} }
...@@ -581,6 +588,9 @@ static ssize_t show_node_type(struct class_device *cdev, char *buf) ...@@ -581,6 +588,9 @@ static ssize_t show_node_type(struct class_device *cdev, char *buf)
{ {
struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
if (!ibdev_is_alive(dev))
return -ENODEV;
switch (dev->node_type) { switch (dev->node_type) {
case IB_NODE_CA: return sprintf(buf, "%d: CA\n", dev->node_type); case IB_NODE_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
case IB_NODE_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type); case IB_NODE_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
...@@ -595,6 +605,9 @@ static ssize_t show_sys_image_guid(struct class_device *cdev, char *buf) ...@@ -595,6 +605,9 @@ static ssize_t show_sys_image_guid(struct class_device *cdev, char *buf)
struct ib_device_attr attr; struct ib_device_attr attr;
ssize_t ret; ssize_t ret;
if (!ibdev_is_alive(dev))
return -ENODEV;
ret = ib_query_device(dev, &attr); ret = ib_query_device(dev, &attr);
if (ret) if (ret)
return ret; return ret;
...@@ -612,6 +625,9 @@ static ssize_t show_node_guid(struct class_device *cdev, char *buf) ...@@ -612,6 +625,9 @@ static ssize_t show_node_guid(struct class_device *cdev, char *buf)
struct ib_device_attr attr; struct ib_device_attr attr;
ssize_t ret; ssize_t ret;
if (!ibdev_is_alive(dev))
return -ENODEV;
ret = ib_query_device(dev, &attr); ret = ib_query_device(dev, &attr);
if (ret) if (ret)
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