From: Takashi Sakamoto Date: Wed, 29 Apr 2026 09:34:42 +0000 (+0900) Subject: firewire: core: code refactoring for early return at client resource allocation X-Git-Tag: v7.2-rc1~81^2~16 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=e05a76ae1507d19d62eb0011592be9efb42e06cd;p=thirdparty%2Flinux.git firewire: core: code refactoring for early return at client resource allocation 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 --- diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index f791db4c8dfff..144625c34be2e 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -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,