part: Detect errors when reading partition tables

The logic for part_init() is not ideal, since it silently ignores read
errors. Each partition type tries to read the disk and presumably fails
as well. No error is reported, however, so there is no indication that
anything is wrong.

Update the function to return an error, and update each of the probe
functions to do the same, trying to minimise changes.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-07-01 17:32:41 -06:00
parent b3d8820e98
commit 235585cbc3
8 changed files with 77 additions and 23 deletions

View File

@@ -20,6 +20,7 @@
#include <vsprintf.h>
#include <asm/unaligned.h>
#include <linux/compiler.h>
#include <linux/err.h>
#include "part_dos.h"
#include <part.h>
@@ -103,12 +104,14 @@ static int part_test_dos(struct blk_desc *desc)
#ifndef CONFIG_XPL_BUILD
ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr,
DIV_ROUND_UP(desc->blksz, sizeof(legacy_mbr)));
long ret;
if (blk_dread(desc, 0, 1, (ulong *)mbr) != 1)
return -1;
ret = blk_dread(desc, 0, 1, (ulong *)mbr);
if (IS_ERR_VALUE(ret))
return ret;
if (test_block_type((unsigned char *)mbr) != DOS_MBR)
return -1;
return -ENOENT;
if (desc->sig_type == SIG_TYPE_NONE && mbr->unique_mbr_signature) {
desc->sig_type = SIG_TYPE_MBR;
@@ -118,10 +121,10 @@ static int part_test_dos(struct blk_desc *desc)
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);
if (blk_dread(desc, 0, 1, (ulong *)buffer) != 1)
return -1;
return -EIO;
if (test_block_type(buffer) != DOS_MBR)
return -1;
return -ENOENT;
#endif
return 0;