Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp797578imm; Thu, 5 Jul 2018 09:03:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdd7JWPThO0NXX3p719FMIGwRFcpkuSDKVOMRnvDSZT7q91d/242uxfP3FWsDnz5d5ED5uw X-Received: by 2002:a62:b02:: with SMTP id t2-v6mr7075846pfi.36.1530806584473; Thu, 05 Jul 2018 09:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530806584; cv=none; d=google.com; s=arc-20160816; b=HrAkUsRtjzoHMcAySX8Wo11065sEQKZNVj4rYtmD4XlH/atv3MMAPRvJEBVZcg/du6 KsQe1zej4SbD7UMT60j06c6YD/A2P63Gq9JCbRJ9eCY/EX02jtuoBjpJydTI/iDDQr2M /TiUeHi9wn1EhvdXEVlfkLoWDMHozwfpaCkf5BDOLNNepbUXcV0J7EEr/XyEDglyTkue SbCM4m7OuPxj2k4NU2dq5OtCmW30MV0HBKXNNRYY+Os8uw/aOW/CLBqQdKm5TtpJxo4D +tfZacE5gUPibAtn2Z0MbppvxB3FVo0fvRw5xVQh1r1jqcA+25Y+7j048xZB+RgqcaQX 18iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Qw84VOOqY39YhwbBDW3/AwU+pROJF7IvDu1nZkYTmls=; b=m2LK9hoUmD2iy7RY0K5bwcnRdWTSDRtOfdnpz38VkVAUzEw8B48VcBPndxjVMATRub dT33//I2apgLuTAPxLkckuYW8OxH/G+G9DNVOqVZkRzVVnNMg27RpBWn+jDn7dODEtb5 T1mZXfuHXCGzHTlRdGi1am0ekMjUZm3sOMgSv4KvMJLjny57wsPhfnQ5fj874Y10gaxU uIwNv72A6HGDt76orViSKlji4qkqUq+DblWZAh9uJ1WVnQie6asfgsaUKS4IGdboAxf8 CrQ98bikuIOcbQWQCItF87HaZ45Ox6M0SeUZO0BxQto+D2d1PWhb8389rN2tRwvmZx1x wT0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi1-v6si6114386plb.126.2018.07.05.09.02.49; Thu, 05 Jul 2018 09:03:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753831AbeGEQBN (ORCPT + 99 others); Thu, 5 Jul 2018 12:01:13 -0400 Received: from inva020.nxp.com ([92.121.34.13]:50318 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753417AbeGEQBM (ORCPT ); Thu, 5 Jul 2018 12:01:12 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D8C0A1A0020; Thu, 5 Jul 2018 18:01:10 +0200 (CEST) Received: from smtp.na-rdc02.nxp.com (inv1260.us-phx01.nxp.com [134.27.49.11]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A1A191A0014; Thu, 5 Jul 2018 18:01:10 +0200 (CEST) Received: from az84smr01.freescale.net (az84smr01.freescale.net [10.64.34.197]) by inv1260.na-rdc02.nxp.com (Postfix) with ESMTP id 1921B40A6B; Thu, 5 Jul 2018 09:01:10 -0700 (MST) Received: from fsr-ub1464-137.ea.freescale.net (fsr-ub1464-137.ea.freescale.net [10.171.82.114]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id w65G17To026341; Thu, 5 Jul 2018 09:01:08 -0700 From: Ioana Ciornei To: gregkh@linuxfoundation.org, rjw@rjwysocki.net, linux-kernel@vger.kernel.org Cc: vivek.gautam@codeaurora.org, Ioana Ciornei Subject: [PATCH] drivers/base: add sysfs entries for suppliers and consumers Date: Thu, 5 Jul 2018 19:00:28 +0300 Message-Id: <1530806428-19702-1-git-send-email-ioana.ciornei@nxp.com> X-Mailer: git-send-email 1.9.1 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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