]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
firewire: core: code cleanup for iso resource auto creation
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 29 Apr 2026 09:34:48 +0000 (18:34 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 29 Apr 2026 11:30:34 +0000 (20:30 +0900)
The init_iso_resource function is only called by
ioctl_allocate_iso_resource(), thus no need to be unique.

This commit unifies them with minor code refactoring.

Link: https://lore.kernel.org/r/20260429093449.160545-8-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
drivers/firewire/core-cdev.c

index b3ce34d777c31275025b56c1d6c031d961d61409..bcfb20b770df5c2597f6e413500720a8e012b770 100644 (file)
@@ -1424,23 +1424,20 @@ static void release_iso_resource_auto(struct client *client, struct client_resou
        schedule_iso_resource_auto(r, 0);
 }
 
-static int init_iso_resource(struct client *client, struct fw_cdev_allocate_iso_resource *request)
+static int ioctl_allocate_iso_resource(struct client *client, union ioctl_arg *arg)
 {
-       struct iso_resource_event *e1, *e2;
-       struct iso_resource_auto *r;
-       int ret;
+       struct fw_cdev_allocate_iso_resource *request = &arg->allocate_iso_resource;
+       struct iso_resource_event *e1 __free(kfree) = kmalloc_obj(*e1);
+       struct iso_resource_event *e2 __free(kfree) = kmalloc_obj(*e2);
+       struct iso_resource_auto *r  __free(kfree) = kmalloc_obj(*r);
+       int err;
 
-       r = kmalloc_obj(*r);
-       e1 = kmalloc_obj(*e1);
-       e2 = kmalloc_obj(*e2);
-       if (r == NULL || e1 == NULL || e2 == NULL) {
-               ret = -ENOMEM;
-               goto fail;
-       }
+       if (!r || !e1 || !e2)
+               return -ENOMEM;
 
-       ret = fill_iso_resource_params(&r->params, request);
-       if (ret < 0)
-               goto fail;
+       err = fill_iso_resource_params(&r->params, request);
+       if (err < 0)
+               return  err;
 
        INIT_DELAYED_WORK(&r->work, iso_resource_auto_work);
        r->client       = client;
@@ -1449,31 +1446,21 @@ static int init_iso_resource(struct client *client, struct fw_cdev_allocate_iso_
        r->e_dealloc    = e2;
 
        e1->iso_resource.closure = request->closure;
-       e1->iso_resource.type    = FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED;
+       e1->iso_resource.type = FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED;
        e2->iso_resource.closure = request->closure;
-       e2->iso_resource.type    = FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED;
+       e2->iso_resource.type = FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED;
 
        r->resource.release = release_iso_resource_auto;
-       ret = add_client_resource(client, &r->resource, GFP_KERNEL);
-       if (ret < 0)
-               goto fail;
-       schedule_iso_resource_auto(r, 0);
-
+       err = add_client_resource(client, &r->resource, GFP_KERNEL);
+       if (err < 0)
+               return err;
        request->handle = r->resource.handle;
 
-       return 0;
- fail:
-       kfree(r);
-       kfree(e1);
-       kfree(e2);
-
-       return ret;
-}
+       retain_and_null_ptr(e1);
+       retain_and_null_ptr(e2);
+       schedule_iso_resource_auto(no_free_ptr(r), 0);
 
-static int ioctl_allocate_iso_resource(struct client *client,
-                                      union ioctl_arg *arg)
-{
-       return init_iso_resource(client, &arg->allocate_iso_resource);
+       return 0;
 }
 
 static int ioctl_deallocate_iso_resource(struct client *client,