Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp865237imm; Thu, 5 Jul 2018 10:12:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd+wZU++2eIKmy49wu9WYfhz5UnE4IKiP066nIkrYbYNU7G/hnOAk8vgmN7RqdAVI9Sciwo X-Received: by 2002:a17:902:d896:: with SMTP id b22-v6mr7189236plz.265.1530810779881; Thu, 05 Jul 2018 10:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530810779; cv=none; d=google.com; s=arc-20160816; b=EBL9LIcNwfWs1/YNtIRsxBnG9syW58yD2DW79YMGkPeC3bCDap1WABjN2CKrj5JMKw 9I8h0vFMkbtKvVvaMHmJRmlE7autPys5CXdzU6VFUTo7KM7/TwBpHfn1PmVXYj/qnUTC FiC85nQIlTilaNRjJLwjUZSTua+qbZHvJb/4xemSy69UE9WDgfiidGvVNP2s/9tPiiC6 uD+nRXRO53iR8cUhpED68jiiedcBg7e4yXfE77p+LLOJ/EDbQJrGyPH6mRh9BJpsmdIm cHqj1deTN+ocu85RLmzPsbjF0aDauPVu1S3+tCwGM/vjCm1Z/QHDkNNSIUy/EU4dKrqo FzzQ== 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=y9DtTe9r8FtSeLDGEdJLz0EGby4WYNb0rhDTK3GAS7E=; b=XTODQCrY062a9e8220e6WHz0YxdXRxaWLigEKs7EEI6U8lCMO/6f9hWicmwemwYP4O LbWIQ8WsL/o1FFr1PBhAMsQrbMVcA9RPZXflE54iulmkkTwxEwYr4PnAGjKf7St6uROJ DTzN2mQVdqsHMm6XWyD4yyjYl/MP8CXov4Jfgcb0J0JFFCTzmZkO5VzfI0il6RL3z/Ii K6GdIPPe/mYwqi3n653aW8e6/DJtUoRfwQ3/3n/bgMZpQe0hHllSWUjYaWKTipch7NEd mTYbiLD8sKCcpRMZs4EJ/Ec1vIXsMgnEfh9GwIveqzTrSeZAKgmmdS+niNBYeeivEkQh iIEQ== 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 n61-v6si6180521plb.256.2018.07.05.10.12.22; Thu, 05 Jul 2018 10:12:59 -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 S1753844AbeGERK7 (ORCPT + 99 others); Thu, 5 Jul 2018 13:10:59 -0400 Received: from inva020.nxp.com ([92.121.34.13]:37022 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753525AbeGERK6 (ORCPT ); Thu, 5 Jul 2018 13:10:58 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id C71071A0044; Thu, 5 Jul 2018 19:10:56 +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 653CD1A0020; Thu, 5 Jul 2018 19:10:56 +0200 (CEST) Received: from az84smr01.freescale.net (az84smr01.freescale.net [10.64.34.197]) by inv1260.na-rdc02.nxp.com (Postfix) with ESMTP id D51C540A6B; Thu, 5 Jul 2018 10:10:55 -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 w65HAr4A030974; Thu, 5 Jul 2018 10:10:54 -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 v2] drivers/base: add sysfs entries for suppliers and consumers Date: Thu, 5 Jul 2018 20:10:27 +0300 Message-Id: <1530810627-15015-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 --- Changes in v2: - add documentation entries for the new sysfs files Documentation/ABI/testing/sysfs-devices-links | 13 +++++++++ drivers/base/core.c | 42 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-devices-links diff --git a/Documentation/ABI/testing/sysfs-devices-links b/Documentation/ABI/testing/sysfs-devices-links new file mode 100644 index 0000000..0c73ef5 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-devices-links @@ -0,0 +1,13 @@ +What: /sys/devices/.../consumers +Date: July 2018 +Contact: Ioana Ciornei +Description: + Read-only attribute that lists the devices that have a device + link which denodes a consumer relationship to this device. + +What: /sys/devices/.../suppliers +Date: July 2018 +Contact: Ioana Ciornei +Description: + Read-only attribute that lists the devices that have a device + link which denodes a supplier relationship to this device. 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