From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 07 Jun 2023 10:08:28 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q6oDV-00E4Dl-Iv for lore@lore.pengutronix.de; Wed, 07 Jun 2023 10:08:28 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1q6oDS-0000IE-AU; Wed, 07 Jun 2023 10:08:26 +0200 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q6oDP-0000Hn-9o; Wed, 07 Jun 2023 10:08:23 +0200 Received: from [2a0a:edc0:0:1101:1d::54] (helo=dude05.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1q6oDO-005hQU-L5; Wed, 07 Jun 2023 10:08:22 +0200 Received: from afa by dude05.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1q6oDN-0030Ec-M2; Wed, 07 Jun 2023 10:08:21 +0200 From: Ahmad Fatoum To: oss-tools@pengutronix.de Date: Wed, 7 Jun 2023 10:08:18 +0200 Message-Id: <20230607080818.715192-1-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable X-BeenThere: oss-tools@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: Pengutronix Public Open-Source-Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "OSS-Tools" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: oss-tools-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false of_get_devicepath code flow is split into two: A) Either the device tree node in question has a direct udev_device associated with it B) Or we assume it's a partition and lookup udev_device for the parent first, before finding a child udev_device or setting a partition offset within the parent udev_device. Since v2017.03.0, we have had a fallthrough from case A into case B: If we have a udev_device, but it's neither a EEPROMs, MTDs or block device, we just consider it a partition. This is problematic, because this may result in us pointing at a very different device: - backend points at a SD-Card host. Host is enabled, but SD-Card is not inserted, so no block device - case A fails, so it's assumed it's a partition and case B uses parent SoC bus to lookup appropriate device - We fall through into the second device_find_block_device, which will take the first matching block device across the SoC. So we could end up with the eMMC: a completely different device than what was pointed at. Fixes: 929ed64cb42f ("of_get_devicepath: make partition finding more robust") Signed-off-by: Ahmad Fatoum --- src/libdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libdt.c b/src/libdt.c index e54d7fb5649d..7b99efe5b2de 100644 --- a/src/libdt.c +++ b/src/libdt.c @@ -2492,9 +2492,11 @@ int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t } /* - * If we found a device but couldn't classify it above, we fall - * through. + * If we find a udev_device but couldn't classify it above, + * it's an error. Falling through would mean to handle it as a + * partition and could lead us to return an arbitrary sibling device */ + return -ENODEV; } /* -- 2.39.2