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

RDMA/uverbs: Use device.groups to initialize device attributes

Instead of explicitly adding device attribute files and handling such
error conditions, depend on device core layer to create device attributes
files based group pointer NULL terminated array.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Reviewed-by: default avatarDaniel Jurgens <danielj@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent c5c4d92e
......@@ -101,6 +101,8 @@ struct ib_uverbs_device {
int num_comp_vectors;
struct completion comp;
struct device dev;
/* First group for device attributes, NULL terminated array */
const struct attribute_group *groups[2];
struct ib_device __rcu *ib_dev;
int devnum;
struct cdev cdev;
......
......@@ -947,7 +947,7 @@ static struct ib_client uverbs_client = {
.remove = ib_uverbs_remove_one
};
static ssize_t show_ibdev(struct device *device, struct device_attribute *attr,
static ssize_t ibdev_show(struct device *device, struct device_attribute *attr,
char *buf)
{
struct ib_uverbs_device *dev =
......@@ -964,10 +964,10 @@ static ssize_t show_ibdev(struct device *device, struct device_attribute *attr,
return ret;
}
static DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL);
static DEVICE_ATTR_RO(ibdev);
static ssize_t show_dev_abi_version(struct device *device,
struct device_attribute *attr, char *buf)
static ssize_t abi_version_show(struct device *device,
struct device_attribute *attr, char *buf)
{
struct ib_uverbs_device *dev =
container_of(device, struct ib_uverbs_device, dev);
......@@ -983,7 +983,17 @@ static ssize_t show_dev_abi_version(struct device *device,
return ret;
}
static DEVICE_ATTR(abi_version, S_IRUGO, show_dev_abi_version, NULL);
static DEVICE_ATTR_RO(abi_version);
static struct attribute *ib_dev_attrs[] = {
&dev_attr_abi_version.attr,
&dev_attr_ibdev.attr,
NULL,
};
static const struct attribute_group dev_attr_group = {
.attrs = ib_dev_attrs,
};
static CLASS_ATTR_STRING(abi_version, S_IRUGO,
__stringify(IB_USER_VERBS_ABI_VERSION));
......@@ -1050,6 +1060,8 @@ static void ib_uverbs_add_one(struct ib_device *device)
uverbs_dev->dev.parent = device->dev.parent;
uverbs_dev->dev.devt = base;
uverbs_dev->dev.release = ib_uverbs_release_dev;
uverbs_dev->groups[0] = &dev_attr_group;
uverbs_dev->dev.groups = uverbs_dev->groups;
dev_set_name(&uverbs_dev->dev, "uverbs%d", uverbs_dev->devnum);
cdev_init(&uverbs_dev->cdev,
......@@ -1060,17 +1072,9 @@ static void ib_uverbs_add_one(struct ib_device *device)
if (ret)
goto err_cdev;
if (device_create_file(&uverbs_dev->dev, &dev_attr_ibdev))
goto err_file;
if (device_create_file(&uverbs_dev->dev, &dev_attr_abi_version))
goto err_file;
ib_set_client_data(device, &uverbs_client, uverbs_dev);
return;
err_file:
cdev_device_del(&uverbs_dev->cdev, &uverbs_dev->dev);
err_cdev:
cdev_del(&uverbs_dev->cdev);
put_device(&uverbs_dev->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