mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/6] partitions: gpt: pass epd context pointer to find_valid_gpt()
Date: Mon, 15 Dec 2025 13:28:45 +0100	[thread overview]
Message-ID: <fe7cae90-6696-4a0e-8e23-01e34db51fa0@pengutronix.de> (raw)
In-Reply-To: <20251203-efi-partition-refresh-v1-1-f0b6e79b5fa0@pengutronix.de>



On 12/3/25 4:19 PM, Sascha Hauer wrote:
> Pass the epd context pointer to find_valid_gpt() which we'll use in a
> followup patch. This makes other arguments unnecessary, so they are
> dropped. While at it change the return value of find_valid_gpt() to
> standard 0 for success and negative error code otherwise.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

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

> ---
>  common/partitions/efi.c | 58 ++++++++++++++++++++++++-------------------------
>  1 file changed, 29 insertions(+), 29 deletions(-)
> 
> diff --git a/common/partitions/efi.c b/common/partitions/efi.c
> index 88d8a2d739c4e545952684f5647d105d9f38b028..da9c2d89c1c68ae1acebc1f8eaea8da48243f0d6 100644
> --- a/common/partitions/efi.c
> +++ b/common/partitions/efi.c
> @@ -381,11 +381,10 @@ compare_gpts(struct device *dev, gpt_header *pgpt, gpt_header *agpt,
>  
>  /**
>   * find_valid_gpt() - Search disk for valid GPT headers and PTEs
> - * @state
> - * @gpt is a GPT header ptr, filled on return.
> - * @ptes is a PTEs ptr, filled on return.
> - * Description: Returns 1 if valid, 0 on error.
> - * If valid, returns pointers to newly allocated GPT header and PTEs.
> + * @buf buffer containing the first lba
> + * @epd the efi partition descriptor context pointer
> + * Description: Returns 0 for success, negative error code otherwise.
> + * If valid, epd is filled with pointers to newly allocated GPT header and PTEs.
>   * Validity depends on PMBR being valid (or being overridden by the
>   * 'gpt' kernel command line option) and finding either the Primary
>   * GPT header and PTEs valid, or the Alternate GPT header and PTEs
> @@ -394,17 +393,14 @@ compare_gpts(struct device *dev, gpt_header *pgpt, gpt_header *agpt,
>   * This protects against devices which misreport their size, and forces
>   * the user to decide to use the Alternate GPT.
>   */
> -static int find_valid_gpt(void *buf, struct block_device *blk, gpt_header **gpt,
> -			  gpt_entry **ptes)
> +static int find_valid_gpt(struct efi_partition_desc *epd, void *buf)
>  {
> +	struct block_device *blk = epd->pd.blk;
>  	int good_pgpt = 0, good_agpt = 0;
>  	gpt_header *pgpt = NULL, *agpt = NULL;
>  	gpt_entry *pptes = NULL, *aptes = NULL;
>  	u64 lastlba;
>  
> -	if (!ptes)
> -		return 0;
> -
>  	lastlba = last_lba(blk);
>  	if (force_gpt) {
>  		/* This will be added to the EFI Spec. per Intel after v1.02. */
> @@ -430,21 +426,20 @@ static int find_valid_gpt(void *buf, struct block_device *blk, gpt_header **gpt,
>  
>  	/* The good cases */
>  	if (good_pgpt) {
> -		*gpt  = pgpt;
> -		*ptes = pptes;
> +		epd->gpt  = pgpt;
> +		epd->ptes = pptes;
>  		free(agpt);
>  		free(aptes);
>  		if (!good_agpt)
>  			dev_warn(blk->dev, "Alternate GPT is invalid, using primary GPT.\n");
> -		return 1;
> -	}
> -	else if (good_agpt) {
> -		*gpt  = agpt;
> -		*ptes = aptes;
> +		return 0;
> +	} else {
> +		epd->gpt  = agpt;
> +		epd->ptes = aptes;
>  		free(pgpt);
>  		free(pptes);
>  		dev_warn(blk->dev, "Primary GPT is invalid, using alternate GPT.\n");
> -		return 1;
> +		return 0;
>  	}
>  
>   fail:
> @@ -452,9 +447,8 @@ static int find_valid_gpt(void *buf, struct block_device *blk, gpt_header **gpt,
>  	free(agpt);
>  	free(pptes);
>  	free(aptes);
> -	*gpt = NULL;
> -	*ptes = NULL;
> -	return 0;
> +
> +	return -EINVAL;
>  }
>  
>  static void part_set_efi_name(gpt_entry *pte, char *dest)
> @@ -516,9 +510,17 @@ static struct partition_desc *efi_partition(void *buf, struct block_device *blk)
>  	struct efi_partition *epart;
>  	struct partition *pentry;
>  	struct efi_partition_desc *epd;
> +	int ret;
>  
> -	if (!find_valid_gpt(buf, blk, &gpt, &ptes) || !gpt || !ptes)
> -		return NULL;
> +	epd = xzalloc(sizeof(*epd));
> +	partition_desc_init(&epd->pd, blk);
> +
> +	ret = find_valid_gpt(epd, buf);
> +	if (ret)
> +		goto err;
> +
> +	gpt = epd->gpt;
> +	ptes = epd->ptes;
>  
>  	blk->cdev.flags |= DEVFS_IS_GPT_PARTITIONED;
>  
> @@ -530,12 +532,6 @@ static struct partition_desc *efi_partition(void *buf, struct block_device *blk)
>  		nb_part = MAX_PARTITION;
>  	}
>  
> -	epd = xzalloc(sizeof(*epd));
> -	partition_desc_init(&epd->pd, blk);
> -
> -	epd->gpt = gpt;
> -	epd->ptes = ptes;
> -
>  	snprintf(blk->cdev.diskuuid, sizeof(blk->cdev.diskuuid), "%pUl", &gpt->disk_guid);
>  	add_gpt_diskuuid_param(epd, blk);
>  
> @@ -560,6 +556,10 @@ static struct partition_desc *efi_partition(void *buf, struct block_device *blk)
>  	}
>  
>  	return &epd->pd;
> +err:
> +	free(epd);
> +
> +	return NULL;
>  }
>  
>  static void efi_partition_free(struct partition_desc *pd)
> 

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




  reply	other threads:[~2025-12-15 12:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-03 15:19 [PATCH 0/6] partitions: GPT: refresh partition tables when necessary Sascha Hauer
2025-12-03 15:19 ` [PATCH 1/6] partitions: gpt: pass epd context pointer to find_valid_gpt() Sascha Hauer
2025-12-15 12:28   ` Ahmad Fatoum [this message]
2025-12-03 15:19 ` [PATCH 2/6] partitions: gpt: only write actual ptes size to device Sascha Hauer
2025-12-15 12:29   ` Ahmad Fatoum
2025-12-03 15:19 ` [PATCH 3/6] partitions: gpt: factor out a function to write primary/alternate GPT Sascha Hauer
2025-12-15 12:34   ` Ahmad Fatoum
2025-12-03 15:19 ` [PATCH 4/6] partitions: gpt: write inactive GPT first Sascha Hauer
2025-12-15 12:38   ` Ahmad Fatoum
2025-12-03 15:19 ` [PATCH 5/6] partitions: gpt: fix GPT restauration from alternate GPT Sascha Hauer
2025-12-15 12:41   ` Ahmad Fatoum
2025-12-03 15:19 ` [PATCH 6/6] partitions: gpt: refresh partition tables when necessary Sascha Hauer
2025-12-15 12:47   ` Ahmad Fatoum
2025-12-15 14:13     ` Sascha Hauer
2025-12-15 14:15       ` Ahmad Fatoum
2025-12-15 14:09 ` [PATCH 0/6] partitions: GPT: " Sascha Hauer

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=fe7cae90-6696-4a0e-8e23-01e34db51fa0@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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