From 4b35702880a6145297b498397b42a563d6f1d8d2 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 21:19:37 +1100 Subject: [PATCH] media: apple: ave: test the firmware size refusal path Use the same segment-size predicate when matching a build and when validating the fallback variant. Cover both valid M2 builds and near misses in KUnit. Include the two observed segment sizes in the probe diagnostic. Signed-off-by: Ryan Murray --- drivers/media/platform/apple/ave/ave-abi-test.c | 9 ++++++++- drivers/media/platform/apple/ave/ave-fw.c | 17 +++++++++-------- drivers/media/platform/apple/ave/ave.h | 6 +++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/apple/ave/ave-abi-test.c b/drivers/media/platform/apple/ave/ave-abi-test.c index f8488c825e5cb..20e83305a7c78 100644 --- a/drivers/media/platform/apple/ave/ave-abi-test.c +++ b/drivers/media/platform/apple/ave/ave-abi-test.c @@ -1502,7 +1502,8 @@ static void ave_26b123_layout(struct kunit *test) /* * The M2 with the 27.2 stub: the reserved segment sizes select the 27.2 * build's own start (device 12, handshake type 12) and the 26B123 layout; - * the 13.5 build keeps the M2's 6070 start, and other sizes stay refused. + * the 13.5 build keeps the M2's 6070 start. Other sizes fall back to + * ave_t8112, whose size check in ave_fw_probe() then refuses them. */ static void ave_t8112_26b123_build(struct kunit *test) { @@ -1516,6 +1517,12 @@ static void ave_t8112_26b123_build(struct kunit *test) &ave_t8112); KUNIT_EXPECT_PTR_EQ(test, ave_fw_select_build(&ave_t8112, 0x134000, 0x128000), &ave_t8112); + /* The near misses are refused: no variant of the chain pins them. */ + KUNIT_EXPECT_FALSE(test, ave_fw_sizes_match(&ave_t8112, 0x11c000, 0x12c000)); + KUNIT_EXPECT_FALSE(test, ave_fw_sizes_match(&ave_t8112, 0x134000, 0x128000)); + KUNIT_EXPECT_FALSE(test, ave_fw_sizes_match(n, 0x11c000, 0x12c000)); + KUNIT_EXPECT_TRUE(test, ave_fw_sizes_match(&ave_t8112, 0xd0000, 0x128000)); + KUNIT_EXPECT_TRUE(test, ave_fw_sizes_match(n, 0x11c000, 0x128000)); KUNIT_EXPECT_NULL(test, n->next_build); KUNIT_EXPECT_TRUE(test, n->boot_qualified); KUNIT_EXPECT_PTR_EQ(test, n->regs, ave_t8112.regs); diff --git a/drivers/media/platform/apple/ave/ave-fw.c b/drivers/media/platform/apple/ave/ave-fw.c index fd2e056610a37..49f1da033411f 100644 --- a/drivers/media/platform/apple/ave/ave-fw.c +++ b/drivers/media/platform/apple/ave/ave-fw.c @@ -235,9 +235,11 @@ static const struct ave_fw_build *ave_fw_find_build(const struct ave_variant *v, return NULL; } -/* Whether these are the segment sizes of one of v's builds */ -static bool ave_fw_sizes_match(const struct ave_variant *v, size_t text, - size_t data) +/* + * Whether TEXT/DATA segments of these sizes are a build the variant pins. + * ave_fw_probe() refuses the firmware when they are not. + */ +bool ave_fw_sizes_match(const struct ave_variant *v, size_t text, size_t data) { if (v->build_count) return ave_fw_find_build(v, text, data, 0); @@ -297,12 +299,11 @@ int ave_fw_probe(struct ave_dev *ave) want_crc = build->text_crc; } else if (!ave->variant->boot_qualified && !ave->variant->fw_text_size) { /* A probe-only variant that pins no build takes any segment sizes. */ - } else if (ave->text.size != ave->variant->fw_text_size || - (ave->data.size != ave->variant->fw_data_size && - (!ave->variant->fw_data_size_alt || - ave->data.size != ave->variant->fw_data_size_alt))) { + } else if (!ave_fw_sizes_match(ave->variant, ave->text.size, + ave->data.size)) { return dev_err_probe(dev, -EINVAL, - "unexpected firmware segment sizes\n"); + "unexpected firmware segment sizes (TEXT %#zx DATA %#zx)\n", + ave->text.size, ave->data.size); } if ((ave->text.phys < ave->data.phys + ave->data.size && ave->data.phys < ave->text.phys + ave->text.size) || diff --git a/drivers/media/platform/apple/ave/ave.h b/drivers/media/platform/apple/ave/ave.h index ec2328aed0d57..a0bda7749166a 100644 --- a/drivers/media/platform/apple/ave/ave.h +++ b/drivers/media/platform/apple/ave/ave.h @@ -259,7 +259,10 @@ struct ave_variant { * The same encoder running another firmware build that a newer * bootloader preloads, with a start and command protocol of its own. * The firmware segment sizes the bootloader reserved select it. - * NULL when there is none. + * NULL when there is none. Use builds[] when the builds differ only + * in TEXT CRC (and command layout) but start the same way; use + * next_build when a build needs other start fields (boot device, + * handshake type, boot word, DATA handling) and has sizes of its own. */ const struct ave_variant *next_build; @@ -580,6 +583,7 @@ extern const struct ave_variant ave_t6000, ave_t6041, ave_t8112, ave_t8132, /* ave-fw.c */ u64 ave_fw_vcbar(const struct ave_variant *variant, u64 text_iova); int ave_fw_probe(struct ave_dev *ave); +bool ave_fw_sizes_match(const struct ave_variant *v, size_t text, size_t data); const struct ave_variant *ave_fw_select_build(const struct ave_variant *v, size_t text, size_t data); int ave_fw_text_id_crc(const void *text, size_t size, u32 cell_off,