kunit_platfo...it_for_probe(9)
π 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 π₯
0on success π- negative errno on failure π
π SEE ALSO π
kernel file ./lib/kunit/platform.c plus its besties:
kunit_platform_device_alloc(9)kunit_platform_device_add(9)kunit_platform_device_register_full(9)kunit_platform_device_unregister(9)kunit_platform_driver_register(9)
π‘ 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms