Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp491993pxb; Thu, 14 Jan 2021 10:44:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/bXtiz91NGMxmefFJSr2WeImhF8ch49W/YXyifAn1yEE8uuIJ1MHnUUAIDs4IMyW58lyL X-Received: by 2002:a17:906:f8d5:: with SMTP id lh21mr6382641ejb.167.1610649842666; Thu, 14 Jan 2021 10:44:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610649842; cv=none; d=google.com; s=arc-20160816; b=FqAuJvS6axEsGsvjm8Z1KenrFwwYEeNxGvIaYghsIWH4CPNUw0lROm3a8zzA4sXeTs MxdoHkoHI5mvI1CSvl2O8t3olOtby4ARGOH94JZYFCkF25pXiP4xWhnRcdEp6AmHqJP/ tO/XAqLgpwmIo18lnGN+Lt9L8n1/gh6ywyQ4UxlTlFQmuFbFupKhwg4AgbQmU9b1gvT9 ha2PToE/iuK5FQUCZerNh64840mj08oIDtZa57gsbYWmF71yog84uizSRR6vsN+UEBkA NGFo5U/F94WTY+ETiRmjNvvKJFjMHfHGnaysHA5aO/ZVVjh9xwDMq16Ar+WKUTfnfvL7 vfoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=neBuUZRdbZl8kkRP5zypxSDWXTMCDH3LhoiqSh6xCnQ=; b=FXbDUZN9uoxS0PTutT8o89/2UAaDQIN2NrLqeqITZkNQqpEPaoOyUI02lL6+Y5lKr3 ZKJEOu0TSiCImZVYegfKHy43CNpxzVD9GGujzozkqgbn03D5/cE238BaYzYrwnGBjHFS TvSopD4Ti5VAQzi5ntO9vncyJai74TY/KhlrJ3417yWCELr2FdeXF+j4AKb0MzlU0VqB H5wZ/rOJzntmPRPLSL6i0yX3JZFfwq9/kv1c9UJ3qgrQEgHUIEPYKs7cQGla9NWyWI4U MP4shOxTP/K4+GocmqwgsOSWY1S8TnEK35pFzQIdOwvI432GvK7uQH+HxSEA+VGcO9K6 Py1A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l19si2659814edq.537.2021.01.14.10.43.38; Thu, 14 Jan 2021 10:44:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727805AbhANSmh (ORCPT + 99 others); Thu, 14 Jan 2021 13:42:37 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:53368 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726482AbhANSmg (ORCPT ); Thu, 14 Jan 2021 13:42:36 -0500 Received: from 89-64-81-33.dynamic.chello.pl (89.64.81.33) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.537) id 53ba55cc67cb7881; Thu, 14 Jan 2021 19:41:54 +0100 From: "Rafael J. Wysocki" To: Greg Kroah-Hartman Cc: LKML , Linux PM , Stephan Gerhold , Saravana Kannan Subject: [PATCH] driver core: Extend device_is_dependent() Date: Thu, 14 Jan 2021 19:41:53 +0100 Message-ID: <2073294.4OfjquceTg@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki When adding a new device link, device_is_dependent() is used to check whether or not the prospective supplier device does not depend on the prospective consumer one to avoid adding loops to the graph of device dependencies. However, device_is_dependent() does not take the ancestors of the target device into account, so it may not detect an existing reverse dependency if, for example, the parent of the target device depends on the device passed as its first argument. For this reason, extend device_is_dependent() to also check if the device passed as its first argument is an ancestor of the target one and return 1 if that is the case. Signed-off-by: Rafael J. Wysocki Reported-by: Stephan Gerhold --- drivers/base/core.c | 12 +++++++++++- 1 file changed, 11 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,7 @@ int device_is_dependent(struct device *d struct device_link *link; int ret; - if (dev == target) + if (dev == target || device_is_ancestor(dev, target)) return 1; ret = device_for_each_child(dev, target, device_is_dependent);