1 From 4a84eacedc55e78c8f64a5a4f9ade6e285844b85 Mon Sep 17 00:00:00 2001
2 From: Ioana Ciornei <ioana.ciornei@nxp.com>
3 Date: Mon, 25 Jun 2018 13:19:53 +0300
4 Subject: [PATCH] drivers/base: add sysfs entries for suppliers and consumers
6 Instead of scraping dmesg for messages such as 'Linked as a consumer to'
7 or 'Dropping the link to' export two new sysfs entries in the device
8 folder that list the consumer and supplier devices.
10 Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
12 Documentation/ABI/testing/sysfs-devices-links | 13 +++++++++
13 drivers/base/core.c | 42 +++++++++++++++++++++++++++
14 2 files changed, 55 insertions(+)
15 create mode 100644 Documentation/ABI/testing/sysfs-devices-links
18 +++ b/Documentation/ABI/testing/sysfs-devices-links
20 +What: /sys/devices/.../consumers
22 +Contact: Ioana Ciornei <ioana.ciornei@nxp.com>
24 + Read-only attribute that lists the current "consumers" of
27 +What: /sys/devices/.../suppliers
29 +Contact: Ioana Ciornei <ioana.ciornei@nxp.com>
31 + Read-only attribute that lists the current "suppliers" of
33 --- a/drivers/base/core.c
34 +++ b/drivers/base/core.c
35 @@ -1320,6 +1320,34 @@ static ssize_t online_store(struct devic
37 static DEVICE_ATTR_RW(online);
39 +static ssize_t suppliers_show(struct device *dev, struct device_attribute *attr,
42 + struct device_link *link;
45 + list_for_each_entry(link, &dev->links.suppliers, c_node)
46 + count += scnprintf(buf + count, PAGE_SIZE - count, "%s\n",
47 + dev_name(link->supplier));
51 +static DEVICE_ATTR_RO(suppliers);
53 +static ssize_t consumers_show(struct device *dev, struct device_attribute *attr,
56 + struct device_link *link;
59 + list_for_each_entry(link, &dev->links.consumers, s_node)
60 + count += scnprintf(buf + count, PAGE_SIZE - count, "%s\n",
61 + dev_name(link->consumer));
65 +static DEVICE_ATTR_RO(consumers);
67 int device_add_groups(struct device *dev, const struct attribute_group **groups)
69 return sysfs_create_groups(&dev->kobj, groups);
70 @@ -1491,8 +1519,20 @@ static int device_add_attrs(struct devic
71 goto err_remove_dev_groups;
74 + error = device_create_file(dev, &dev_attr_suppliers);
76 + goto err_remove_online;
78 + error = device_create_file(dev, &dev_attr_consumers);
80 + goto err_remove_suppliers;
84 + err_remove_suppliers:
85 + device_remove_file(dev, &dev_attr_suppliers);
87 + device_remove_file(dev, &dev_attr_online);
88 err_remove_dev_groups:
89 device_remove_groups(dev, dev->groups);
90 err_remove_type_groups:
91 @@ -1510,6 +1550,8 @@ static void device_remove_attrs(struct d
92 struct class *class = dev->class;
93 const struct device_type *type = dev->type;
95 + device_remove_file(dev, &dev_attr_consumers);
96 + device_remove_file(dev, &dev_attr_suppliers);
97 device_remove_file(dev, &dev_attr_online);
98 device_remove_groups(dev, dev->groups);