mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
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 <o-takashi@sakamocchi.jp>
This commit is contained in:
parent
254f49634e
commit
e05a76ae15
|
|
@ -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) {
|
||||
ret = -ECANCELED;
|
||||
if (client->in_shutdown)
|
||||
return -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user