All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/base: add sysfs entries for suppliers and consumers
@ 2018-07-05 16:00 Ioana Ciornei
  2018-07-05 16:05 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Ioana Ciornei @ 2018-07-05 16:00 UTC (permalink / raw)
  To: gregkh, rjw, linux-kernel; +Cc: vivek.gautam, Ioana Ciornei

Instead of scraping dmesg for messages such as 'Linked as a consumer to'
or 'Dropping the link to' export two new sysfs entries in the device
folder that list the consumer and supplier devices.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/base/core.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index df3e1a4..6d245f7 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1055,6 +1055,34 @@ static ssize_t online_store(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RW(online);
 
+static ssize_t suppliers_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct device_link *link;
+	size_t count = 0;
+
+	list_for_each_entry(link, &dev->links.suppliers, c_node)
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%s\n",
+				   dev_name(link->supplier));
+
+	return count;
+}
+static DEVICE_ATTR_RO(suppliers);
+
+static ssize_t consumers_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct device_link *link;
+	size_t count = 0;
+
+	list_for_each_entry(link, &dev->links.consumers, s_node)
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%s\n",
+				   dev_name(link->consumer));
+
+	return count;
+}
+static DEVICE_ATTR_RO(consumers);
+
 int device_add_groups(struct device *dev, const struct attribute_group **groups)
 {
 	return sysfs_create_groups(&dev->kobj, groups);
@@ -1226,8 +1254,20 @@ static int device_add_attrs(struct device *dev)
 			goto err_remove_dev_groups;
 	}
 
+	error = device_create_file(dev, &dev_attr_suppliers);
+	if (error)
+		goto err_remove_online;
+
+	error = device_create_file(dev, &dev_attr_consumers);
+	if (error)
+		goto err_remove_suppliers;
+
 	return 0;
 
+ err_remove_suppliers:
+	device_remove_file(dev, &dev_attr_suppliers);
+ err_remove_online:
+	device_remove_file(dev, &dev_attr_online);
  err_remove_dev_groups:
 	device_remove_groups(dev, dev->groups);
  err_remove_type_groups:
@@ -1245,6 +1285,8 @@ static void device_remove_attrs(struct device *dev)
 	struct class *class = dev->class;
 	const struct device_type *type = dev->type;
 
+	device_remove_file(dev, &dev_attr_consumers);
+	device_remove_file(dev, &dev_attr_suppliers);
 	device_remove_file(dev, &dev_attr_online);
 	device_remove_groups(dev, dev->groups);
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers/base: add sysfs entries for suppliers and consumers
  2018-07-05 16:00 [PATCH] drivers/base: add sysfs entries for suppliers and consumers Ioana Ciornei
@ 2018-07-05 16:05 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2018-07-05 16:05 UTC (permalink / raw)
  To: Ioana Ciornei; +Cc: rjw, linux-kernel, vivek.gautam

On Thu, Jul 05, 2018 at 07:00:28PM +0300, Ioana Ciornei wrote:
> Instead of scraping dmesg for messages such as 'Linked as a consumer to'
> or 'Dropping the link to' export two new sysfs entries in the device
> folder that list the consumer and supplier devices.
> 
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---
>  drivers/base/core.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)

No new documentation files for these new sysfs files?  Not good :(

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-05 16:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-05 16:00 [PATCH] drivers/base: add sysfs entries for suppliers and consumers Ioana Ciornei
2018-07-05 16:05 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.