w1: slaves: w1_ds28e04: convert to use w1_family_ops.groups

This moves the sysfs file creation/removal to the w1 core by using the
.groups field, saving code in the slave driver.

Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Alexander Stein <alexander.stein@informatik.tu-chemnitz.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Greg Kroah-Hartman 2013-08-21 15:45:02 -07:00
parent 38f40982e1
commit fa33a65a9c

View File

@ -118,9 +118,9 @@ static int w1_f1C_read(struct w1_slave *sl, int addr, int len, char *data)
return w1_read_block(sl->master, data, len); return w1_read_block(sl->master, data, len);
} }
static ssize_t w1_f1C_read_bin(struct file *filp, struct kobject *kobj, static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, struct bin_attribute *bin_attr, char *buf,
char *buf, loff_t off, size_t count) loff_t off, size_t count)
{ {
struct w1_slave *sl = kobj_to_w1_slave(kobj); struct w1_slave *sl = kobj_to_w1_slave(kobj);
struct w1_f1C_data *data = sl->family_data; struct w1_f1C_data *data = sl->family_data;
@ -226,9 +226,9 @@ static int w1_f1C_write(struct w1_slave *sl, int addr, int len, const u8 *data)
return 0; return 0;
} }
static ssize_t w1_f1C_write_bin(struct file *filp, struct kobject *kobj, static ssize_t eeprom_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, struct bin_attribute *bin_attr, char *buf,
char *buf, loff_t off, size_t count) loff_t off, size_t count)
{ {
struct w1_slave *sl = kobj_to_w1_slave(kobj); struct w1_slave *sl = kobj_to_w1_slave(kobj);
@ -280,9 +280,11 @@ out_up:
return count; return count;
} }
static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj, static BIN_ATTR_RW(eeprom, W1_EEPROM_SIZE);
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count) static ssize_t pio_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf, loff_t off,
size_t count)
{ {
struct w1_slave *sl = kobj_to_w1_slave(kobj); struct w1_slave *sl = kobj_to_w1_slave(kobj);
@ -299,9 +301,9 @@ static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj,
return ret; return ret;
} }
static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj, static ssize_t pio_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, struct bin_attribute *bin_attr, char *buf, loff_t off,
char *buf, loff_t off, size_t count) size_t count)
{ {
struct w1_slave *sl = kobj_to_w1_slave(kobj); struct w1_slave *sl = kobj_to_w1_slave(kobj);
@ -339,8 +341,10 @@ static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj,
return count; return count;
} }
static ssize_t w1_f1C_show_crccheck(struct device *dev, static BIN_ATTR_RW(pio, 1);
struct device_attribute *attr, char *buf)
static ssize_t crccheck_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
if (put_user(w1_enable_crccheck + 0x30, buf)) if (put_user(w1_enable_crccheck + 0x30, buf))
return -EFAULT; return -EFAULT;
@ -348,9 +352,8 @@ static ssize_t w1_f1C_show_crccheck(struct device *dev,
return sizeof(w1_enable_crccheck); return sizeof(w1_enable_crccheck);
} }
static ssize_t w1_f1C_store_crccheck(struct device *dev, static ssize_t crccheck_store(struct device *dev, struct device_attribute *attr,
struct device_attribute *attr, const char *buf, size_t count)
const char *buf, size_t count)
{ {
char val; char val;
@ -371,35 +374,31 @@ static ssize_t w1_f1C_store_crccheck(struct device *dev,
return sizeof(w1_enable_crccheck); return sizeof(w1_enable_crccheck);
} }
#define NB_SYSFS_BIN_FILES 2 static DEVICE_ATTR_RW(crccheck);
static struct bin_attribute w1_f1C_bin_attr[NB_SYSFS_BIN_FILES] = {
{ static struct attribute *w1_f1C_attrs[] = {
.attr = { &dev_attr_crccheck.attr,
.name = "eeprom", NULL,
.mode = S_IRUGO | S_IWUSR,
},
.size = W1_EEPROM_SIZE,
.read = w1_f1C_read_bin,
.write = w1_f1C_write_bin,
},
{
.attr = {
.name = "pio",
.mode = S_IRUGO | S_IWUSR,
},
.size = 1,
.read = w1_f1C_read_pio,
.write = w1_f1C_write_pio,
}
}; };
static DEVICE_ATTR(crccheck, S_IWUSR | S_IRUGO, static struct bin_attribute *w1_f1C_bin_attrs[] = {
w1_f1C_show_crccheck, w1_f1C_store_crccheck); &bin_attr_eeprom,
&bin_attr_pio,
NULL,
};
static const struct attribute_group w1_f1C_group = {
.attrs = w1_f1C_attrs,
.bin_attrs = w1_f1C_bin_attrs,
};
static const struct attribute_group *w1_f1C_groups[] = {
&w1_f1C_group,
NULL,
};
static int w1_f1C_add_slave(struct w1_slave *sl) static int w1_f1C_add_slave(struct w1_slave *sl)
{ {
int err = 0;
int i;
struct w1_f1C_data *data = NULL; struct w1_f1C_data *data = NULL;
if (w1_enable_crccheck) { if (w1_enable_crccheck) {
@ -409,46 +408,19 @@ static int w1_f1C_add_slave(struct w1_slave *sl)
sl->family_data = data; sl->family_data = data;
} }
/* create binary sysfs attributes */ return 0;
for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i)
err = sysfs_create_bin_file(
&sl->dev.kobj, &(w1_f1C_bin_attr[i]));
if (!err) {
/* create device attributes */
err = device_create_file(&sl->dev, &dev_attr_crccheck);
}
if (err) {
/* remove binary sysfs attributes */
for (i = 0; i < NB_SYSFS_BIN_FILES; ++i)
sysfs_remove_bin_file(
&sl->dev.kobj, &(w1_f1C_bin_attr[i]));
kfree(data);
}
return err;
} }
static void w1_f1C_remove_slave(struct w1_slave *sl) static void w1_f1C_remove_slave(struct w1_slave *sl)
{ {
int i;
kfree(sl->family_data); kfree(sl->family_data);
sl->family_data = NULL; sl->family_data = NULL;
/* remove device attributes */
device_remove_file(&sl->dev, &dev_attr_crccheck);
/* remove binary sysfs attributes */
for (i = 0; i < NB_SYSFS_BIN_FILES; ++i)
sysfs_remove_bin_file(&sl->dev.kobj, &(w1_f1C_bin_attr[i]));
} }
static struct w1_family_ops w1_f1C_fops = { static struct w1_family_ops w1_f1C_fops = {
.add_slave = w1_f1C_add_slave, .add_slave = w1_f1C_add_slave,
.remove_slave = w1_f1C_remove_slave, .remove_slave = w1_f1C_remove_slave,
.groups = w1_f1C_groups,
}; };
static struct w1_family w1_family_1C = { static struct w1_family w1_family_1C = {