mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 2/6] partitions: gpt: refresh also when primary or alternate is invalid
Date: Wed, 01 Jul 2026 11:27:35 +0200	[thread overview]
Message-ID: <20260701-gpt-size-fixes-v1-2-aec2e5641a19@pengutronix.de> (raw)
In-Reply-To: <20260701-gpt-size-fixes-v1-0-aec2e5641a19@pengutronix.de>

Currently we only refresh/repair when primary and alternate GPT differ. When
either of them is missing, we should repair as well.

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

diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 28198f25b1..98172672ff 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -385,10 +385,20 @@ compare_gpts(struct block_device *blk, gpt_header *pgpt, gpt_header *agpt,
 	     u64 lastlba)
 {
 	struct device *dev = blk->dev;
-
 	int error_found = 0;
-	if (!pgpt || !agpt)
-		return;
+
+	if (!pgpt) {
+		dev_warn(dev, "GPT:Primary GPT not found\n");
+		error_found++;
+		goto refresh;
+	}
+
+	if (!agpt) {
+		dev_warn(dev, "GPT:Alternate GPT not found\n");
+		error_found++;
+		goto refresh;
+	}
+
 	if (le64_to_cpu(pgpt->my_lba) != le64_to_cpu(agpt->alternate_lba)) {
 		dev_warn(dev,
 		       "GPT:Primary header LBA != Alt. header alternate_lba\n");
@@ -469,15 +479,15 @@ compare_gpts(struct block_device *blk, gpt_header *pgpt, gpt_header *agpt,
 		error_found++;
 	}
 
-	if (error_found) {
-		add_gpt_refresh(blk);
-		if (!IS_ENABLED(CONFIG_PARTITION_DISK_EFI_REFRESH))
-			dev_info(dev, "GPT: will repair later if global.system.gpt_refresh=1\n");
-		else
-			dev_warn(dev, "GPT: Use parted to correct GPT errors.\n");
-	}
+	if (!error_found)
+		return;
 
-	return;
+refresh:
+	add_gpt_refresh(blk);
+	if (!IS_ENABLED(CONFIG_PARTITION_DISK_EFI_REFRESH))
+		dev_info(dev, "GPT: will repair later if global.system.gpt_refresh=1\n");
+	else
+		dev_warn(dev, "GPT: Use parted to correct GPT errors.\n");
 }
 
 /**

-- 
2.47.3




  parent reply	other threads:[~2026-07-01  9:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  9:27 [PATCH 0/6] GPT: fixes around last_usable_lba Sascha Hauer
2026-07-01  9:27 ` [PATCH 1/6] partitions: gpt: Adjust last_usable_lba to real device size when writing Sascha Hauer
2026-07-01  9:27 ` Sascha Hauer [this message]
2026-07-01  9:27 ` [PATCH 3/6] partitions: gpt: validate mkpart range against GPT usable LBAs Sascha Hauer
2026-07-01  9:27 ` [PATCH 4/6] partitions: check new partitions against usable LBAs, not device size Sascha Hauer
2026-07-01  9:27 ` [PATCH 5/6] partitions: gpt: fix wrong error messages Sascha Hauer
2026-07-01  9:27 ` [PATCH 6/6] partitions: gpt: log a message when partition table refreshed 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=20260701-gpt-size-fixes-v1-2-aec2e5641a19@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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