Commit 99c5bfe9 authored by Evgeniy Polyakov's avatar Evgeniy Polyakov Committed by Greg Kroah-Hartman

[PATCH] w1: Adds a default family so that new slave families will show up in sysfs.

Adds a default family so that new slave families will show up in sysfs.
Signed-off-by: default avatarBen Gardner <bgardner@wabtec.com>
Signed-off-by: default avatarEvgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 2a9d0c17
...@@ -59,6 +59,19 @@ static pid_t control_thread; ...@@ -59,6 +59,19 @@ static pid_t control_thread;
static int control_needs_exit; static int control_needs_exit;
static DECLARE_COMPLETION(w1_control_complete); static DECLARE_COMPLETION(w1_control_complete);
/* stuff for the default family */
static ssize_t w1_famdefault_read_name(struct device *dev, struct device_attribute *attr, char *buf)
{
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
return(sprintf(buf, "%s\n", sl->name));
}
static struct w1_family_ops w1_default_fops = {
.rname = &w1_famdefault_read_name,
};
static struct w1_family w1_default_family = {
.fops = &w1_default_fops,
};
static int w1_master_match(struct device *dev, struct device_driver *drv) static int w1_master_match(struct device *dev, struct device_driver *drv)
{ {
return 1; return 1;
...@@ -360,14 +373,16 @@ static int __w1_attach_slave_device(struct w1_slave *sl) ...@@ -360,14 +373,16 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
return err; return err;
} }
err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin); if ( sl->attr_bin.read ) {
if (err < 0) { err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin);
dev_err(&sl->dev, if (err < 0) {
"sysfs file creation for [%s] failed. err=%d\n", dev_err(&sl->dev,
sl->dev.bus_id, err); "sysfs file creation for [%s] failed. err=%d\n",
device_remove_file(&sl->dev, &sl->attr_name); sl->dev.bus_id, err);
device_unregister(&sl->dev); device_remove_file(&sl->dev, &sl->attr_name);
return err; device_unregister(&sl->dev);
return err;
}
} }
list_add_tail(&sl->w1_slave_entry, &sl->master->slist); list_add_tail(&sl->w1_slave_entry, &sl->master->slist);
...@@ -403,12 +418,10 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) ...@@ -403,12 +418,10 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
spin_lock(&w1_flock); spin_lock(&w1_flock);
f = w1_family_registered(rn->family); f = w1_family_registered(rn->family);
if (!f) { if (!f) {
spin_unlock(&w1_flock); f= &w1_default_family;
dev_info(&dev->dev, "Family %x for %02x.%012llx.%02x is not registered.\n", dev_info(&dev->dev, "Family %x for %02x.%012llx.%02x is not registered.\n",
rn->family, rn->family, rn->family, rn->family,
(unsigned long long)rn->id, rn->crc); (unsigned long long)rn->id, rn->crc);
kfree(sl);
return -ENODEV;
} }
__w1_family_get(f); __w1_family_get(f);
spin_unlock(&w1_flock); spin_unlock(&w1_flock);
...@@ -449,7 +462,9 @@ static void w1_slave_detach(struct w1_slave *sl) ...@@ -449,7 +462,9 @@ static void w1_slave_detach(struct w1_slave *sl)
flush_signals(current); flush_signals(current);
} }
sysfs_remove_bin_file (&sl->dev.kobj, &sl->attr_bin); if ( sl->attr_bin.read ) {
sysfs_remove_bin_file (&sl->dev.kobj, &sl->attr_bin);
}
device_remove_file(&sl->dev, &sl->attr_name); device_remove_file(&sl->dev, &sl->attr_name);
device_unregister(&sl->dev); device_unregister(&sl->dev);
w1_family_put(sl->family); w1_family_put(sl->family);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment