kunit_platfo...it_for_probe(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… kunit_platform_device_prepare_wait_for_probe(9)

okay bestie, welcome to the Kernel API Manual ✨ β€” this one's a lil helper from the KUnit platform device crowd, and it's genuinely so useful once you get the vibe. Let me spill πŸ«–


🌸 NAME 🌸

kunit_platform_device_prepare_wait_for_probe β€” prepare a completion variable so you can wait for a platform device to probe πŸŽ€


✨ SYNOPSIS ✨

int kunit_platform_device_prepare_wait_for_probe (struct kunit *test ,
struct platform_device *pdev , struct completion *x );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • test β€” the test context, your main character ✨
  • pdev β€” the platform device you're getting ready to wait on for its probe πŸ‘€
  • x β€” the completion variable that gets completed once the dev has probed πŸ’–

πŸ’œ DESCRIPTION πŸ’œ

So basically, this function preps a completion variable x so you can wait for pdev to probe. And here's the lowkey important part: waiting on that completion forces a preemption, which is what lets the platform driver actually go ahead and probe. It's giving "make room so the driver can do its thing" 🧚 no cap.

πŸ“ Example πŸ“

static int kunit_platform_driver_probe(struct platform_device *pdev)
{
        return 0;
}

static void kunit_platform_driver_test(struct kunit *test)
{
        struct platform_device *pdev;
        struct platform_driver *pdrv;
        DECLARE_COMPLETION_ONSTACK(comp);

        pdev = kunit_platform_device_alloc(test, "kunit-platform", -1);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
        KUNIT_ASSERT_EQ(test, 0, kunit_platform_device_add(test, pdev));

        pdrv = kunit_kzalloc(test, sizeof(*pdrv), GFP_KERNEL);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdrv);

        pdrv->probe = kunit_platform_driver_probe;
        pdrv->driver.name = "kunit-platform";
        pdrv->driver.owner = THIS_MODULE;

        KUNIT_ASSERT_EQ(test, 0, kunit_platform_device_prepare_wait_for_probe(test, pdev, comp));
        KUNIT_ASSERT_EQ(test, 0, kunit_platform_driver_register(test, pdrv));

        KUNIT_EXPECT_NE(test, 0, wait_for_completion_timeout(comp, 3 * HZ));
}

like, look at that flow 😭 it's iconic. allocate, add, register, wait β€” periodt.


πŸ”₯ RETURN πŸ”₯

  • 0 on success πŸŽ‰
  • negative errno on failure πŸ’€

🌈 SEE ALSO 🌈

kernel file ./lib/kunit/platform.c plus its besties:


πŸ’‘ reminder bestie: waiting on the completion is the whole point β€” it's what forces the preemption so the driver can probe. don't skip the vibe check on that one 🫢

and that's the whole page! brought to you by <pink>./lib/kunit</pink> πŸ’– dated <purple>October 2026</purple> πŸ—“οΈ β€” go forth and probe, queen πŸ‘‘πŸ’…

πŸ“¦ where this page comes from