Loading Documentation/filesystems/sysfs.txt +14 −14 Original line number Diff line number Diff line Loading @@ -99,14 +99,14 @@ struct device_attribute dev_attr_##_name = { \ For example, declaring static DEVICE_ATTR(foo,0644,show_foo,store_foo); static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo); is equivalent to doing: static struct device_attribute dev_attr_foo = { .attr = { .name = "foo", .mode = 0644, .mode = S_IWUSR | S_IRUGO, }, .show = show_foo, .store = store_foo, Loading Loading @@ -216,13 +216,13 @@ A very simple (and naive) implementation of a device attribute is: static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf,"%s\n",dev->name); return snprintf(buf, PAGE_SIZE, "%s\n", dev->name); } static ssize_t store_name(struct device * dev, const char * buf) { sscanf(buf, "%20s", dev->name); return strlen(buf); return strnlen(buf, PAGE_SIZE); } static DEVICE_ATTR(name, S_IRUGO, show_name, store_name); Loading drivers/base/bus.c +5 −3 Original line number Diff line number Diff line Loading @@ -156,7 +156,9 @@ static ssize_t driver_unbind(struct device_driver *drv, device_release_driver(dev); err = count; } if (err) return err; return count; } static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); Loading Loading @@ -358,7 +360,7 @@ int bus_add_device(struct device * dev) if (bus) { pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); device_attach(dev); klist_add_tail(&bus->klist_devices, &dev->knode_bus); klist_add_tail(&dev->knode_bus, &bus->klist_devices); error = device_add_attrs(bus, dev); if (!error) { sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); Loading Loading @@ -446,7 +448,7 @@ int bus_add_driver(struct device_driver * drv) } driver_attach(drv); klist_add_tail(&bus->klist_drivers, &drv->knode_bus); klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); driver_add_attrs(bus, drv); Loading drivers/base/class.c +33 −6 Original line number Diff line number Diff line Loading @@ -299,10 +299,8 @@ static void class_dev_release(struct kobject * kobj) pr_debug("device class '%s': release.\n", cd->class_id); if (cd->devt_attr) { kfree(cd->devt_attr); cd->devt_attr = NULL; } if (cls->release) cls->release(cd); Loading Loading @@ -452,10 +450,29 @@ void class_device_initialize(struct class_device *class_dev) INIT_LIST_HEAD(&class_dev->node); } static char *make_class_name(struct class_device *class_dev) { char *name; int size; size = strlen(class_dev->class->name) + strlen(kobject_name(&class_dev->kobj)) + 2; name = kmalloc(size, GFP_KERNEL); if (!name) return ERR_PTR(-ENOMEM); strcpy(name, class_dev->class->name); strcat(name, ":"); strcat(name, kobject_name(&class_dev->kobj)); return name; } int class_device_add(struct class_device *class_dev) { struct class * parent = NULL; struct class_interface * class_intf; char *class_name = NULL; int error; class_dev = class_device_get(class_dev); Loading Loading @@ -500,9 +517,13 @@ int class_device_add(struct class_device *class_dev) } class_device_add_attrs(class_dev); if (class_dev->dev) if (class_dev->dev) { class_name = make_class_name(class_dev); sysfs_create_link(&class_dev->kobj, &class_dev->dev->kobj, "device"); sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, class_name); } /* notify any interfaces this device is now here */ if (parent) { Loading @@ -519,6 +540,7 @@ int class_device_add(struct class_device *class_dev) if (error && parent) class_put(parent); class_device_put(class_dev); kfree(class_name); return error; } Loading Loading @@ -584,6 +606,7 @@ void class_device_del(struct class_device *class_dev) { struct class * parent = class_dev->class; struct class_interface * class_intf; char *class_name = NULL; if (parent) { down(&parent->sem); Loading @@ -594,8 +617,11 @@ void class_device_del(struct class_device *class_dev) up(&parent->sem); } if (class_dev->dev) if (class_dev->dev) { class_name = make_class_name(class_dev); sysfs_remove_link(&class_dev->kobj, "device"); sysfs_remove_link(&class_dev->dev->kobj, class_name); } if (class_dev->devt_attr) class_device_remove_file(class_dev, class_dev->devt_attr); class_device_remove_attrs(class_dev); Loading @@ -605,6 +631,7 @@ void class_device_del(struct class_device *class_dev) if (parent) class_put(parent); kfree(class_name); } void class_device_unregister(struct class_device *class_dev) Loading drivers/base/core.c +1 −1 Original line number Diff line number Diff line Loading @@ -249,7 +249,7 @@ int device_add(struct device *dev) if ((error = bus_add_device(dev))) goto BusError; if (parent) klist_add_tail(&parent->klist_children, &dev->knode_parent); klist_add_tail(&dev->knode_parent, &parent->klist_children); /* notify platform of device entry */ if (platform_notify) Loading drivers/base/dd.c +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ void device_bind_driver(struct device * dev) { pr_debug("bound device '%s' to driver '%s'\n", dev->bus_id, dev->driver->name); klist_add_tail(&dev->driver->klist_devices, &dev->knode_driver); klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); sysfs_create_link(&dev->driver->kobj, &dev->kobj, kobject_name(&dev->kobj)); sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); Loading Loading
Documentation/filesystems/sysfs.txt +14 −14 Original line number Diff line number Diff line Loading @@ -99,14 +99,14 @@ struct device_attribute dev_attr_##_name = { \ For example, declaring static DEVICE_ATTR(foo,0644,show_foo,store_foo); static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo); is equivalent to doing: static struct device_attribute dev_attr_foo = { .attr = { .name = "foo", .mode = 0644, .mode = S_IWUSR | S_IRUGO, }, .show = show_foo, .store = store_foo, Loading Loading @@ -216,13 +216,13 @@ A very simple (and naive) implementation of a device attribute is: static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf,"%s\n",dev->name); return snprintf(buf, PAGE_SIZE, "%s\n", dev->name); } static ssize_t store_name(struct device * dev, const char * buf) { sscanf(buf, "%20s", dev->name); return strlen(buf); return strnlen(buf, PAGE_SIZE); } static DEVICE_ATTR(name, S_IRUGO, show_name, store_name); Loading
drivers/base/bus.c +5 −3 Original line number Diff line number Diff line Loading @@ -156,7 +156,9 @@ static ssize_t driver_unbind(struct device_driver *drv, device_release_driver(dev); err = count; } if (err) return err; return count; } static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); Loading Loading @@ -358,7 +360,7 @@ int bus_add_device(struct device * dev) if (bus) { pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); device_attach(dev); klist_add_tail(&bus->klist_devices, &dev->knode_bus); klist_add_tail(&dev->knode_bus, &bus->klist_devices); error = device_add_attrs(bus, dev); if (!error) { sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); Loading Loading @@ -446,7 +448,7 @@ int bus_add_driver(struct device_driver * drv) } driver_attach(drv); klist_add_tail(&bus->klist_drivers, &drv->knode_bus); klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); driver_add_attrs(bus, drv); Loading
drivers/base/class.c +33 −6 Original line number Diff line number Diff line Loading @@ -299,10 +299,8 @@ static void class_dev_release(struct kobject * kobj) pr_debug("device class '%s': release.\n", cd->class_id); if (cd->devt_attr) { kfree(cd->devt_attr); cd->devt_attr = NULL; } if (cls->release) cls->release(cd); Loading Loading @@ -452,10 +450,29 @@ void class_device_initialize(struct class_device *class_dev) INIT_LIST_HEAD(&class_dev->node); } static char *make_class_name(struct class_device *class_dev) { char *name; int size; size = strlen(class_dev->class->name) + strlen(kobject_name(&class_dev->kobj)) + 2; name = kmalloc(size, GFP_KERNEL); if (!name) return ERR_PTR(-ENOMEM); strcpy(name, class_dev->class->name); strcat(name, ":"); strcat(name, kobject_name(&class_dev->kobj)); return name; } int class_device_add(struct class_device *class_dev) { struct class * parent = NULL; struct class_interface * class_intf; char *class_name = NULL; int error; class_dev = class_device_get(class_dev); Loading Loading @@ -500,9 +517,13 @@ int class_device_add(struct class_device *class_dev) } class_device_add_attrs(class_dev); if (class_dev->dev) if (class_dev->dev) { class_name = make_class_name(class_dev); sysfs_create_link(&class_dev->kobj, &class_dev->dev->kobj, "device"); sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, class_name); } /* notify any interfaces this device is now here */ if (parent) { Loading @@ -519,6 +540,7 @@ int class_device_add(struct class_device *class_dev) if (error && parent) class_put(parent); class_device_put(class_dev); kfree(class_name); return error; } Loading Loading @@ -584,6 +606,7 @@ void class_device_del(struct class_device *class_dev) { struct class * parent = class_dev->class; struct class_interface * class_intf; char *class_name = NULL; if (parent) { down(&parent->sem); Loading @@ -594,8 +617,11 @@ void class_device_del(struct class_device *class_dev) up(&parent->sem); } if (class_dev->dev) if (class_dev->dev) { class_name = make_class_name(class_dev); sysfs_remove_link(&class_dev->kobj, "device"); sysfs_remove_link(&class_dev->dev->kobj, class_name); } if (class_dev->devt_attr) class_device_remove_file(class_dev, class_dev->devt_attr); class_device_remove_attrs(class_dev); Loading @@ -605,6 +631,7 @@ void class_device_del(struct class_device *class_dev) if (parent) class_put(parent); kfree(class_name); } void class_device_unregister(struct class_device *class_dev) Loading
drivers/base/core.c +1 −1 Original line number Diff line number Diff line Loading @@ -249,7 +249,7 @@ int device_add(struct device *dev) if ((error = bus_add_device(dev))) goto BusError; if (parent) klist_add_tail(&parent->klist_children, &dev->knode_parent); klist_add_tail(&dev->knode_parent, &parent->klist_children); /* notify platform of device entry */ if (platform_notify) Loading
drivers/base/dd.c +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ void device_bind_driver(struct device * dev) { pr_debug("bound device '%s' to driver '%s'\n", dev->bus_id, dev->driver->name); klist_add_tail(&dev->driver->klist_devices, &dev->knode_driver); klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); sysfs_create_link(&dev->driver->kobj, &dev->kobj, kobject_name(&dev->kobj)); sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); Loading