stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Stephan Gerhold <stephan@gerhold.net>,
	Saravana Kannan <saravanak@google.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Subject: [PATCH 4.14 07/15] driver core: Extend device_is_dependent()
Date: Fri,  5 Feb 2021 15:08:52 +0100	[thread overview]
Message-ID: <20210205140650.022247260@linuxfoundation.org> (raw)
In-Reply-To: <20210205140649.733510103@linuxfoundation.org>

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

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 <stephan@gerhold.net>
Tested-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Saravana Kannan <saravanak@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/17705994.d592GUb2YH@kreacher
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 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);



  parent reply	other threads:[~2021-02-05 22:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 14:08 [PATCH 4.14 00/15] 4.14.220-rc1 review Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 01/15] net: dsa: bcm_sf2: put device node before return Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 02/15] ibmvnic: Ensure that CRQ entry read are correctly ordered Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 03/15] ACPI: thermal: Do not call acpi_thermal_check() directly Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 04/15] net_sched: reject silly cell_log in qdisc_get_rtab() Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 05/15] net_sched: gen_estimator: support large ewma log Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 06/15] base: core: Remove WARN_ON from link dependencies check Greg Kroah-Hartman
2021-02-05 14:08 ` Greg Kroah-Hartman [this message]
2021-02-05 17:52   ` [PATCH 4.14 07/15] driver core: Extend device_is_dependent() Saravana Kannan
2021-02-09 19:04     ` Stephan Gerhold
2021-02-05 14:08 ` [PATCH 4.14 08/15] phy: cpcap-usb: Fix warning for missing regulator_disable Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 09/15] x86: __always_inline __{rd,wr}msr() Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 10/15] scsi: scsi_transport_srp: Dont block target in failfast state Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 11/15] scsi: libfc: Avoid invoking response handler twice if ep is already completed Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 12/15] mac80211: fix fast-rx encryption check Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 13/15] scsi: ibmvfc: Set default timeout to avoid crash during migration Greg Kroah-Hartman
2021-02-05 14:08 ` [PATCH 4.14 14/15] objtool: Dont fail on missing symbol table Greg Kroah-Hartman
2021-02-05 14:09 ` [PATCH 4.14 15/15] kthread: Extract KTHREAD_IS_PER_CPU Greg Kroah-Hartman
2021-02-06 14:57 ` [PATCH 4.14 00/15] 4.14.220-rc1 review Naresh Kamboju
2021-02-06 16:01 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210205140650.022247260@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=saravanak@google.com \
    --cc=stable@vger.kernel.org \
    --cc=stephan@gerhold.net \
    --cc=sudipm.mukherjee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).