summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorParav Pandit <parav@mellanox.com>2018-09-05 09:48:00 +0300
committerJason Gunthorpe <jgg@mellanox.com>2018-09-05 16:19:25 -0600
commitb53b1c08a23eb1091982daacb2122f90a7094a77 (patch)
tree5496d534bb224e63dd25dd261dda2cf921c0556f
parentc5c4d92e70f37369b5bdca5e85f9fc55dc2c8a3b (diff)
downloadop-kernel-dev-b53b1c08a23eb1091982daacb2122f90a7094a77.zip
op-kernel-dev-b53b1c08a23eb1091982daacb2122f90a7094a77.tar.gz
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: Parav Pandit <parav@mellanox.com> Reviewed-by: Daniel Jurgens <danielj@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
-rw-r--r--drivers/infiniband/core/uverbs.h2
-rw-r--r--drivers/infiniband/core/uverbs_main.c30
2 files changed, 19 insertions, 13 deletions
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index 0288aec..7199c27 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -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;
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 1d2650f..16e5f71 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -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);
OpenPOWER on IntegriCloud