]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
firewire: core: code refactoring for early return at client resource allocation
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 29 Apr 2026 09:34:42 +0000 (18:34 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 29 Apr 2026 11:30:33 +0000 (20:30 +0900)
The add_client_resource() function returns zero at success or negative
value at error. The critical section is already protected by
scoped_guard() macro. In this case, the programming pattern of early
return improves code readability.

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

index f791db4c8dfffc3a93ad97fb32b1737577aa3c83..144625c34be2e703e37b47e9f6ad8d3493b4dde1 100644 (file)
@@ -507,31 +507,30 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
 static int add_client_resource(struct client *client, struct client_resource *resource,
                               gfp_t gfp_mask)
 {
-       int ret;
-
        scoped_guard(spinlock_irqsave, &client->lock) {
                u32 index;
+               int ret;
+
+               if (client->in_shutdown)
+                       return  -ECANCELED;
 
-               if (client->in_shutdown) {
-                       ret = -ECANCELED;
+               if (gfpflags_allow_blocking(gfp_mask)) {
+                       ret = xa_alloc(&client->resource_xa, &index, resource, xa_limit_32b,
+                                      GFP_NOWAIT);
                } else {
-                       if (gfpflags_allow_blocking(gfp_mask)) {
-                               ret = xa_alloc(&client->resource_xa, &index, resource, xa_limit_32b,
-                                              GFP_NOWAIT);
-                       } else {
-                               ret = xa_alloc_bh(&client->resource_xa, &index, resource,
-                                                 xa_limit_32b, GFP_NOWAIT);
-                       }
-               }
-               if (ret >= 0) {
-                       resource->handle = index;
-                       client_get(client);
-                       if (is_iso_resource(resource))
-                               schedule_iso_resource(to_iso_resource(resource), 0);
+                       ret = xa_alloc_bh(&client->resource_xa, &index, resource,
+                                         xa_limit_32b, GFP_NOWAIT);
                }
+               if (ret < 0)
+                       return ret;
+
+               resource->handle = index;
+               client_get(client);
+               if (is_iso_resource(resource))
+                       schedule_iso_resource(to_iso_resource(resource), 0);
        }
 
-       return ret < 0 ? ret : 0;
+       return 0;
 }
 
 static int release_client_resource(struct client *client, u32 handle,