From patchwork Tue Mar 13 08:55:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 10277975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9F2EE6038F for ; Tue, 13 Mar 2018 08:57:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A368C26538 for ; Tue, 13 Mar 2018 08:57:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9728B26D08; Tue, 13 Mar 2018 08:57:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 414A426538 for ; Tue, 13 Mar 2018 08:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752539AbeCMI4L (ORCPT ); Tue, 13 Mar 2018 04:56:11 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:37200 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752526AbeCMI4I (ORCPT ); Tue, 13 Mar 2018 04:56:08 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 08BF560A05; Tue, 13 Mar 2018 08:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520931368; bh=pSpMVtcBGZKJb5g2NaPOGEIZLOhZdoK5GN1t9W+3DVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SoQ3cJ32fgImoppvaIvFoEd4GG/utFWJal3cQLsiUMZ2wCHbK7gLud4uEuAYQftm9 6JMblcA7LmPYCMh71JVYazURq7CNXwH1mOyLEPTu8YvucSkoCHGUc54I5QxsBX4xBf n86nZRZ+ckMd8927bO/SRiSzUFjwFE6ChWuIUNbw= Received: from blr-ubuntu-41.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3824060858; Tue, 13 Mar 2018 08:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520931366; bh=pSpMVtcBGZKJb5g2NaPOGEIZLOhZdoK5GN1t9W+3DVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IIyzhMgzTV2IymqkyXHqrDIjNF/befD/G5ip/hMthrHFhbh/qFGthmZVblfC3Xn1v 1wC5MfyJyyepo7s4rbKf+9JTB2FousQ+pbdlTTlYivf4p8RPxn0m8d1sSW+qLms1b2 pg5eZ7lfFCMR+7PoDu4fNur0KH14sWo4SGqmPtdk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3824060858 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: joro@8bytes.org, robh+dt@kernel.org, robin.murphy@arm.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mark.rutland@arm.com, will.deacon@arm.com, robdclark@gmail.com, tfiga@chromium.org, sricharan@codeaurora.org, m.szyprowski@samsung.com, architt@codeaurora.org, linux-arm-msm@vger.kernel.org, vivek.gautam@codeaurora.org, "Rafael J . Wysocki" , Greg Kroah-Hartman Subject: [PATCH v9 1/5] driver core: Find an existing link between two devices Date: Tue, 13 Mar 2018 14:25:30 +0530 Message-Id: <20180313085534.11650-2-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 2.16.1.72.g5be1f00a9a70 In-Reply-To: <20180313085534.11650-1-vivek.gautam@codeaurora.org> References: <20180313085534.11650-1-vivek.gautam@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The lists managing the device-links can be traversed to find the link between two devices. The device_link_add() APIs does traverse these lists to check if there's already a link setup between the two devices. So, add a new APIs, device_link_find(), to find an existing device link between two devices - suppliers and consumers. Signed-off-by: Vivek Gautam Cc: Rafael J. Wysocki Cc: Greg Kroah-Hartman --- * New patch added to this series. drivers/base/core.c | 30 +++++++++++++++++++++++++++--- include/linux/device.h | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 5847364f25d9..e8c9774e4ba2 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -144,6 +144,30 @@ static int device_reorder_to_tail(struct device *dev, void *not_used) return 0; } +/** + * device_link_find - find any existing link between two devices. + * @consumer: Consumer end of the link. + * @supplier: Supplier end of the link. + * + * Returns pointer to the existing link between a supplier and + * and consumer devices, or NULL if no link exists. + */ +struct device_link *device_link_find(struct device *consumer, + struct device *supplier) +{ + struct device_link *link = NULL; + + if (!consumer || !supplier) + return NULL; + + list_for_each_entry(link, &supplier->links.consumers, s_node) + if (link->consumer == consumer) + break; + + return link; +} +EXPORT_SYMBOL_GPL(device_link_find); + /** * device_link_add - Create a link between two devices. * @consumer: Consumer end of the link. @@ -195,9 +219,9 @@ struct device_link *device_link_add(struct device *consumer, goto out; } - list_for_each_entry(link, &supplier->links.consumers, s_node) - if (link->consumer == consumer) - goto out; + link = device_link_find(consumer, supplier); + if (link) + goto out; link = kzalloc(sizeof(*link), GFP_KERNEL); if (!link) diff --git a/include/linux/device.h b/include/linux/device.h index b093405ed525..13bc1884c3eb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1278,6 +1278,8 @@ extern const char *dev_driver_string(const struct device *dev); struct device_link *device_link_add(struct device *consumer, struct device *supplier, u32 flags); void device_link_del(struct device_link *link); +struct device_link *device_link_find(struct device *consumer, + struct device *supplier); #ifdef CONFIG_PRINTK