diff options
author | Jason Gunthorpe <jgg@mellanox.com> | 2018-09-05 18:21:22 -0400 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2018-09-05 18:21:22 -0400 |
commit | 2c910cb75e1fe6de52d95c8e32caedd1629a33a5 (patch) | |
tree | 94a0eea6f8cde689d11e7583ddd0a930b8785ab4 /drivers/infiniband/core/sysfs.c | |
parent | 627212c9d49ba2759b699450f5d8f45f73e062fa (diff) | |
parent | b53b1c08a23eb1091982daacb2122f90a7094a77 (diff) |
Merge branch 'uverbs_dev_cleanups' into rdma.git for-next
For dependencies, branch based on rdma.git 'for-rc' of
https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git/
Pull 'uverbs_dev_cleanups' from Leon Romanovsky:
====================
Reuse the char device code interfaces to simplify ib_uverbs_device
creation and destruction. As part of this series, we are sending fix to
cleanup path, which was discovered during internal review,
The fix definitely can go to -rc, but it means that this series will be
dependent on rdma-rc.
====================
* branch 'uverbs_dev_cleanups':
RDMA/uverbs: Use device.groups to initialize device attributes
RDMA/uverbs: Use cdev_device_add() instead of cdev_add()
RDMA/core: Depend on device_add() to add device attributes
RDMA/uverbs: Fix error cleanup path of ib_uverbs_add_one()
Resolved conflict in ib_device_unregister_sysfs()
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'drivers/infiniband/core/sysfs.c')
-rw-r--r-- | drivers/infiniband/core/sysfs.c | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c index 62351b3fcafc..0b04dbff884f 100644 --- a/drivers/infiniband/core/sysfs.c +++ b/drivers/infiniband/core/sysfs.c | |||
@@ -1183,7 +1183,7 @@ err_put: | |||
1183 | return ret; | 1183 | return ret; |
1184 | } | 1184 | } |
1185 | 1185 | ||
1186 | static ssize_t show_node_type(struct device *device, | 1186 | static ssize_t node_type_show(struct device *device, |
1187 | struct device_attribute *attr, char *buf) | 1187 | struct device_attribute *attr, char *buf) |
1188 | { | 1188 | { |
1189 | struct ib_device *dev = container_of(device, struct ib_device, dev); | 1189 | struct ib_device *dev = container_of(device, struct ib_device, dev); |
@@ -1198,8 +1198,9 @@ static ssize_t show_node_type(struct device *device, | |||
1198 | default: return sprintf(buf, "%d: <unknown>\n", dev->node_type); | 1198 | default: return sprintf(buf, "%d: <unknown>\n", dev->node_type); |
1199 | } | 1199 | } |
1200 | } | 1200 | } |
1201 | static DEVICE_ATTR_RO(node_type); | ||
1201 | 1202 | ||
1202 | static ssize_t show_sys_image_guid(struct device *device, | 1203 | static ssize_t sys_image_guid_show(struct device *device, |
1203 | struct device_attribute *dev_attr, char *buf) | 1204 | struct device_attribute *dev_attr, char *buf) |
1204 | { | 1205 | { |
1205 | struct ib_device *dev = container_of(device, struct ib_device, dev); | 1206 | struct ib_device *dev = container_of(device, struct ib_device, dev); |
@@ -1210,8 +1211,9 @@ static ssize_t show_sys_image_guid(struct device *device, | |||
1210 | be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[2]), | 1211 | be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[2]), |
1211 | be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[3])); | 1212 | be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[3])); |
1212 | } | 1213 | } |
1214 | static DEVICE_ATTR_RO(sys_image_guid); | ||
1213 | 1215 | ||
1214 | static ssize_t show_node_guid(struct device *device, | 1216 | static ssize_t node_guid_show(struct device *device, |
1215 | struct device_attribute *attr, char *buf) | 1217 | struct device_attribute *attr, char *buf) |
1216 | { | 1218 | { |
1217 | struct ib_device *dev = container_of(device, struct ib_device, dev); | 1219 | struct ib_device *dev = container_of(device, struct ib_device, dev); |
@@ -1222,8 +1224,9 @@ static ssize_t show_node_guid(struct device *device, | |||
1222 | be16_to_cpu(((__be16 *) &dev->node_guid)[2]), | 1224 | be16_to_cpu(((__be16 *) &dev->node_guid)[2]), |
1223 | be16_to_cpu(((__be16 *) &dev->node_guid)[3])); | 1225 | be16_to_cpu(((__be16 *) &dev->node_guid)[3])); |
1224 | } | 1226 | } |
1227 | static DEVICE_ATTR_RO(node_guid); | ||
1225 | 1228 | ||
1226 | static ssize_t show_node_desc(struct device *device, | 1229 | static ssize_t node_desc_show(struct device *device, |
1227 | struct device_attribute *attr, char *buf) | 1230 | struct device_attribute *attr, char *buf) |
1228 | { | 1231 | { |
1229 | struct ib_device *dev = container_of(device, struct ib_device, dev); | 1232 | struct ib_device *dev = container_of(device, struct ib_device, dev); |
@@ -1231,9 +1234,9 @@ static ssize_t show_node_desc(struct device *device, | |||
1231 | return sprintf(buf, "%.64s\n", dev->node_desc); | 1234 | return sprintf(buf, "%.64s\n", dev->node_desc); |
1232 | } | 1235 | } |
1233 | 1236 | ||
1234 | static ssize_t set_node_desc(struct device *device, | 1237 | static ssize_t node_desc_store(struct device *device, |
1235 | struct device_attribute *attr, | 1238 | struct device_attribute *attr, |
1236 | const char *buf, size_t count) | 1239 | const char *buf, size_t count) |
1237 | { | 1240 | { |
1238 | struct ib_device *dev = container_of(device, struct ib_device, dev); | 1241 | struct ib_device *dev = container_of(device, struct ib_device, dev); |
1239 | struct ib_device_modify desc = {}; | 1242 | struct ib_device_modify desc = {}; |
@@ -1249,8 +1252,9 @@ static ssize_t set_node_desc(struct device *device, | |||
1249 | 1252 | ||
1250 | return count; | 1253 | return count; |
1251 | } | 1254 | } |
1255 | static DEVICE_ATTR_RW(node_desc); | ||
1252 | 1256 | ||
1253 | static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr, | 1257 | static ssize_t fw_ver_show(struct device *device, struct device_attribute *attr, |
1254 | char *buf) | 1258 | char *buf) |
1255 | { | 1259 | { |
1256 | struct ib_device *dev = container_of(device, struct ib_device, dev); | 1260 | struct ib_device *dev = container_of(device, struct ib_device, dev); |
@@ -1259,19 +1263,19 @@ static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr, | |||
1259 | strlcat(buf, "\n", IB_FW_VERSION_NAME_MAX); | 1263 | strlcat(buf, "\n", IB_FW_VERSION_NAME_MAX); |
1260 | return strlen(buf); | 1264 | return strlen(buf); |
1261 | } | 1265 | } |
1266 | static DEVICE_ATTR_RO(fw_ver); | ||
1267 | |||
1268 | static struct attribute *ib_dev_attrs[] = { | ||
1269 | &dev_attr_node_type.attr, | ||
1270 | &dev_attr_node_guid.attr, | ||
1271 | &dev_attr_sys_image_guid.attr, | ||
1272 | &dev_attr_fw_ver.attr, | ||
1273 | &dev_attr_node_desc.attr, | ||
1274 | NULL, | ||
1275 | }; | ||
1262 | 1276 | ||
1263 | static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL); | 1277 | static const struct attribute_group dev_attr_group = { |
1264 | static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL); | 1278 | .attrs = ib_dev_attrs, |
1265 | static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL); | ||
1266 | static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc); | ||
1267 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); | ||
1268 | |||
1269 | static struct device_attribute *ib_class_attributes[] = { | ||
1270 | &dev_attr_node_type, | ||
1271 | &dev_attr_sys_image_guid, | ||
1272 | &dev_attr_node_guid, | ||
1273 | &dev_attr_node_desc, | ||
1274 | &dev_attr_fw_ver, | ||
1275 | }; | 1279 | }; |
1276 | 1280 | ||
1277 | static void free_port_list_attributes(struct ib_device *device) | 1281 | static void free_port_list_attributes(struct ib_device *device) |
@@ -1311,16 +1315,13 @@ int ib_device_register_sysfs(struct ib_device *device, | |||
1311 | if (ret) | 1315 | if (ret) |
1312 | return ret; | 1316 | return ret; |
1313 | 1317 | ||
1318 | device->groups[0] = &dev_attr_group; | ||
1319 | class_dev->groups = device->groups; | ||
1320 | |||
1314 | ret = device_add(class_dev); | 1321 | ret = device_add(class_dev); |
1315 | if (ret) | 1322 | if (ret) |
1316 | goto err; | 1323 | goto err; |
1317 | 1324 | ||
1318 | for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) { | ||
1319 | ret = device_create_file(class_dev, ib_class_attributes[i]); | ||
1320 | if (ret) | ||
1321 | goto err_unregister; | ||
1322 | } | ||
1323 | |||
1324 | device->ports_parent = kobject_create_and_add("ports", | 1325 | device->ports_parent = kobject_create_and_add("ports", |
1325 | &class_dev->kobj); | 1326 | &class_dev->kobj); |
1326 | if (!device->ports_parent) { | 1327 | if (!device->ports_parent) { |
@@ -1347,18 +1348,13 @@ int ib_device_register_sysfs(struct ib_device *device, | |||
1347 | 1348 | ||
1348 | err_put: | 1349 | err_put: |
1349 | free_port_list_attributes(device); | 1350 | free_port_list_attributes(device); |
1350 | |||
1351 | err_unregister: | ||
1352 | device_del(class_dev); | 1351 | device_del(class_dev); |
1353 | |||
1354 | err: | 1352 | err: |
1355 | return ret; | 1353 | return ret; |
1356 | } | 1354 | } |
1357 | 1355 | ||
1358 | void ib_device_unregister_sysfs(struct ib_device *device) | 1356 | void ib_device_unregister_sysfs(struct ib_device *device) |
1359 | { | 1357 | { |
1360 | int i; | ||
1361 | |||
1362 | /* Hold device until ib_dealloc_device() */ | 1358 | /* Hold device until ib_dealloc_device() */ |
1363 | get_device(&device->dev); | 1359 | get_device(&device->dev); |
1364 | 1360 | ||
@@ -1369,8 +1365,5 @@ void ib_device_unregister_sysfs(struct ib_device *device) | |||
1369 | free_hsag(&device->dev.kobj, device->hw_stats_ag); | 1365 | free_hsag(&device->dev.kobj, device->hw_stats_ag); |
1370 | } | 1366 | } |
1371 | 1367 | ||
1372 | for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) | ||
1373 | device_remove_file(&device->dev, ib_class_attributes[i]); | ||
1374 | |||
1375 | device_unregister(&device->dev); | 1368 | device_unregister(&device->dev); |
1376 | } | 1369 | } |