Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2301794pxb; Mon, 18 Jan 2021 14:05:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCLo0nJYAESWSebQfEu9cSYzqUSuaoTvXsMF8gK3GCqy6nVcwpC69eclh2G6LmEODGXacu X-Received: by 2002:a17:906:4bc2:: with SMTP id x2mr1087042ejv.4.1611007504746; Mon, 18 Jan 2021 14:05:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611007504; cv=none; d=google.com; s=arc-20160816; b=Fvvd1VK9ccJU2tbCSl3cqCZyrgKQ+xlMJkYfUcJzjEU+pZ6FXDdhQRiKHd51n7ZBH7 9oi+JGz+ltH2MSub3kGCPU8X1byudZzAyM5w+EmkvKHMFhoz24gSf++cS4CEGFtrf1Ds IZgWmOBiJMK5p6yE5DmBYubQQdXxRiPp3bG34aGlxolUk2pgwaZ2MTQ0GWuN6vJY3ydH CZSy245ZSMHplT80oqdttcxcJDN6ZVV6Q8Ft1tbccjz7ZQ0U9ErkoeKaEDB0BHMBM5Ew +ViTq9f6RgIZ7XjE4f5fIy7s1Z1jG6xBdfMy0E0InmV8BDIMIESPFRZ3MgekNTZmgjvt ogsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zumUIy9oq3c425eUVST4wJD5csI9JUzk2QZ8OmfbAnc=; b=MrsXn9K/lYP/x2xIrDLmre1WoXKTBLljq5Z/tPoEdexLHQ7jNfFSg6Z/OBFSuggq3x 246jhWwNHeQRkbm9brvIOsaIkbssMSoYLmEwltxUtds0Js6JuKXWoMSEZzrTIPsLMJQM VNs+3+ecbFh3ubcD/XIdhMHNBzfQ2mAaNipNnqMBUc2T5y0ojocDTwR0/q+8/isM3mB9 5pht7dh9QNugi/hrR4nqyzzR7tFv6apo7YWmZY6czIFFh4KRIV4iaVTMqhalmorPmdSD oRwC/TtfjQ5nAX/5OUNntqdVP1sIcevkiHk5TmywaZqAyzyAK24zgU312RXELyhWb/u+ Mx6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Yo5Gg8UT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si6346241edo.512.2021.01.18.14.04.41; Mon, 18 Jan 2021 14:05:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Yo5Gg8UT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387494AbhARWCv (ORCPT + 99 others); Mon, 18 Jan 2021 17:02:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733098AbhARWCs (ORCPT ); Mon, 18 Jan 2021 17:02:48 -0500 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE4CBC061574 for ; Mon, 18 Jan 2021 14:02:32 -0800 (PST) Received: by mail-yb1-xb29.google.com with SMTP id x78so9594791ybe.11 for ; Mon, 18 Jan 2021 14:02:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zumUIy9oq3c425eUVST4wJD5csI9JUzk2QZ8OmfbAnc=; b=Yo5Gg8UTepfDRZ/i1xpsy4Mpf2PqreW1jRKVkhStFNYMcHkIvvl7uKf0NDbnoUCH9K 1dG6y09tKrXhb4WEaSoXL5zDbhU2TLyLOXExny1os4qH3LG+NoXoSvH63bJtQ0UO/hON 4ApMI9Ucv2UG2G5i1t3aWuVWwVB0G9TdycK7qIGUnrrQRkvBtCOzLojO75skKtnDdl02 Br/ALA5LiKPxtxkaUfBrxJT4etBZ2ueMep9G9WjJaB5yAF2SwmOJn+1XP3hR0ACa7VPa vHb7Ot98fy5t1cHh9mPCnRIkh23qzqTGBPtq8ch9ufbyTyIGHzyLmDTZSaMnwn5PKh8P iIfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zumUIy9oq3c425eUVST4wJD5csI9JUzk2QZ8OmfbAnc=; b=DOaXQVEoFASxhxMkwfM2O9OHIqlyjpRgZKCWHn0P3g6dg9swb5JhvqXVW6/RgpqUKX 1+fgRdYIuUdtsRkpuL62l8mFffJZwsWBooY7LRCRL3CBTcgMdDDiNF83/k1FfSFVfop2 nzeMGDYP2dM9Gcp2FCb0gp6xtki8+7kgh7akpKCXM7nh/9j7Ihkd/co+Mgf19MQSDl99 6gvbwMvlPqLAvnv+7/KhbgkPbafDuyesUMwxSexbfBsgeX2CJG2kRyP9Pl1YOc0vocF+ AclKxMGaVs/n8qO9wZBMt0SIyVr9k5UmQklDlMnuD42RMhrDqLfRvIv6dwqLGqv0XEl4 sgow== X-Gm-Message-State: AOAM5320eiFowPTStI3pfWGglf70ESAIXyJtLmu7thNJ0ru7XSa0q8AS mizK54i6Ee9gT5pFAvwImQ+N6ASd0/8hKM18tACEwz/XUws= X-Received: by 2002:a25:4047:: with SMTP id n68mr1677312yba.466.1611007352096; Mon, 18 Jan 2021 14:02:32 -0800 (PST) MIME-Version: 1.0 References: <17705994.d592GUb2YH@kreacher> In-Reply-To: <17705994.d592GUb2YH@kreacher> From: Saravana Kannan Date: Mon, 18 Jan 2021 14:01:55 -0800 Message-ID: Subject: Re: [PATCH v2] driver core: Extend device_is_dependent() To: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman , LKML , Linux PM , Stephan Gerhold Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 10:30 AM Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > If the device passed as the target (second argument) to > device_is_dependent() is not completely registered (that is, it has > been initialized, but not added yet), but the parent pointer of it > is set, it may be missing from the list of the parent's children > and device_for_each_child() called by device_is_dependent() cannot > be relied on to catch that dependency. > > For this reason, modify device_is_dependent() to check the ancestors > of the target device by following its parent pointer in addition to > the device_for_each_child() walk. > > Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support") > Signed-off-by: Rafael J. Wysocki > Reported-by: Stephan Gerhold > Tested-by: Stephan Gerhold > --- > > -> v2: > * Improve the changelog. > * Add a comment to explain the reason for the extra check. > * Add tags. > > No code changes. > > --- > drivers/base/core.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > Index: linux-pm/drivers/base/core.c > =================================================================== > --- linux-pm.orig/drivers/base/core.c > +++ linux-pm/drivers/base/core.c > @@ -208,6 +208,16 @@ int device_links_read_lock_held(void) > #endif > #endif /* !CONFIG_SRCU */ > > +static bool device_is_ancestor(struct device *dev, struct device *target) > +{ > + while (target->parent) { > + target = target->parent; > + if (dev == target) > + return true; > + } > + return false; > +} > + > /** > * device_is_dependent - Check if one device depends on another one > * @dev: Device to check dependencies for. > @@ -221,7 +231,12 @@ int device_is_dependent(struct device *d > struct device_link *link; > int ret; > > - if (dev == target) > + /* > + * The "ancestors" check is needed to catch the case when the target > + * device has not been completely initialized yet and it is still > + * missing from the list of children of its parent device. > + */ > + if (dev == target || device_is_ancestor(dev, target)) > return 1; > > ret = device_for_each_child(dev, target, device_is_dependent); > Reviewed-by: Saravana Kannan fw_devlink_relax_cycle() needs a similar fix. Want me to handle that as a separate patch to driver-core-next? Or do you want to combine that in this patch? -Saravana