Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp193974pxb; Fri, 15 Jan 2021 10:33:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBo4FFthmsOC0BG9K23P7w83tE4pHYYiAVEufAaVQ06ZMrvykcFSdspTXeGc9tIboZlpun X-Received: by 2002:a17:906:87c3:: with SMTP id zb3mr9944592ejb.244.1610735587244; Fri, 15 Jan 2021 10:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610735587; cv=none; d=google.com; s=arc-20160816; b=wHkt8+10/Z+mJNyPY7sRjRMS0OwOLPSytO5MW/oXUl+MkbWtorYs3rrSpsRu5mq2Wi 16aqROWU8N8SV2Y38eRJPS8nJGyAHLj3tw0rzOVaBxCk7ukHh2a8KddV34AvCaAhUhuP YfvT+0znf1zkZT4+tiMfCXiffF2+cI9/7iN1b882uxeNEDhHOVp+sW/TakYyYqnTJ5pS pJfRmicr2QVibIelDq5SOlNL2+EQWuslczG4Vtg5Raxb3tgX2ZILSgRaMswjssL5YeAl Z+yLV7TdG0MOz3kiWQ0+K43SmTGMakaPZP+bmRw5RrwuCfdtgoI5s8U8eOrcDkzIyfHm 05XQ== 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=t+Aorcy9oSBimHQUgvmqCmLzXtfiCUa8Z4qD7Xz9jBU=; b=dmkgNXU5u4UGyHcY8YOkigmSzvNmkHMTNElWMpAhINNJjUWY4+I6F53b1/oiAzQtNQ sNABPE3Xc+1hIcrtWdanRhI88CnO6sO3P6B6PMS8RBTONeu/N2ZkA8bdsqQilUKOQIqv J5SK3dxZiXRNEvg2Y0SLC3bzri3ou2sQLJ7SIuP7OYwnmg0Rm/8th0HGi7DakskOy7FH grrFXe73JJdQOngTEYwG+RTEj5wk66Aq3hh8CDEz6chl+Q91agmljIFKRqWcdKD6xIzI 2pL75akMBoi/Xt/cav4ZtVlqHChpKJAchkGJ0AtusVNzQIDT8RvLqxE4/IVzH7S/7gJN PjwQ== 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 t14si4445202edw.119.2021.01.15.10.32.44; Fri, 15 Jan 2021 10:33:07 -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 S1727278AbhAOSbe (ORCPT + 99 others); Fri, 15 Jan 2021 13:31:34 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:59974 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbhAOSbe (ORCPT ); Fri, 15 Jan 2021 13:31:34 -0500 Received: from 89-64-81-100.dynamic.chello.pl (89.64.81.100) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.537) id 3e720a1ca388cf11; Fri, 15 Jan 2021 19:30:51 +0100 From: "Rafael J. Wysocki" To: Greg Kroah-Hartman Cc: LKML , Linux PM , Stephan Gerhold , Saravana Kannan Subject: [PATCH v2] driver core: Extend device_is_dependent() Date: Fri, 15 Jan 2021 19:30:51 +0100 Message-ID: <17705994.d592GUb2YH@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 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);