[PATCH 8/9] firewire: cdev: use cleanup function for descriptor_resource allocation

From: Takashi Sakamoto

Date: Sun Nov 01 2026 - 23:22:19 EST


Use a cleanup function to simplify error handling when allocating a
descriptor_resource object.

Signed-off-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>
---
drivers/firewire/core-cdev.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index f94b22a608e9..ef4fca7e8363 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -960,7 +960,7 @@ static void release_descriptor(struct client *client,
static int ioctl_add_descriptor(struct client *client, union ioctl_arg *arg)
{
struct fw_cdev_add_descriptor *a = &arg->add_descriptor;
- struct descriptor_resource *r;
+ struct descriptor_resource *r __free(kfree) = NULL;
int ret;

/* Access policy: Allow this ioctl only on local nodes' device files. */
@@ -974,11 +974,8 @@ static int ioctl_add_descriptor(struct client *client, union ioctl_arg *arg)
if (r == NULL)
return -ENOMEM;

- if (copy_from_user(r->data, u64_to_uptr(a->data),
- flex_array_size(r, data, a->length))) {
- ret = -EFAULT;
- goto failed;
- }
+ if (copy_from_user(r->data, u64_to_uptr(a->data), flex_array_size(r, data, a->length)))
+ return -EFAULT;

r->descriptor.length = a->length;
r->descriptor.immediate = a->immediate;
@@ -987,20 +984,16 @@ static int ioctl_add_descriptor(struct client *client, union ioctl_arg *arg)

ret = fw_core_add_descriptor(&r->descriptor);
if (ret < 0)
- goto failed;
+ return ret;

ret = add_client_resource(client, &r->resource, release_descriptor);
if (ret < 0) {
fw_core_remove_descriptor(&r->descriptor);
- goto failed;
+ return ret;
}
- a->handle = r->resource.handle;
+ a->handle = no_free_ptr(r)->resource.handle;

return 0;
- failed:
- kfree(r);
-
- return ret;
}

static int ioctl_remove_descriptor(struct client *client, union ioctl_arg *arg)
--
2.53.0