| From foo@baz Sat Jul 6 17:21:15 PDT 2013 |
| Date: Sat, 06 Jul 2013 17:21:15 -0700 |
| To: Greg KH <gregkh@linuxfoundation.org> |
| From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| Subject: driver core: add binary attributes to struct device |
| |
| From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| |
| This lets a device provide a set of default binary attributes, like |
| normal attributes, that are initialized and torn down by the driver core |
| at the proper times, so that there are no races with userspace. |
| |
| |
| Reported-by: Oliver Schinagl <oliver+list@schinagl.nl> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| |
| |
| --- |
| drivers/base/core.c | 7 +++++++ |
| include/linux/device.h | 2 ++ |
| 2 files changed, 9 insertions(+) |
| |
| --- a/drivers/base/core.c |
| +++ b/drivers/base/core.c |
| @@ -491,8 +491,14 @@ static int device_add_attrs(struct devic |
| goto err_remove_type_groups; |
| } |
| |
| + error = device_add_bin_attributes(dev, dev->bin_attrs); |
| + if (error) |
| + goto err_remove_groups; |
| return 0; |
| |
| + err_remove_groups: |
| + device_remove_groups(dev, dev->groups); |
| + |
| err_remove_type_groups: |
| if (type) |
| device_remove_groups(dev, type->groups); |
| @@ -510,6 +516,7 @@ static void device_remove_attrs(struct d |
| |
| device_remove_file(dev, &online_attr); |
| device_remove_groups(dev, dev->groups); |
| + device_remove_bin_attributes(dev, dev->bin_attrs); |
| |
| if (type) |
| device_remove_groups(dev, type->groups); |
| --- a/include/linux/device.h |
| +++ b/include/linux/device.h |
| @@ -656,6 +656,7 @@ struct acpi_dev_node { |
| * @knode_class: The node used to add the device to the class list. |
| * @class: The class of the device. |
| * @groups: Optional attribute groups. |
| + * @bin_attrs: Optional binary attributes for this device. |
| * @release: Callback to free the device after all references have |
| * gone away. This should be set by the allocator of the |
| * device (i.e. the bus driver that discovered the device). |
| @@ -732,6 +733,7 @@ struct device { |
| struct klist_node knode_class; |
| struct class *class; |
| const struct attribute_group **groups; /* optional groups */ |
| + const struct bin_attribute *bin_attrs; |
| |
| void (*release)(struct device *dev); |
| struct iommu_group *iommu_group; |