[PATCH 115/141] staging: unisys: Wire up proper device attr for bus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Don Zickus <dzickus@xxxxxxxxxx>

This patch moves the attributes to underneath the bus device correctly.
This will help remove a bunch of cruft from the code and let the kernel
infrastructure manage the sysfs files instead of the driver.

Signed-off-by: Don Zickus <dzickus@xxxxxxxxxx>
Signed-off-by: Benjamin Romer <benjamin.romer@xxxxxxxxxx>
---
 drivers/staging/unisys/visorbus/visorbus_main.c | 75 +++++++++++++++++++------
 1 file changed, 58 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c
index 1266259..6204105 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -659,7 +659,7 @@ struct businst_attribute {
 #define to_businst_attr(_attr) \
 	container_of(_attr, struct businst_attribute, attr)
 #define to_visorbus_devdata(obj) \
-	container_of(obj, struct visorbus_devdata, kobj)
+	container_of(obj, struct visorbus_devdata, dev)
 
 static ssize_t
 businst_attr_show(struct kobject *kobj, struct attribute *attr,
@@ -774,8 +774,10 @@ unregister_bustype_attributes(void)
  *
  */
 
-static ssize_t businst_attr_partition_handle(struct visorbus_devdata *businst,
-					     char *buf) {
+static ssize_t partition_handle_show(struct device *dev,
+				     struct device_attribute *attr,
+				     char *buf) {
+	struct visorbus_devdata *businst = to_visorbus_devdata(dev);
 	struct visorchipset_bus_info bus_info;
 	int len = 0;
 
@@ -786,8 +788,10 @@ static ssize_t businst_attr_partition_handle(struct visorbus_devdata *businst,
 	return len;
 }
 
-static ssize_t businst_attr_partition_guid(struct visorbus_devdata *businst,
-					   char *buf) {
+static ssize_t partition_guid_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buf) {
+	struct visorbus_devdata *businst = to_visorbus_devdata(dev);
 	struct visorchipset_bus_info bus_info;
 	int len = 0;
 
@@ -797,8 +801,10 @@ static ssize_t businst_attr_partition_guid(struct visorbus_devdata *businst,
 	return len;
 }
 
-static ssize_t businst_attr_partition_name(struct visorbus_devdata *businst,
-					   char *buf) {
+static ssize_t partition_name_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buf) {
+	struct visorbus_devdata *businst = to_visorbus_devdata(dev);
 	struct visorchipset_bus_info bus_info;
 	int len = 0;
 
@@ -809,8 +815,10 @@ static ssize_t businst_attr_partition_name(struct visorbus_devdata *businst,
 	return len;
 }
 
-static ssize_t businst_attr_channel_addr(struct visorbus_devdata *businst,
-					 char *buf) {
+static ssize_t channel_addr_show(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf) {
+	struct visorbus_devdata *businst = to_visorbus_devdata(dev);
 	struct visorchipset_bus_info bus_info;
 	int len = 0;
 
@@ -820,8 +828,10 @@ static ssize_t businst_attr_channel_addr(struct visorbus_devdata *businst,
 	return len;
 }
 
-static ssize_t businst_attr_nchannel_bytes(struct visorbus_devdata *businst,
-					   char *buf) {
+static ssize_t channel_bytes_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf) {
+	struct visorbus_devdata *businst = to_visorbus_devdata(dev);
 	struct visorchipset_bus_info bus_info;
 	int len = 0;
 
@@ -831,8 +841,10 @@ static ssize_t businst_attr_nchannel_bytes(struct visorbus_devdata *businst,
 	return len;
 }
 
-static ssize_t businst_attr_channel_id(struct visorbus_devdata *businst,
-				       char *buf) {
+static ssize_t channel_id_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buf) {
+	struct visorbus_devdata *businst = to_visorbus_devdata(dev);
 	int len = 0;
 
 	if (businst && businst->chan) {
@@ -843,8 +855,10 @@ static ssize_t businst_attr_channel_id(struct visorbus_devdata *businst,
 	return len;
 }
 
-static ssize_t businst_attr_client_bus_info(struct visorbus_devdata *businst,
-					    char *buf) {
+static ssize_t client_bus_info_show(struct device *dev,
+				    struct device_attribute *attr,
+				    char *buf) {
+	struct visorbus_devdata *businst = to_visorbus_devdata(dev);
 	struct visorchipset_bus_info bus_info;
 	int i, x, remain = PAGE_SIZE;
 	unsigned long off;
@@ -918,6 +932,34 @@ static struct businst_attribute ba_channel_id =
 static struct businst_attribute ba_client_bus_info =
 	__ATTR(client_bus_info, S_IRUGO, businst_attr_client_bus_info, NULL);
 
+static DEVICE_ATTR_RO(partition_handle);
+static DEVICE_ATTR_RO(partition_guid);
+static DEVICE_ATTR_RO(partition_name);
+static DEVICE_ATTR_RO(channel_addr);
+static DEVICE_ATTR_RO(channel_bytes);
+static DEVICE_ATTR_RO(channel_id);
+static DEVICE_ATTR_RO(client_bus_info);
+
+static struct attribute *dev_attrs[] = {
+		&dev_attr_partition_handle.attr,
+		&dev_attr_partition_guid.attr,
+		&dev_attr_partition_name.attr,
+		&dev_attr_channel_addr.attr,
+		&dev_attr_channel_bytes.attr,
+		&dev_attr_channel_id.attr,
+		&dev_attr_client_bus_info.attr,
+		NULL
+};
+
+static struct attribute_group dev_attr_grp = {
+		.attrs = dev_attrs,
+};
+
+static const struct attribute_group *visorbus_groups[] = {
+		&dev_attr_grp,
+		NULL
+};
+
 static int
 register_businst_attributes(struct visorbus_devdata *businst)
 {
@@ -1646,6 +1688,7 @@ create_bus_instance(int id)
 		goto away;
 	}
 	dev_set_name(&devdata->dev, "visorbus%d", id);
+	devdata->dev.groups = visorbus_groups;
 	devdata->dev.release = visorbus_release_busdevice;
 	if (device_register(&devdata->dev) < 0) {
 		POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, id,
@@ -1692,7 +1735,6 @@ create_bus_instance(int id)
 			}
 		}
 	}
-	register_businst_attributes(devdata);
 	bus_count++;
 	list_add_tail(&devdata->list_all, &list_all_bus_instances);
 	if (id == 0)
@@ -1715,7 +1757,6 @@ remove_bus_instance(struct visorbus_devdata *devdata)
 	 * successfully been able to trace thru the code to see where/how
 	 * release() gets called.  But I know it does.
 	 */
-	unregister_businst_attributes(devdata);
 	bus_count--;
 	if (devdata->chan) {
 		visorchannel_destroy(devdata->chan);
-- 
2.1.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux