Received: by 10.213.65.68 with SMTP id h4csp243498imn; Tue, 13 Mar 2018 02:56:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELsSAzVVsKtTEksirqoODOeu0Dqe2KOF05yJ8NXyj2vrTft7NN5EzT2IQTae659e21RbjV/7 X-Received: by 10.99.107.6 with SMTP id g6mr5882702pgc.109.1520935002260; Tue, 13 Mar 2018 02:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520935002; cv=none; d=google.com; s=arc-20160816; b=HTqmj4Msxgbkqz8OwgRiA8OFCa2LoKFTNZJW5unohuQgvjellHFg/lE1kIdWz8GKEb 56ojEjzpm+58peQrPirRknSDtXsKw9BteWqWx9uZ6lCfRDPsZcx9pp/wIonAg542YAuR eFWba0rboyYp+YH18/sTlQoQpJUXx4xfVSvtxR99xpYYJjFDyGELwwoCNkSzSg1GoYpp 9EyVe0qJtYHV2qXGIkDrVsNnN/CMjSkQIYhLWsFZzjDXvDG8/3WAq9pJpJ3lGvndCNyA e7WB3u80sVSyOcWsZ3gjVczEwNlgR8W6rb5OGkuQtknj17jkbDJxjjE+18HGEAE6iVOw tygA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter:dkim-signature :dkim-signature:arc-authentication-results; bh=TgD35LWOvW0b5MeeI9tKOq6Ycf4/vZbPgI2AcUU9OyI=; b=V5nvSXxsmWXC7XC2Wr3aDeQz9ELtOfngkRvu3Im6EG5GBelyQWiyw9vCbc5jgphYO0 QOnO96fHEtZLrUGP4wGwRs91ntT7adfXUiaHjZPZX8cElyWlukRuUjkpaAuEswI2qHUU MMtIDqGIkpVdvPzgCprBYKbwm44d2bmKuxR0ixKI5vEmE7NOyuBnoQdulwtZ0WBedgvP aJaILV1V62rrHBTl5FHkx5tBAxjozex+h2PtRrMmzvx2yJN6xHpflJnoN7anMRbUAo4i +CUsGoKaR1bN9STHkGVGtRyFWysajlJLA4r15/lCOjdpTWXk0xLIKSwZFro3mqhGSwpI rAug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Ba6JnaXm; dkim=pass header.i=@codeaurora.org header.s=default header.b=nzzXX4Xl; 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 s16-v6si7725240plk.550.2018.03.13.02.56.27; Tue, 13 Mar 2018 02:56:42 -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=Ba6JnaXm; dkim=pass header.i=@codeaurora.org header.s=default header.b=nzzXX4Xl; 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 S932471AbeCMJzY (ORCPT + 99 others); Tue, 13 Mar 2018 05:55:24 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:45774 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752181AbeCMJzW (ORCPT ); Tue, 13 Mar 2018 05:55:22 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 90CFF6095F; Tue, 13 Mar 2018 09:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520934921; bh=oG000ofGekjH7vZg0mv32vSifeaoPkgR2amfn3CDGzk=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=Ba6JnaXmAv5y1IP7GHmC/i8ZQih6rq/XoSSq1R0/PWMMk3RpQxUEu3f3fBqcA76Xu WDNe1/+ZbCnXehystRZsyPHhzoAzOAX6F48zmwql5gL6xsktoHPNarsr1BlIAzUWVV QI97DhbSmIp4TvLU4qUjY5EJhBh1voiSqeSX2yHo= 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 mail-qt0-f181.google.com (mail-qt0-f181.google.com [209.85.216.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 785AD60854; Tue, 13 Mar 2018 09:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520934919; bh=oG000ofGekjH7vZg0mv32vSifeaoPkgR2amfn3CDGzk=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=nzzXX4Xlg1Qk8zFbksUMtn7HBpcDeS+/9NOuJtfm3fUIShHjwMVK4MndfQD6qtCul 9nEpHCmMSKGQiVKp7Aw3lt1EXEEkdorPlf7WDhgwejxy3WasdcauCPuQIFiZNEbGRj ejOw0k0Ws/6eCk4XWfnrtkGEhkJLmopf8CUjSDwU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 785AD60854 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 Received: by mail-qt0-f181.google.com with SMTP id l25so22021441qtj.1; Tue, 13 Mar 2018 02:55:19 -0700 (PDT) X-Gm-Message-State: AElRT7FD4W6hl0FQ6DKc6RV8rqIxkbKxskCoV78dVJMqdfcje/R0c/Gu Tl4/t2z2r0R2v22NgdXf0AQH/87AwFzvPuRFnII= X-Received: by 10.200.56.249 with SMTP id g54mr16111079qtc.245.1520934918579; Tue, 13 Mar 2018 02:55:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.83.10 with HTTP; Tue, 13 Mar 2018 02:55:18 -0700 (PDT) In-Reply-To: <8903307.QazHKW0JrR@aspire.rjw.lan> References: <20180313085534.11650-1-vivek.gautam@codeaurora.org> <20180313085534.11650-2-vivek.gautam@codeaurora.org> <8903307.QazHKW0JrR@aspire.rjw.lan> From: Vivek Gautam Date: Tue, 13 Mar 2018 15:25:18 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v9 1/5] driver core: Find an existing link between two devices To: "Rafael J. Wysocki" Cc: "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , "robh+dt" , Robin Murphy , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , devicetree@vger.kernel.org, open list , Mark Rutland , Will Deacon , Rob Clark , Tomasz Figa , Sricharan R , Marek Szyprowski , Archit Taneja , linux-arm-msm , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 13, 2018 at 3:10 PM, Rafael J. Wysocki wrote: > On Tuesday, March 13, 2018 9:55:30 AM CET Vivek Gautam wrote: >> 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; >> + > > Any mutual exclusion? > > Or is the caller expected to take care of it? And if so, then how? I think it's better that we take care of lock here in the code rather than depending on the caller. But i can't take device_links_write_lock() since device_link_add() already takes that. regards Vivek > >> + 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 >> >> > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation