bcachefs: Mark bch_errcode helpers __attribute__((const))
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 28 May 2025 15:27:59 +0000 (11:27 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 30 May 2025 15:20:18 +0000 (11:20 -0400)
These don't access global memory or defer pointer arguments - this
enables CSE optimizations.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/errcode.c
fs/bcachefs/errcode.h

index 43557bebd0f8549f5e0bc7c23229687d2f4c102f..c39cf304c68102f35b69a94f280fd18761ca63c0 100644 (file)
@@ -13,12 +13,13 @@ static const char * const bch2_errcode_strs[] = {
        NULL
 };
 
-static unsigned bch2_errcode_parents[] = {
+static const unsigned bch2_errcode_parents[] = {
 #define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = class,
        BCH_ERRCODES()
 #undef x
 };
 
+__attribute__((const))
 const char *bch2_err_str(int err)
 {
        const char *errstr;
@@ -36,6 +37,7 @@ const char *bch2_err_str(int err)
        return errstr ?: "(Invalid error)";
 }
 
+__attribute__((const))
 bool __bch2_err_matches(int err, int class)
 {
        err     = abs(err);
index 62843e772b2c63774d241ec6224e27844045fddb..6b0791e1e64d14fd25ce65e0050cdfb9c094d4c3 100644 (file)
@@ -357,9 +357,11 @@ enum bch_errcode {
        BCH_ERR_MAX
 };
 
-const char *bch2_err_str(int);
-bool __bch2_err_matches(int, int);
+__attribute__((const)) const char *bch2_err_str(int);
 
+__attribute__((const)) bool __bch2_err_matches(int, int);
+
+__attribute__((const))
 static inline bool _bch2_err_matches(int err, int class)
 {
        return err < 0 && __bch2_err_matches(err, class);