Commit 5b187b3c authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

w1: use default attribute groups for w1 slave devices



As we have 2 sysfs files for the w1 slave devices, let the driver core
create / destroy them automatically by setting the default attribute
group for them, saving code and housekeeping logic.

Acked-by: default avatarEvgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 47eba33a
Loading
Loading
Loading
Loading
+11 −27
Original line number Original line Diff line number Diff line
@@ -96,14 +96,15 @@ static void w1_slave_release(struct device *dev)
	complete(&sl->released);
	complete(&sl->released);
}
}


static ssize_t w1_slave_read_name(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf)
{
{
	struct w1_slave *sl = dev_to_w1_slave(dev);
	struct w1_slave *sl = dev_to_w1_slave(dev);


	return sprintf(buf, "%s\n", sl->name);
	return sprintf(buf, "%s\n", sl->name);
}
}
static DEVICE_ATTR_RO(name);


static ssize_t w1_slave_read_id(struct device *dev,
static ssize_t id_show(struct device *dev,
	struct device_attribute *attr, char *buf)
	struct device_attribute *attr, char *buf)
{
{
	struct w1_slave *sl = dev_to_w1_slave(dev);
	struct w1_slave *sl = dev_to_w1_slave(dev);
@@ -112,11 +113,14 @@ static ssize_t w1_slave_read_id(struct device *dev,
	memcpy(buf, (u8 *)&sl->reg_num, count);
	memcpy(buf, (u8 *)&sl->reg_num, count);
	return count;
	return count;
}
}
static DEVICE_ATTR_RO(id);


static struct device_attribute w1_slave_attr_name =
static struct attribute *w1_slave_attrs[] = {
	__ATTR(name, S_IRUGO, w1_slave_read_name, NULL);
	&dev_attr_name.attr,
static struct device_attribute w1_slave_attr_id =
	&dev_attr_id.attr,
	__ATTR(id, S_IRUGO, w1_slave_read_id, NULL);
	NULL,
};
ATTRIBUTE_GROUPS(w1_slave);


/* Default family */
/* Default family */


@@ -610,25 +614,6 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action,


	switch (action) {
	switch (action) {
	case BUS_NOTIFY_ADD_DEVICE:
	case BUS_NOTIFY_ADD_DEVICE:
		/* Create our sysfs files before userspace is told about it */
		/* Create "name" entry */
		err = device_create_file(&sl->dev, &w1_slave_attr_name);
		if (err < 0) {
			dev_err(&sl->dev,
				"sysfs file creation for [%s] failed. err=%d\n",
				dev_name(&sl->dev), err);
			return err;
		}

		/* Create "id" entry */
		err = device_create_file(&sl->dev, &w1_slave_attr_id);
		if (err < 0) {
			dev_err(&sl->dev,
				"sysfs file creation for [%s] failed. err=%d\n",
				dev_name(&sl->dev), err);
			return err;
		}

		/* if the family driver needs to initialize something... */
		/* if the family driver needs to initialize something... */
		if (sl->family->fops && sl->family->fops->add_slave &&
		if (sl->family->fops && sl->family->fops->add_slave &&
		    ((err = sl->family->fops->add_slave(sl)) < 0)) {
		    ((err = sl->family->fops->add_slave(sl)) < 0)) {
@@ -643,8 +628,6 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action,
		/* Remove our sysfs files */
		/* Remove our sysfs files */
		if (sl->family->fops && sl->family->fops->remove_slave)
		if (sl->family->fops && sl->family->fops->remove_slave)
			sl->family->fops->remove_slave(sl);
			sl->family->fops->remove_slave(sl);
		device_remove_file(&sl->dev, &w1_slave_attr_id);
		device_remove_file(&sl->dev, &w1_slave_attr_name);
		break;
		break;
	}
	}
	return 0;
	return 0;
@@ -662,6 +645,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
	sl->dev.driver = &w1_slave_driver;
	sl->dev.driver = &w1_slave_driver;
	sl->dev.bus = &w1_bus_type;
	sl->dev.bus = &w1_bus_type;
	sl->dev.release = &w1_slave_release;
	sl->dev.release = &w1_slave_release;
	sl->dev.groups = w1_slave_groups;


	dev_set_name(&sl->dev, "%02x-%012llx",
	dev_set_name(&sl->dev, "%02x-%012llx",
		 (unsigned int) sl->reg_num.family,
		 (unsigned int) sl->reg_num.family,