From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 15/26] efi: block: fix sector size mismatch in block device registration and ops
Date: Fri, 26 Jun 2026 10:42:26 +0200 [thread overview]
Message-ID: <20260626084608.1388806-16-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260626084608.1388806-1-a.fatoum@barebox.org>
efi_bio_read/efi_bio_write use a hardcoded 512 byte multiplier for the
block sizes, while registration happens with whatever block size the EFI
Block I/O protocol had reported.
Drop the hardcoded 512 byte sector sizes and while at it, use
block_size_bits(), so invalid block sizes are rejected early.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/block/efi-block-io.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/block/efi-block-io.c b/drivers/block/efi-block-io.c
index 8955a8c2b585..5f38409fb76d 100644
--- a/drivers/block/efi-block-io.c
+++ b/drivers/block/efi-block-io.c
@@ -34,7 +34,7 @@ static int efi_bio_read(struct block_device *blk, void *buffer, sector_t block,
efi_status_t efiret;
efiret = priv->protocol->read(priv->protocol, priv->media_id,
- block, num_blocks * 512, buffer);
+ block, num_blocks << blk->blockbits, buffer);
if (EFI_ERROR(efiret))
return -efi_errno(efiret);
@@ -49,7 +49,7 @@ static int efi_bio_write(struct block_device *blk,
efi_status_t efiret;
efiret = priv->protocol->write(priv->protocol, priv->media_id,
- block, num_blocks * 512, (void *)buffer);
+ block, num_blocks << blk->blockbits, (void *)buffer);
if (EFI_ERROR(efiret))
return -efi_errno(efiret);
@@ -115,7 +115,7 @@ static bool is_bio_usbdev(struct efi_device *efidev)
static int efi_bio_probe(struct efi_device *efidev)
{
bool is_usbdev;
- int instance;
+ int blockbits, instance;
struct efi_bio_priv *priv;
struct efi_block_io_media *media;
struct device *dev = &efidev->dev;
@@ -124,13 +124,22 @@ static int efi_bio_probe(struct efi_device *efidev)
BS->handle_protocol(efidev->handle, &efi_block_io_protocol_guid,
(void **)&priv->protocol);
- if (!priv->protocol)
+ if (!priv->protocol) {
+ free(priv);
return -ENODEV;
+ }
+
+
+ media = priv->protocol->media;
+ blockbits = block_size_bits(dev, media->block_size);
+ if (blockbits < 0) {
+ free(priv);
+ return blockbits;
+ }
dev->priv = priv;
devinfo_add(dev, efi_bio_print_info);
- media = priv->protocol->media;
if (__is_defined(DEBUG))
efi_bio_print_info(dev);
priv->dev = &efidev->dev;
@@ -147,7 +156,7 @@ static int efi_bio_probe(struct efi_device *efidev)
priv->blk.cdev.name = xasprintf("disk%d", instance);
}
- priv->blk.blockbits = ffs(media->block_size) - 1;
+ priv->blk.blockbits = blockbits;
priv->blk.num_blocks = media->last_block + 1;
priv->blk.ops = &efi_bio_ops;
priv->blk.dev = &efidev->dev;
--
2.47.3
next prev parent reply other threads:[~2026-06-26 8:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 01/26] nvme: use barebox-appropriate 64-bit type for timeouts Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 02/26] nvme: fix buffer advancement when chunking due to max_hw_sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 03/26] nvme: allow flush opcode Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 04/26] nvme: honor namespace block size for I/O Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 05/26] bootscan: fix detection of GPT Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 06/26] block: clarify that writebuffer_io_len returns sector counts Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 07/26] block: fix wrong type for discard_start/size byte ranges Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 08/26] block: fix discard zeroing too little memory Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 09/26] block: use logical block size for reparse checks Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 10/26] block: require lower bound of sector size to be 512 bytes Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 11/26] filetype: don't hardcode sector size in file_detect_partition_table Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 12/26] block: define helpers for non-512-byte sector support Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 13/26] bootscan: use block size for partition table probe Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 14/26] ramdisk: validate exported sector size Ahmad Fatoum
2026-06-26 8:42 ` Ahmad Fatoum [this message]
2026-06-26 8:42 ` [PATCH 16/26] efi: loader: disk: report block device size in Block I/O Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 17/26] efi: loader: file: report cdev block size in file info Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 18/26] partitions: use byte offset for first partition policy Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 19/26] partitions: dos: allocate correctly sized buffer for dos_partition_desc Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 20/26] partition: support non-512 byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 21/26] fs: fat: fix garbage read when writing with bigger block size Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 22/26] fs: fat: support larger block device sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 23/26] usb-storage: preserve READ CAPACITY sector size Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 24/26] fuzz: add 4K-sector partition ramdisk target Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 25/26] commands: parted: prepare use of non-512-byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 26/26] commands: parted: exit if block size if not 512 Ahmad Fatoum
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=20260626084608.1388806-16-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--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