* [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable
@ 2023-06-07 8:08 Ahmad Fatoum
2023-06-07 8:55 ` Uwe Kleine-König
2023-06-07 11:02 ` Ahmad Fatoum
0 siblings, 2 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-06-07 8:08 UTC (permalink / raw)
To: oss-tools
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 <a.fatoum@pengutronix.de>
---
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable
2023-06-07 8:08 [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable Ahmad Fatoum
@ 2023-06-07 8:55 ` Uwe Kleine-König
2023-06-07 9:00 ` Ahmad Fatoum
2023-06-07 11:02 ` Ahmad Fatoum
1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2023-06-07 8:55 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: oss-tools
[-- Attachment #1: Type: text/plain, Size: 2568 bytes --]
Hello Ahmad,
On Wed, Jun 07, 2023 at 10:08:18AM +0200, Ahmad Fatoum wrote:
> 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.
So another surprise is that device_find_block_device() recurses to find
a device when starting on /soc, isn't it? Is this worth addressing?
> Fixes: 929ed64cb42f ("of_get_devicepath: make partition finding more robust")
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> 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;
I don't remember the details of 929ed64cb42f any more, but probably I
didn't have a specific case that were fixed by that commit. Your
rationale makes sense.
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable
2023-06-07 8:55 ` Uwe Kleine-König
@ 2023-06-07 9:00 ` Ahmad Fatoum
0 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-06-07 9:00 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: oss-tools
Hello Uwe,
On 07.06.23 10:55, Uwe Kleine-König wrote:
> Hello Ahmad,
>
> On Wed, Jun 07, 2023 at 10:08:18AM +0200, Ahmad Fatoum wrote:
>> 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.
>
> So another surprise is that device_find_block_device() recurses to find
> a device when starting on /soc, isn't it? Is this worth addressing?
I don't know what I'd break if I limit iteration depth and I don't know
what else I could do to curtail this..
>
>> Fixes: 929ed64cb42f ("of_get_devicepath: make partition finding more robust")
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> 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;
>
> I don't remember the details of 929ed64cb42f any more, but probably I
> didn't have a specific case that were fixed by that commit. Your
> rationale makes sense.
>
> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thanks,
Ahmad
>
> Best regards
> Uwe
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable
2023-06-07 8:08 [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable Ahmad Fatoum
2023-06-07 8:55 ` Uwe Kleine-König
@ 2023-06-07 11:02 ` Ahmad Fatoum
1 sibling, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-06-07 11:02 UTC (permalink / raw)
To: oss-tools
On 07.06.23 10:08, Ahmad Fatoum wrote:
> 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 <a.fatoum@pengutronix.de>
Patch applied to next.
> ---
> 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;
> }
>
> /*
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-07 11:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 8:08 [OSS-Tools] [PATCH] libdt: fix of_get_devicepath looking up sibling if device unavailable Ahmad Fatoum
2023-06-07 8:55 ` Uwe Kleine-König
2023-06-07 9:00 ` Ahmad Fatoum
2023-06-07 11:02 ` Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox