[RFC/PATCH 13/22] W1: cleanup master attributes handling

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

 



W1: clean-up master attribute implementation:
    - drop unnecessary "w1_master" prefix from attribute names;
    - do not acquire master->mutex when accessing attributes;
    - move attribute code "closer" to the rest of master code.

Signed-off-by: Dmitry Torokhov <[email protected]>
---

 w1.c |  111 +++++++++++++++++++++++++------------------------------------------
 w1.h |    1 
 2 files changed, 44 insertions(+), 68 deletions(-)

Index: dtor/drivers/w1/w1.c
===================================================================
--- dtor.orig/drivers/w1/w1.c
+++ dtor/drivers/w1/w1.c
@@ -95,72 +95,6 @@ struct device w1_device = {
 	.release = &w1_master_release
 };
 
-static ssize_t w1_master_attribute_show_name(struct device *dev, char *buf)
-{
-	struct w1_master *md = container_of (dev, struct w1_master, dev);
-	ssize_t count;
-
-	if (down_interruptible (&md->mutex))
-		return -EBUSY;
-
-	count = sprintf(buf, "%s\n", md->name);
-
-	up(&md->mutex);
-
-	return count;
-}
-
-static ssize_t w1_master_attribute_show_timeout(struct device *dev, char *buf)
-{
-	ssize_t count;
-	count = sprintf(buf, "%d\n", w1_timeout);
-	return count;
-}
-
-static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, char *buf)
-{
-	struct w1_master *md = container_of(dev, struct w1_master, dev);
-	ssize_t count;
-
-	if (down_interruptible(&md->mutex))
-		return -EBUSY;
-
-	count = sprintf(buf, "%d\n", md->max_slave_count);
-
-	up(&md->mutex);
-	return count;
-}
-
-#define W1_MASTER_ATTR_RO(_name, _mode)				\
-	struct device_attribute w1_master_attribute_##_name =	\
-		__ATTR(w1_master_##_name, _mode,		\
-		       w1_master_attribute_show_##_name, NULL)
-
-static W1_MASTER_ATTR_RO(name, S_IRUGO);
-static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO);
-static W1_MASTER_ATTR_RO(timeout, S_IRUGO);
-
-static struct attribute *w1_master_default_attrs[] = {
-	&w1_master_attribute_name.attr,
-	&w1_master_attribute_max_slave_count.attr,
-	&w1_master_attribute_timeout.attr,
-	NULL
-};
-
-static struct attribute_group w1_master_defattr_group = {
-	.attrs = w1_master_default_attrs,
-};
-
-int w1_create_master_attributes(struct w1_master *master)
-{
-	return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group);
-}
-
-void w1_destroy_master_attributes(struct w1_master *master)
-{
-	sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group);
-}
-
 static ssize_t w1_slave_attribute_show_family(struct device *dev, char *buf)
 {
 	struct w1_slave *slave = to_w1_slave(dev);
@@ -460,6 +394,47 @@ static int w1_process(void *data)
 	return 0;
 }
 
+static ssize_t w1_master_attribute_show_name(struct device *dev, char *buf)
+{
+	struct w1_master *master = to_w1_master(dev);
+
+	return sprintf(buf, "%s\n", master->name);
+}
+
+static ssize_t w1_master_attribute_show_timeout(struct device *dev, char *buf)
+{
+	ssize_t count;
+	count = sprintf(buf, "%d\n", w1_timeout);
+	return count;
+}
+
+static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, char *buf)
+{
+	struct w1_master *master = to_w1_master(dev);
+
+	return sprintf(buf, "%d\n", master->max_slave_count);
+}
+
+#define W1_MASTER_ATTR_RO(_name, _mode)				\
+	struct device_attribute w1_master_attribute_##_name =	\
+		__ATTR(_name, _mode,				\
+		       w1_master_attribute_show_##_name, NULL)
+
+static W1_MASTER_ATTR_RO(name, S_IRUGO);
+static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO);
+static W1_MASTER_ATTR_RO(timeout, S_IRUGO);
+
+static struct attribute *w1_master_default_attrs[] = {
+	&w1_master_attribute_name.attr,
+	&w1_master_attribute_max_slave_count.attr,
+	&w1_master_attribute_timeout.attr,
+	NULL
+};
+
+static struct attribute_group w1_master_defattr_group = {
+	.attrs = w1_master_default_attrs,
+};
+
 struct w1_master *w1_allocate_master_device(void)
 {
 	struct w1_master *dev;
@@ -535,7 +510,7 @@ int w1_add_master_device(struct w1_maste
 		goto err_out_free_dev;
 	}
 
-	error = w1_create_master_attributes(dev);
+	error = sysfs_create_group(&dev->dev.kobj, &w1_master_defattr_group);
 	if (error)
 		goto err_out_kill_thread;
 
@@ -566,7 +541,7 @@ void w1_remove_master_device(struct w1_m
 		kfree(slave);
 	}
 
-	w1_destroy_master_attributes(dev);
+	sysfs_remove_group(&dev->dev.kobj, &w1_master_defattr_group);
 
 	while (atomic_read(&dev->refcnt)) {
 		printk(KERN_INFO "Waiting for %s to become free: refcnt=%d.\n",
Index: dtor/drivers/w1/w1.h
===================================================================
--- dtor.orig/drivers/w1/w1.h
+++ dtor/drivers/w1/w1.h
@@ -127,6 +127,7 @@ struct w1_master
 
 	u32			seq, groups;
 };
+#define to_w1_master(dev)	container_of((dev), struct w1_master, dev)
 
 struct w1_master *w1_allocate_master_device(void);
 int w1_add_master_device(struct w1_master *);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux