From patchwork Fri Feb 20 00:19:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1904 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771546791; bh=PW0tmYyaDkSixSaizyzxnlBqYZmvIqQE1Vy6DRmHMlg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=baWvx743JcXpNuFYVdqY6hk22qLb1V/K35BT8uRVlwuPlfz5Mmhe56dT4vS4EX9ww hdw1aCUMY6FYCrQfrxS4wqk020Sevd5TuxOO25Tf5P1WwDF6o/1CnKWgXqvbIh2yoU ozupveNJ8l7IvU99NdTIjFOCUkyA0RJJOerV0JHpxrEXG6sqIcKnfkgaRO2oZWDOFg ceohLj4aD7dehGgBi7L6yhFgJCQ1XUNsRsjtYMCVYgAE/yq3Wu96W7OiOhdG8d852+ Ts84Lv9aOiO2XjoWSWlN+vNYYKvtSHV+t5wXUg7UMr4VJNhoRqXWznSdr/ZwxJvK7+ Twwyob37yS1LA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 35C5469C8E for ; Thu, 19 Feb 2026 17:19:51 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id DlwwbeYfqwVr for ; Thu, 19 Feb 2026 17:19:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771546791; bh=PW0tmYyaDkSixSaizyzxnlBqYZmvIqQE1Vy6DRmHMlg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=baWvx743JcXpNuFYVdqY6hk22qLb1V/K35BT8uRVlwuPlfz5Mmhe56dT4vS4EX9ww hdw1aCUMY6FYCrQfrxS4wqk020Sevd5TuxOO25Tf5P1WwDF6o/1CnKWgXqvbIh2yoU ozupveNJ8l7IvU99NdTIjFOCUkyA0RJJOerV0JHpxrEXG6sqIcKnfkgaRO2oZWDOFg ceohLj4aD7dehGgBi7L6yhFgJCQ1XUNsRsjtYMCVYgAE/yq3Wu96W7OiOhdG8d852+ Ts84Lv9aOiO2XjoWSWlN+vNYYKvtSHV+t5wXUg7UMr4VJNhoRqXWznSdr/ZwxJvK7+ Twwyob37yS1LA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 25D9A69C89 for ; Thu, 19 Feb 2026 17:19:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771546790; bh=P5K79Z5YQwkFJvoX8WVbPPiFR6R17ulUboEpvt5sB5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DuPQcDBzUR2hFveJJIvbClGG2iJ5vxOX5t7WfLaYGMjgyEOi65n/zsf7awcHsagD/ ZIlRD5pb14coSGrZhyurbDAPXPAtpQOuwff9UV06YqE1zj8wxLAWpHYsDpq/dhVs4L uypFh7krzXYdlDqJSECIpvru0rdIUhiTuKOBh1QnXZPwPZ48xcY3C85rx1mBh4IUfk knb+SwqnpxGEZ15XreggMFBrCnbVkBf/TWdFDglRS91sLbQcNAusenBFmX+iREtUXZ kRhaW0cHKIlnvD39SbxamjA9eGJ3GClUhP3V/RFIcKFoEW2pXYaveeb8GWsTGknVNg w2e/zI9JZErdg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7840169C85; Thu, 19 Feb 2026 17:19:50 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id oriZyq175fGC; Thu, 19 Feb 2026 17:19:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771546786; bh=vh5ap5vIJ5YIdWDDFmbh7eH54ZtKKDSemkJGxjUPCeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IOFzgm2nn61uZ+FWziV84tXzkQ66kDc1qKRRYdHrMLjeJ2lv2eOC9NzpPz8TqJHGk 6maG4bQsiNjYpklYCv9MeY5tyrFeneMXQpgIOOpz/VX1IgIXDmGFBfGYX6LnrnimAw rebykj8t5a3vsxodcX0pOuIhf3B/D26PmMVXYoV1rzix1eZuErhX7qvCPdGpiUtel3 PwThYKnTpX2zuiTM8PPDYaeKmB29/z8DeFS5oZf7RE0Y2itIJ637oXLdJvAECtDu8L s9fIvZLrJQigc3RsNangqSCgK72qhsm054yesX6K4wGEocF3UYQWEt3pP/Do8Z+B7o UY74vX4E0nwZw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2A08F69C7C; Thu, 19 Feb 2026 17:19:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Thu, 19 Feb 2026 17:19:10 -0700 Message-ID: <20260220001926.2366140-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260220001926.2366140-1-sjg@u-boot.org> References: <20260220001926.2366140-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: DJX3YFJYECERQMU7Y65X6FC4BAK7VB6L X-Message-ID-Hash: DJX3YFJYECERQMU7Y65X6FC4BAK7VB6L X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/13] disk: part_efi: Check the block size in part_test_efi() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The ALLOC_CACHE_ALIGN_BUFFER_PAD() macro divides by desc->blksz to compute alignment padding, causing a Divide Error when blksz is 0. This happens when bootmeth_rauc scans block devices that have no block size set. This happens on qemu-x86, for example. Return -ENOENT early when blksz is zero, since a device without a block size cannot have a valid EFI partition table. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- disk/part_efi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index fbed515b303..b48ff518b03 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -314,9 +314,18 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, static int part_test_efi(struct blk_desc *desc) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, desc->blksz); long ret; + /* + * An ATAPI device (e.g. CD-ROM) may have blksz == 0 if the + * capacity query failed or no media is present. The buffer + * macro below divides by blksz, so bail out early. + */ + if (!desc->blksz) + return -ENOENT; + + ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, desc->blksz); + /* Read legacy MBR from block 0 and validate it */ ret = blk_dread(desc, 0, 1, (ulong *)legacymbr); if (IS_ERR_VALUE(ret))