Skip to content

Commit e05a76a

Browse files
committed
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>
1 parent 254f496 commit e05a76a

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

drivers/firewire/core-cdev.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -507,31 +507,30 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
507507
static int add_client_resource(struct client *client, struct client_resource *resource,
508508
gfp_t gfp_mask)
509509
{
510-
int ret;
511-
512510
scoped_guard(spinlock_irqsave, &client->lock) {
513511
u32 index;
512+
int ret;
513+
514+
if (client->in_shutdown)
515+
return -ECANCELED;
514516

515-
if (client->in_shutdown) {
516-
ret = -ECANCELED;
517+
if (gfpflags_allow_blocking(gfp_mask)) {
518+
ret = xa_alloc(&client->resource_xa, &index, resource, xa_limit_32b,
519+
GFP_NOWAIT);
517520
} else {
518-
if (gfpflags_allow_blocking(gfp_mask)) {
519-
ret = xa_alloc(&client->resource_xa, &index, resource, xa_limit_32b,
520-
GFP_NOWAIT);
521-
} else {
522-
ret = xa_alloc_bh(&client->resource_xa, &index, resource,
523-
xa_limit_32b, GFP_NOWAIT);
524-
}
525-
}
526-
if (ret >= 0) {
527-
resource->handle = index;
528-
client_get(client);
529-
if (is_iso_resource(resource))
530-
schedule_iso_resource(to_iso_resource(resource), 0);
521+
ret = xa_alloc_bh(&client->resource_xa, &index, resource,
522+
xa_limit_32b, GFP_NOWAIT);
531523
}
524+
if (ret < 0)
525+
return ret;
526+
527+
resource->handle = index;
528+
client_get(client);
529+
if (is_iso_resource(resource))
530+
schedule_iso_resource(to_iso_resource(resource), 0);
532531
}
533532

534-
return ret < 0 ? ret : 0;
533+
return 0;
535534
}
536535

537536
static int release_client_resource(struct client *client, u32 handle,

0 commit comments

Comments
 (0)