Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2304983pxb; Fri, 5 Feb 2021 14:29:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+FWj4kLyF4kbeESbDmRGUe1DG0beeebeBIZnF+ve0cLqK1ipX1y2CRq6VIW0xUBNq2dsF X-Received: by 2002:aa7:de0f:: with SMTP id h15mr5846545edv.198.1612564169558; Fri, 05 Feb 2021 14:29:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612564169; cv=none; d=google.com; s=arc-20160816; b=HF1GMzsm5+AyiQomTs81wsatnajPsg4RaREfRj0tEogexcSP5bfrOOEctdKV81gBZq V+buORUqmCKXL75WzKDc7lg3hqjko3wPptueywRNDWYRSYiiHChMkAkSiAnXW6l+Sdta UwW/btTYZCwZyR41VHFX1QukyykFzES+L0QEm0kjChV29pdUFijnz32rS2xCsFNLkRKn +vY0m/1c8EArMJ4bxGKEe5xNsAchoJdHhf5iYMFJSZkqFm7vKAk/2spv4r6LPL5igp7c Nvkx0j63jzYpZuVw7kh0AN/gJp7VnMlP+6YvWoMqwulfJ8q5YVvVv97Z8wn4e5NJPYdz x/pQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7Pdv/lxhTALXJFk8/HsadQncGTIyqRxF0v8WSPFD5Jo=; b=trLpoh7uKOxNmRugedu7gNwEi+8rhqFd39Ft0LUjo8Zov0tvSstOAiZ/qfY9On+n0/ 5fRYS/kESaO9zQ53lnP/PnQ1aqas8czstzKQyi9+fzT+nIdj7yoZZmk1AIiJJ7Otu3eN BGowpQl/ugpczcidxgycxrRv9zozQ641Raug4q2JLvXcVpuLecyAP/m8uM1cOp/O88s5 W1RLH3DtTLDn07le/SCHY9ktV46Y+h6/NHWt1JKRPHYvJDieOj0gjVDNTkI+gUc02DbA 5Hy8BM9tMRdQFzYYPdkYxzKmAiFgqeCgF6DYxxkOZa8YoUwXZQr1H7wGDuond4+Ze/Dd a8pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GkrHs5ce; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si6081343ejh.668.2021.02.05.14.29.05; Fri, 05 Feb 2021 14:29:29 -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=@linuxfoundation.org header.s=korg header.b=GkrHs5ce; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233195AbhBEWZz (ORCPT + 99 others); Fri, 5 Feb 2021 17:25:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:44980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232851AbhBEOyw (ORCPT ); Fri, 5 Feb 2021 09:54:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95D9D650C4; Fri, 5 Feb 2021 14:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534496; bh=caA55sIiCpe1X+tGnqPjpicNBT/1vVp/DxEmiop0XtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GkrHs5ceAC15QzSCbudufptkPSzQUCh3Ybf7cEYt8r7dZCFYEMmz0v5u6p37HYbdR xYW0OWLSUakrigvLiRl4QE7AuzPkcTlOf6G3HrDn9QMeHKUqV7qy5ISyLStLn+lTuK gw4K2VdMmq7tjhSTBFmlmdSkcsiUL+WwyVcVR5dQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephan Gerhold , Saravana Kannan , "Rafael J. Wysocki" , Sudip Mukherjee Subject: [PATCH 4.14 07/15] driver core: Extend device_is_dependent() Date: Fri, 5 Feb 2021 15:08:52 +0100 Message-Id: <20210205140650.022247260@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140649.733510103@linuxfoundation.org> References: <20210205140649.733510103@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" commit 3d1cf435e201d1fd63e4346b141881aed086effd upstream 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") Reported-by: Stephan Gerhold Tested-by: Stephan Gerhold Reviewed-by: Saravana Kannan Signed-off-by: Rafael J. Wysocki Link: https://lore.kernel.org/r/17705994.d592GUb2YH@kreacher Cc: stable Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -96,6 +96,16 @@ void device_links_read_unlock(int not_us } #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. @@ -109,7 +119,12 @@ static int device_is_dependent(struct de 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);