Received: by 10.213.65.68 with SMTP id h4csp220961imn; Tue, 13 Mar 2018 01:59:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELtI7jB0H7LX6RvfBFDYkHHU3TFnDZ2hsGDGVVvcdPn5XWri2Ztoxgsl04+vNIoMDb69g+Ok X-Received: by 10.101.69.4 with SMTP id n4mr9081948pgq.184.1520931541130; Tue, 13 Mar 2018 01:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520931541; cv=none; d=google.com; s=arc-20160816; b=HtEQMHfXOX2DSfZOFKIQVNscjuCFpiXfzHcBCPkW1/OX0fyRsmS1PXlVo9ZNNJVqUd hX8toufEBbQdYLCCi9ERH7iqltZqUT6SnVUXlWS2X+kza8/JmtaR/2EMCuA66oF677ew iuG2z0Kvv0vxh8bW6kK7cI8uICeKjPLqWDFOqaktSuW2Kzm/kpubm10NVCe8Ha9PuhRk a7FKOBhpuz7AUiKJwbhw2v/6F3EVZrGWsJMca1pStljGPZoiek+7nCSKnq+bsCDZgYvf lzwMaEmdj6F4stRmhQ6Og05HA3mBI8EKmdimgag02WZ6ZnIFXBy9Py0ZvGtHBXniow1R X4fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=xSjuxkzt7Bdix4yG+U3IFlWuFrhzLN9ID1OsVrTbH2k=; b=N9KPhkQu/8ixa/cczhmi1IITTZCAv37k7p5H10rYn2upHp/nPvcSVL+hgB80+2xG9M dUZkHONE9WwWNhCmKozL57/mJq0a28JjSPFIBvArd3hqN+FQSLDeLcUxEe+nfpghZkXj Vi4rz5AObRQ/W3CtAkntKDvCMoh33VD88PTN9hZYZT9bVOfx/KbcCnYZAG28gDSyKGDB KxHGIexIYZNVOPjN43xDTB1Lp/bnBVfsk/i2SIlTCQV45pHbfAjpFDYOEoHdkBvKv0YH Wi6EDV1XEoJxPvbD36bfIExD5xV/nQXEGcQ9lAzd1r7LtZZ7uSPa1VWYbPUV4JrdNFBX uc7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=SoQ3cJ32; dkim=pass header.i=@codeaurora.org header.s=default header.b=IIyzhMgz; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y13si573059pgv.755.2018.03.13.01.58.47; Tue, 13 Mar 2018 01:59:01 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=SoQ3cJ32; dkim=pass header.i=@codeaurora.org header.s=default header.b=IIyzhMgz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752565AbeCMI4M (ORCPT + 99 others); Tue, 13 Mar 2018 04:56:12 -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= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation