Skip to content

Commit c06a8b7

Browse files
author
Kent Overstreet
committed
bcachefs: Fix bch2_alloc_ciphers()
Don't put error pointers in bch_fs, that's gross. This fixes (?) the check in bch2_checksum_type_valid() - depending on our error paths, or depending on what our error paths are doing it at least makes the code saner. Reported-by: [email protected] Signed-off-by: Kent Overstreet <[email protected]>
1 parent 6d48e61 commit c06a8b7

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

fs/bcachefs/checksum.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,26 +648,26 @@ int bch2_decrypt_sb_key(struct bch_fs *c,
648648

649649
static int bch2_alloc_ciphers(struct bch_fs *c)
650650
{
651-
int ret;
652-
653-
if (!c->chacha20)
654-
c->chacha20 = crypto_alloc_sync_skcipher("chacha20", 0, 0);
655-
ret = PTR_ERR_OR_ZERO(c->chacha20);
651+
if (c->chacha20)
652+
return 0;
656653

654+
struct crypto_sync_skcipher *chacha20 = crypto_alloc_sync_skcipher("chacha20", 0, 0);
655+
int ret = PTR_ERR_OR_ZERO(chacha20);
657656
if (ret) {
658657
bch_err(c, "error requesting chacha20 module: %s", bch2_err_str(ret));
659658
return ret;
660659
}
661660

662-
if (!c->poly1305)
663-
c->poly1305 = crypto_alloc_shash("poly1305", 0, 0);
664-
ret = PTR_ERR_OR_ZERO(c->poly1305);
665-
661+
struct crypto_shash *poly1305 = crypto_alloc_shash("poly1305", 0, 0);
662+
ret = PTR_ERR_OR_ZERO(poly1305);
666663
if (ret) {
667664
bch_err(c, "error requesting poly1305 module: %s", bch2_err_str(ret));
665+
crypto_free_sync_skcipher(chacha20);
668666
return ret;
669667
}
670668

669+
c->chacha20 = chacha20;
670+
c->poly1305 = poly1305;
671671
return 0;
672672
}
673673

@@ -762,11 +762,11 @@ int bch2_enable_encryption(struct bch_fs *c, bool keyed)
762762

763763
void bch2_fs_encryption_exit(struct bch_fs *c)
764764
{
765-
if (!IS_ERR_OR_NULL(c->poly1305))
765+
if (c->poly1305)
766766
crypto_free_shash(c->poly1305);
767-
if (!IS_ERR_OR_NULL(c->chacha20))
767+
if (c->chacha20)
768768
crypto_free_sync_skcipher(c->chacha20);
769-
if (!IS_ERR_OR_NULL(c->sha256))
769+
if (c->sha256)
770770
crypto_free_shash(c->sha256);
771771
}
772772

@@ -779,6 +779,7 @@ int bch2_fs_encryption_init(struct bch_fs *c)
779779
c->sha256 = crypto_alloc_shash("sha256", 0, 0);
780780
ret = PTR_ERR_OR_ZERO(c->sha256);
781781
if (ret) {
782+
c->sha256 = NULL;
782783
bch_err(c, "error requesting sha256 module: %s", bch2_err_str(ret));
783784
goto out;
784785
}

0 commit comments

Comments
 (0)