/** * kunit_platform_device_alloc() - Allocate a KUnit test managed platform device * @test: test context * @name: device name of platform device to alloc * @id: identifier of platform device to alloc. * * Allocate a test managed platform device. The device is put when the test completes. * * Return: Allocated platform device on success, NULL on failure.
*/ struct platform_device *
kunit_platform_device_alloc(struct kunit *test, constchar *name, int id)
{ struct kunit_platform_device_alloc_params params = {
.name = name,
.id = id,
};
KUNIT_DEFINE_ACTION_WRAPPER(platform_device_unregister_wrapper,
platform_device_unregister, struct platform_device *); /** * kunit_platform_device_add() - Register a KUnit test managed platform device * @test: test context * @pdev: platform device to add * * Register a test managed platform device. The device is unregistered when the * test completes. * * Return: 0 on success, negative errno on failure.
*/ int kunit_platform_device_add(struct kunit *test, struct platform_device *pdev)
{ struct kunit_resource *res; int ret;
ret = platform_device_add(pdev); if (ret) return ret;
res = kunit_find_resource(test, kunit_platform_device_alloc_match, pdev); if (res) { /* * Transfer the reference count of the platform device if it * was allocated with kunit_platform_device_alloc(). In this * case, calling platform_device_put() when the test exits from * kunit_platform_device_alloc_exit() would lead to reference * count underflow because platform_device_unregister_wrapper() * calls platform_device_unregister() which also calls * platform_device_put(). * * Usually callers transfer the refcount initialized in * platform_device_alloc() to platform_device_add() by calling * platform_device_unregister() when platform_device_add() * succeeds or platform_device_put() when it fails. KUnit has to * keep this straight by redirecting the free routine for the * resource to the right function. Luckily this only has to * account for the success scenario.
*/
res->free = kunit_platform_device_add_exit;
kunit_put_resource(res);
} else {
ret = kunit_add_action_or_reset(test, platform_device_unregister_wrapper, pdev); if (ret) return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.