mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] partitions: Increase MAX_PARTITION to 128
@ 2021-06-02  7:15 Sascha Hauer
  2021-06-02  7:15 ` [PATCH 2/2] partitions: efi: Fix MAX_PARTITION check Sascha Hauer
  2021-06-02  9:20 ` [PATCH 1/2] partitions: Increase MAX_PARTITION to 128 Ahmad Fatoum
  0 siblings, 2 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-06-02  7:15 UTC (permalink / raw)
  To: Barebox List

Having MAX_PARTITION defined to 8 is enough for a DOS partition table,
but not for GPT. Increase it to the maximum GPT supports. It might be
even better to allocate the partitions dynamically, but for nor take the
easy way out.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/partitions/parser.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/partitions/parser.h b/common/partitions/parser.h
index 8ad134a9aa..69508932b3 100644
--- a/common/partitions/parser.h
+++ b/common/partitions/parser.h
@@ -11,7 +11,7 @@
 #include <filetype.h>
 #include <linux/list.h>
 
-#define MAX_PARTITION		8
+#define MAX_PARTITION		128
 #define MAX_PARTITION_NAME	38
 
 struct partition {
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] partitions: efi: Fix MAX_PARTITION check
  2021-06-02  7:15 [PATCH 1/2] partitions: Increase MAX_PARTITION to 128 Sascha Hauer
@ 2021-06-02  7:15 ` Sascha Hauer
  2021-06-02  9:17   ` Ahmad Fatoum
  2021-06-02  9:20 ` [PATCH 1/2] partitions: Increase MAX_PARTITION to 128 Ahmad Fatoum
  1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2021-06-02  7:15 UTC (permalink / raw)
  To: Barebox List

The GPT partiton parser has a check which should check if the GPT has
more partitions than we support. This doesn't work because the loop
iterating over the partitions exits with a maximum i of MAX_PARTITION,
i > MAX_PARTITION will never be true. Fix the check.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/partitions/efi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 437c3d64f8..135b08901a 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -446,7 +446,14 @@ static void efi_partition(void *buf, struct block_device *blk,
 	}
 
 	nb_part = le32_to_cpu(gpt->num_partition_entries);
-	for (i = 0; i < MAX_PARTITION && i < nb_part; i++) {
+
+	if (nb_part > MAX_PARTITION) {
+		dev_warn(blk->dev, "GPT has more partitions than we support (%d) > max partition number (%d)\n",
+			 nb_part, MAX_PARTITION);
+		nb_part = MAX_PARTITION;
+	}
+
+	for (i = 0; i < nb_part; i++) {
 		if (!is_pte_valid(&ptes[i], last_lba(blk))) {
 			dev_dbg(blk->dev, "Invalid pte %d\n", i);
 			return;
@@ -460,10 +467,6 @@ static void efi_partition(void *buf, struct block_device *blk,
 		snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
 		pd->used_entries++;
 	}
-
-	if (i > MAX_PARTITION)
-		dev_warn(blk->dev, "num_partition_entries (%d) > max partition number (%d)\n",
-			 nb_part, MAX_PARTITION);
 }
 
 static struct partition_parser efi_partition_parser = {
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] partitions: efi: Fix MAX_PARTITION check
  2021-06-02  7:15 ` [PATCH 2/2] partitions: efi: Fix MAX_PARTITION check Sascha Hauer
@ 2021-06-02  9:17   ` Ahmad Fatoum
  0 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2021-06-02  9:17 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List



On 02.06.21 09:15, Sascha Hauer wrote:
> The GPT partiton parser has a check which should check if the GPT has
> more partitions than we support. This doesn't work because the loop
> iterating over the partitions exits with a maximum i of MAX_PARTITION,
> i > MAX_PARTITION will never be true. Fix the check.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  common/partitions/efi.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/common/partitions/efi.c b/common/partitions/efi.c
> index 437c3d64f8..135b08901a 100644
> --- a/common/partitions/efi.c
> +++ b/common/partitions/efi.c
> @@ -446,7 +446,14 @@ static void efi_partition(void *buf, struct block_device *blk,
>  	}
>  
>  	nb_part = le32_to_cpu(gpt->num_partition_entries);
> -	for (i = 0; i < MAX_PARTITION && i < nb_part; i++) {
> +
> +	if (nb_part > MAX_PARTITION) {
> +		dev_warn(blk->dev, "GPT has more partitions than we support (%d) > max partition number (%d)\n",
> +			 nb_part, MAX_PARTITION);
> +		nb_part = MAX_PARTITION;
> +	}
> +
> +	for (i = 0; i < nb_part; i++) {
>  		if (!is_pte_valid(&ptes[i], last_lba(blk))) {
>  			dev_dbg(blk->dev, "Invalid pte %d\n", i);
>  			return;
> @@ -460,10 +467,6 @@ static void efi_partition(void *buf, struct block_device *blk,
>  		snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
>  		pd->used_entries++;
>  	}
> -
> -	if (i > MAX_PARTITION)
> -		dev_warn(blk->dev, "num_partition_entries (%d) > max partition number (%d)\n",
> -			 nb_part, MAX_PARTITION);
>  }
>  
>  static struct partition_parser efi_partition_parser = {
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] partitions: Increase MAX_PARTITION to 128
  2021-06-02  7:15 [PATCH 1/2] partitions: Increase MAX_PARTITION to 128 Sascha Hauer
  2021-06-02  7:15 ` [PATCH 2/2] partitions: efi: Fix MAX_PARTITION check Sascha Hauer
@ 2021-06-02  9:20 ` Ahmad Fatoum
  1 sibling, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2021-06-02  9:20 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On 02.06.21 09:15, Sascha Hauer wrote:
> Having MAX_PARTITION defined to 8 is enough for a DOS partition table,
> but not for GPT. Increase it to the maximum GPT supports. It might be
> even better to allocate the partitions dynamically, but for nor take the
> easy way out.

Given that struct partition_desc is only ever dynamically allocated, I think
that's ok.

> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviwed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  common/partitions/parser.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/partitions/parser.h b/common/partitions/parser.h
> index 8ad134a9aa..69508932b3 100644
> --- a/common/partitions/parser.h
> +++ b/common/partitions/parser.h
> @@ -11,7 +11,7 @@
>  #include <filetype.h>
>  #include <linux/list.h>
>  
> -#define MAX_PARTITION		8
> +#define MAX_PARTITION		128
>  #define MAX_PARTITION_NAME	38
>  
>  struct partition {
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-02  9:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02  7:15 [PATCH 1/2] partitions: Increase MAX_PARTITION to 128 Sascha Hauer
2021-06-02  7:15 ` [PATCH 2/2] partitions: efi: Fix MAX_PARTITION check Sascha Hauer
2021-06-02  9:17   ` Ahmad Fatoum
2021-06-02  9:20 ` [PATCH 1/2] partitions: Increase MAX_PARTITION to 128 Ahmad Fatoum

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git