Re: [PATCH] bcachefs: Simplify code in bch2_dev_alloc()

From: Youling Tang
Date: Sun Oct 13 2024 - 21:26:53 EST


Hi, Kent

On 2024/10/13 01:30, Kent Overstreet wrote:

On Sat, Oct 12, 2024 at 03:59:02PM GMT, Youling Tang wrote:
From: Youling Tang <tangyouling@xxxxxxxxxx>

- Remove unnecessary variable 'ret'.
- Remove unnecessary bch2_dev_free() operations.

Signed-off-by: Youling Tang <tangyouling@xxxxxxxxxx>
the 'goto err' style is more readable when you're staring at tons of
code
Well.

But 'ret' is not needed here.
Does not execute bch2_dev_free() if the ca in the err path is NULL,
so it can be removed.
Can be modified as follows if necessary:
-- a/fs/bcachefs/super.c
+++ b/fs/bcachefs/super.c
@@ -1352,7 +1352,6 @@ static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx)
 {
        struct bch_member member = bch2_sb_member_get(c->disk_sb.sb, dev_idx);
        struct bch_dev *ca = NULL;
-       int ret = 0;

        if (bch2_fs_init_fault("dev_alloc"))
                goto err;
@@ -1364,10 +1363,9 @@ static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx)
        ca->fs = c;

        bch2_dev_attach(c, ca, dev_idx);
-       return ret;
+       return 0;
 err:
-       if (ca)
-               bch2_dev_free(ca);
        return -BCH_ERR_ENOMEM_dev_alloc;

 }

Thanks,
Youling.