bcachefs: Use proper errcodes for inode unpack errors
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 9 Dec 2024 02:42:49 +0000 (21:42 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:23 +0000 (01:36 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/errcode.h
fs/bcachefs/inode.c
fs/bcachefs/varint.c

index a6a9561a890d2dbd559893f9309a56db7dc52b18..5d17ceb1e83a6830f8976911ddd2a9e7c3e6bd43 100644 (file)
        x(EINVAL,                       remove_with_metadata_missing_unimplemented)\
        x(EINVAL,                       remove_would_lose_data)                 \
        x(EINVAL,                       no_resize_with_buckets_nouse)           \
+       x(EINVAL,                       inode_unpack_error)                     \
+       x(EINVAL,                       varint_decode_error)                    \
        x(EROFS,                        erofs_trans_commit)                     \
        x(EROFS,                        erofs_no_writes)                        \
        x(EROFS,                        erofs_journal_err)                      \
@@ -313,6 +315,7 @@ static inline long bch2_err_class(long err)
 
 #define BLK_STS_REMOVED                ((__force blk_status_t)128)
 
+#include <linux/blk_types.h>
 const char *bch2_blk_status_to_str(blk_status_t);
 
 #endif /* _BCACHFES_ERRCODE_H */
index 8818e41883f2c0293c8323b384323ebe30e43325..f6245b78eb7840e7744d18cc082ed375eea09c50 100644 (file)
@@ -48,10 +48,10 @@ static int inode_decode_field(const u8 *in, const u8 *end,
        u8 *p;
 
        if (in >= end)
-               return -1;
+               return -BCH_ERR_inode_unpack_error;
 
        if (!*in)
-               return -1;
+               return -BCH_ERR_inode_unpack_error;
 
        /*
         * position of highest set bit indicates number of bytes:
@@ -61,7 +61,7 @@ static int inode_decode_field(const u8 *in, const u8 *end,
        bytes   = byte_table[shift - 1];
 
        if (in + bytes > end)
-               return -1;
+               return -BCH_ERR_inode_unpack_error;
 
        p = (u8 *) be + 16 - bytes;
        memcpy(p, in, bytes);
@@ -177,7 +177,7 @@ static noinline int bch2_inode_unpack_v1(struct bkey_s_c_inode inode,
                return ret;                                             \
                                                                        \
        if (field_bits > sizeof(unpacked->_name) * 8)                   \
-               return -1;                                              \
+               return -BCH_ERR_inode_unpack_error;                     \
                                                                        \
        unpacked->_name = field[1];                                     \
        in += ret;
@@ -218,7 +218,7 @@ static int bch2_inode_unpack_v2(struct bch_inode_unpacked *unpacked,
                                                                        \
        unpacked->_name = v[0];                                         \
        if (v[1] || v[0] != unpacked->_name)                            \
-               return -1;                                              \
+               return -BCH_ERR_inode_unpack_error;                     \
        fieldnr++;
 
        BCH_INODE_FIELDS_v2()
@@ -269,7 +269,7 @@ static int bch2_inode_unpack_v3(struct bkey_s_c k,
                                                                        \
        unpacked->_name = v[0];                                         \
        if (v[1] || v[0] != unpacked->_name)                            \
-               return -1;                                              \
+               return -BCH_ERR_inode_unpack_error;                     \
        fieldnr++;
 
        BCH_INODE_FIELDS_v3()
index 6a78553d9b0cde0f02377a6de138b4353964fd52..6620ecae26af3af4c53a74c3887e1d7359a00c16 100644 (file)
@@ -9,6 +9,7 @@
 #include <valgrind/memcheck.h>
 #endif
 
+#include "errcode.h"
 #include "varint.h"
 
 /**
@@ -53,7 +54,7 @@ int bch2_varint_decode(const u8 *in, const u8 *end, u64 *out)
        u64 v;
 
        if (unlikely(in + bytes > end))
-               return -1;
+               return -BCH_ERR_varint_decode_error;
 
        if (likely(bytes < 9)) {
                __le64 v_le = 0;
@@ -115,7 +116,7 @@ int bch2_varint_decode_fast(const u8 *in, const u8 *end, u64 *out)
        unsigned bytes = ffz(*in) + 1;
 
        if (unlikely(in + bytes > end))
-               return -1;
+               return -BCH_ERR_varint_decode_error;
 
        if (likely(bytes < 9)) {
                v >>= bytes;