diff mbox series

[1/2] part: Check all partitions in part_get_info_by_name()

Message ID 20240328222951.11431-1-semen.protsenko@linaro.org
State New
Headers show
Series [1/2] part: Check all partitions in part_get_info_by_name() | expand

Commit Message

Sam Protsenko March 28, 2024, 10:29 p.m. UTC
In part_get_info_by_name() the inability to get some partition info
shouldn't be a reason for dropping out of the loop. That might happen
e.g. if the partition is hidden or unused. An example of such case are
Samsung devices, where they use the "unused" GUID type
(00000000-0000-0000-0000-000000000000) to indicate that the partition
should be hidden from the OS. Such partitions might not be seen in
"part list" output, which creates "gaps" in numbering in between of the
visible partitions:

    Part    Start LBA       End LBA         Name
      1     0x00000400      0x0000a3ff      "efs"
      5     0x00026420      0x00026c1f      "dtbo"
     12     0x0003f390      0x0074738f      "super"

In that case, the loop in part_get_info_by_name() would break after
partition #1, so any attempt to obtain "dtbo" or "super" partition will
fail. Fix that by continuing to iterate over the remaining partitions to
make sure none of the visible ones is missed. That makes "part" command
(e.g. "part start", "part size") able to work with such tables.

Fixes: 87b8530fe244 ("disk: part: implement generic function part_get_info_by_name()")
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
---
 disk/part.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Heinrich Schuchardt March 29, 2024, 12:03 a.m. UTC | #1
On 3/28/24 23:29, Sam Protsenko wrote:
> In part_get_info_by_name() the inability to get some partition info
> shouldn't be a reason for dropping out of the loop. That might happen
> e.g. if the partition is hidden or unused. An example of such case are
> Samsung devices, where they use the "unused" GUID type
> (00000000-0000-0000-0000-000000000000) to indicate that the partition
> should be hidden from the OS. Such partitions might not be seen in
> "part list" output, which creates "gaps" in numbering in between of the
> visible partitions:
>
>      Part    Start LBA       End LBA         Name
>        1     0x00000400      0x0000a3ff      "efs"
>        5     0x00026420      0x00026c1f      "dtbo"
>       12     0x0003f390      0x0074738f      "super"
>
> In that case, the loop in part_get_info_by_name() would break after
> partition #1, so any attempt to obtain "dtbo" or "super" partition will
> fail. Fix that by continuing to iterate over the remaining partitions to
> make sure none of the visible ones is missed. That makes "part" command
> (e.g. "part start", "part size") able to work with such tables.
>
> Fixes: 87b8530fe244 ("disk: part: implement generic function part_get_info_by_name()")
> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

> ---
>   disk/part.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/disk/part.c b/disk/part.c
> index 36b88205eca7..08c9331e059c 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -717,8 +717,11 @@ int part_get_info_by_name(struct blk_desc *desc, const char *name,
>   	for (i = 1; i < part_drv->max_entries; i++) {
>   		ret = part_drv->get_info(desc, i, info);
>   		if (ret != 0) {
> -			/* no more entries in table */
> -			break;
> +			/*
> +			 * Partition with this index can't be obtained, but
> +			 * further partitions might be, so keep checking.
> +			 */
> +			continue;
>   		}
>   		if (strcmp(name, (const char *)info->name) == 0) {
>   			/* matched */
Tom Rini April 12, 2024, 6:52 p.m. UTC | #2
On Thu, Mar 28, 2024 at 05:29:50PM -0500, Sam Protsenko wrote:

> In part_get_info_by_name() the inability to get some partition info
> shouldn't be a reason for dropping out of the loop. That might happen
> e.g. if the partition is hidden or unused. An example of such case are
> Samsung devices, where they use the "unused" GUID type
> (00000000-0000-0000-0000-000000000000) to indicate that the partition
> should be hidden from the OS. Such partitions might not be seen in
> "part list" output, which creates "gaps" in numbering in between of the
> visible partitions:
> 
>     Part    Start LBA       End LBA         Name
>       1     0x00000400      0x0000a3ff      "efs"
>       5     0x00026420      0x00026c1f      "dtbo"
>      12     0x0003f390      0x0074738f      "super"
> 
> In that case, the loop in part_get_info_by_name() would break after
> partition #1, so any attempt to obtain "dtbo" or "super" partition will
> fail. Fix that by continuing to iterate over the remaining partitions to
> make sure none of the visible ones is missed. That makes "part" command
> (e.g. "part start", "part size") able to work with such tables.
> 
> Fixes: 87b8530fe244 ("disk: part: implement generic function part_get_info_by_name()")
> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/disk/part.c b/disk/part.c
index 36b88205eca7..08c9331e059c 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -717,8 +717,11 @@  int part_get_info_by_name(struct blk_desc *desc, const char *name,
 	for (i = 1; i < part_drv->max_entries; i++) {
 		ret = part_drv->get_info(desc, i, info);
 		if (ret != 0) {
-			/* no more entries in table */
-			break;
+			/*
+			 * Partition with this index can't be obtained, but
+			 * further partitions might be, so keep checking.
+			 */
+			continue;
 		}
 		if (strcmp(name, (const char *)info->name) == 0) {
 			/* matched */