bcachefs: Fix bch2_acl_chmod() cleanup on error
authorDan Robertson <dan@dlrobertson.com>
Thu, 24 Jun 2021 01:52:41 +0000 (21:52 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:07 +0000 (17:09 -0400)
Avoid calling kfree on the returned error pointer if
bch2_acl_from_disk fails.

Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/acl.c

index be31d27443bcb5c44234517a35360dacea0b0d3a..1642518d32332cafc0209c55ff6827aaed15fe55 100644 (file)
@@ -372,7 +372,7 @@ int bch2_acl_chmod(struct btree_trans *trans,
        acl = bch2_acl_from_disk(xattr_val(xattr.v),
                        le16_to_cpu(xattr.v->x_val_len));
        ret = PTR_ERR_OR_ZERO(acl);
-       if (ret || !acl)
+       if (IS_ERR_OR_NULL(acl))
                goto err;
 
        ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
@@ -391,7 +391,8 @@ int bch2_acl_chmod(struct btree_trans *trans,
        acl = NULL;
 err:
        bch2_trans_iter_put(trans, iter);
-       kfree(acl);
+       if (!IS_ERR_OR_NULL(acl))
+               kfree(acl);
        return ret;
 }