Wander Lairson Costa
unread,Apr 18, 2024, 5:02:57 PM4/18/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Brendan Higgins, David Gow, Rae Moar, Greg Kroah-Hartman, Shuah Khan, Maxime Ripard, Matti Vaittinen, open list:KERNEL UNIT TESTING FRAMEWORK (KUnit), open list:KERNEL UNIT TESTING FRAMEWORK (KUnit), open list, Wander Lairson Costa
If the device register fails, free the allocated memory before
returning.
Signed-off-by: Wander Lairson Costa <
wan...@redhat.com>
Fixes: d03c720e03bd ("kunit: Add APIs for managing devices")
---
lib/kunit/device.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/kunit/device.c b/lib/kunit/device.c
index 25c81ed465fb..bc2e2032e505 100644
--- a/lib/kunit/device.c
+++ b/lib/kunit/device.c
@@ -119,10 +119,8 @@ static struct kunit_device *kunit_device_register_internal(struct kunit *test,
kunit_dev->owner = test;
err = dev_set_name(&kunit_dev->dev, "%s.%s", test->name, name);
- if (err) {
- kfree(kunit_dev);
- return ERR_PTR(err);
- }
+ if (err)
+ goto error;
kunit_dev->dev.release = kunit_device_release;
kunit_dev->dev.bus = &kunit_bus_type;
@@ -131,7 +129,7 @@ static struct kunit_device *kunit_device_register_internal(struct kunit *test,
err = device_register(&kunit_dev->dev);
if (err) {
put_device(&kunit_dev->dev);
- return ERR_PTR(err);
+ goto error;
}
kunit_dev->dev.dma_mask = &kunit_dev->dev.coherent_dma_mask;
@@ -140,6 +138,9 @@ static struct kunit_device *kunit_device_register_internal(struct kunit *test,
kunit_add_action(test, device_unregister_wrapper, &kunit_dev->dev);
return kunit_dev;
+error:
+ kfree(kunit_dev);
+ return ERR_PTR(err);
}
/*
--
2.44.0