Received: by 10.213.65.68 with SMTP id h4csp392203imn; Tue, 13 Mar 2018 07:40:30 -0700 (PDT) X-Google-Smtp-Source: AG47ELs5xC7pXKapl/pq1uR/Sq/OO8cPC5wsPNqybJsKnJLfGXrz8cj6W+5zg2to8y/vYM+3AuKZ X-Received: by 10.167.129.67 with SMTP id d3mr870318pfn.108.1520952030545; Tue, 13 Mar 2018 07:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520952030; cv=none; d=google.com; s=arc-20160816; b=p6/T3Qbxmbh1yoZaV9cZU9IBTjviiplwC8jVgpOjxVloF82RRzfttVrpvNeobV6zMk O2KGneRCoHManviUyRq/HlyS5n/vlQE3Ybh3I7F2SCwS5lV9q5tAbKGXOZWGD7hZScT3 v9/hGCcjWedDTjoXYSshFlI13u0QKY2p+5UwCjWayyouNEv2pVX0AVabnefsSS3QKOeD KNBkFWukKNYc6TAjhojSa717rH48TvYsrDa8N1cS93aoUV6O7fiIaAjYZup4Vm0IX11+ e0UaFIfGldC9AtKhhI7VamMJdHWSLHO0zVqoddHqeDoyRrg/9YcdIEAf/asTFPPGne+1 Lr5g== 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=gILkTrsjYJCXjY3cCJjPhJLlOabmgqKlYJXfXgiPOjA=; b=Jxzj36aoseMX4pPmqKrZNWxYevQBVfDdI3iq+pW466y4kHTE/tz1wcpZm1XYya4CuD 5Kh13bmwTp3xm7aGyh+GLpbLMKURV6siIZ5+EPJ8oDncpnumAkL+2KKnrkAVdwF3+no/ Y8xobuJwKG56Aqda+190F0xhrf18fphlojP65Aec+2FcAHoyw4ljRxgf3ToPtsyd3PDn frSzmkHDEhtKNoDN75+mTWxQGMT8On2j4Fh7qx7NAxIpVXFwBtdJ/bpGtRs0XyEXz4aV 056VUBcycdgUp9hl7GB+0vysmQHwRepjJ3/HKWs2o73ifH2j3LxTZs6lQdTCizX3l2e4 R0RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=KNDuY/Gb; dkim=pass header.i=@codeaurora.org header.s=default header.b=LPTwSZZ1; 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 n14si227724pfk.106.2018.03.13.07.40.15; Tue, 13 Mar 2018 07:40:30 -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=KNDuY/Gb; dkim=pass header.i=@codeaurora.org header.s=default header.b=LPTwSZZ1; 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 S1752311AbeCMOjO (ORCPT + 99 others); Tue, 13 Mar 2018 10:39:14 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:51272 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751372AbeCMOjM (ORCPT ); Tue, 13 Mar 2018 10:39:12 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 2A369608CB; Tue, 13 Mar 2018 14:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520951952; bh=/YJBYVlG2QohLibDjSweIdlZ8vJoy5xrUE4akjkYJy8=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=KNDuY/GbUr9egQJO4PdMtEwnspvsPZO1qOt7KAVGw6l90rh8Hx9/drfu2QJszslQM rID16kvJhOypVXMYKau9lJcqo0z4o0t9SZLPGM2/uin3lbgwNaVz0H/YcjLPoTYMmI YDoBJrlkL0Ltr7I6fktVUAwPupKGwYZh1bXRtxZo= 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-f176.google.com (mail-qt0-f176.google.com [209.85.216.176]) (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 B41AF60218; Tue, 13 Mar 2018 14:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520951950; bh=/YJBYVlG2QohLibDjSweIdlZ8vJoy5xrUE4akjkYJy8=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=LPTwSZZ1K5MPYrQw6oXvmW30vectkHEScokRWm7DM0JNh0194QCyYdUrnXXCFqqOk G0eDSATNr5DfpDyFY4oKlwYYnQcndIUZGMszEoSlHpNsULrYKjCHvnK35zpwbvUZfT K0p2NPWaRss72tiDamUktMn8ZC0FWiUPKfSbj9KA= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B41AF60218 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-f176.google.com with SMTP id l25so22955953qtj.1; Tue, 13 Mar 2018 07:39:10 -0700 (PDT) X-Gm-Message-State: AElRT7HtXDabdhFhvPLBoPZOLayltZBkR3XSMP0QjSfB31LG67b6cbKj NRClSEPx+End5b3A3vzhsGTCFlGCnEpfZ+0vYak= X-Received: by 10.237.48.34 with SMTP id 31mr1344006qte.325.1520951949965; Tue, 13 Mar 2018 07:39:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.83.10 with HTTP; Tue, 13 Mar 2018 07:39:09 -0700 (PDT) In-Reply-To: <4eaf2006-ea68-d9e9-a0db-89acec0ea299@arm.com> References: <20180313085534.11650-1-vivek.gautam@codeaurora.org> <20180313085534.11650-2-vivek.gautam@codeaurora.org> <8903307.QazHKW0JrR@aspire.rjw.lan> <4eaf2006-ea68-d9e9-a0db-89acec0ea299@arm.com> From: Vivek Gautam Date: Tue, 13 Mar 2018 20:09:09 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v9 1/5] driver core: Find an existing link between two devices To: Robin Murphy Cc: "Rafael J. Wysocki" , "list@263.net:IOMMU DRIVERS" , Joerg Roedel , "robh+dt" , 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 Hi Robin, On Tue, Mar 13, 2018 at 6:19 PM, Robin Murphy wrote: > On 13/03/18 09:55, Vivek Gautam wrote: >> >> 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. > > > Well, the normal pattern is to break out the internal helper function as-is, > then add a public wrapper which validates inputs, handles locking, etc., > equivalently to existing caller(s). See what device_link_del() and others > do, e.g.: > > static struct device_link *__device_link_find(struct device *consumer, > struct device *supplier) > { > list_for_each_entry(link, &supplier->links.consumers, s_node) > if (link->consumer == consumer) > return link; > return NULL; > } > > struct device_link *device_link_find(struct device *consumer, > struct device *supplier) > { > struct device_link *link; > > if (!consumer || !supplier) > return NULL; > > device_links_write_lock(); > link = __device_link_find(consumer, supplier); > device_links_write_unlock(); > return link; > } > > where device_link_add() would call __device_link_find() directly. Right, I understand it now. Thanks for detailed explanation. regards Vivek > > However, as Tomasz points out (and I hadn't really considered), if the only > reasonable thing to with a link once you've found it is to delete it, then > in terms of the public API it may well make more sense to just implement > something like a device_link_remove() which does both in one go. > > Robin. > > -- > 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