From: Kent Overstreet Date: Wed, 28 May 2025 15:27:59 +0000 (-0400) Subject: bcachefs: Mark bch_errcode helpers __attribute__((const)) X-Git-Tag: v6.16-rc1~48^2~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc43f6a70b9685acabfda210f7cbb0520e952510;p=thirdparty%2Flinux.git bcachefs: Mark bch_errcode helpers __attribute__((const)) These don't access global memory or defer pointer arguments - this enables CSE optimizations. Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/errcode.c b/fs/bcachefs/errcode.c index 43557bebd0f85..c39cf304c6810 100644 --- a/fs/bcachefs/errcode.c +++ b/fs/bcachefs/errcode.c @@ -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); diff --git a/fs/bcachefs/errcode.h b/fs/bcachefs/errcode.h index 62843e772b2c6..6b0791e1e64d1 100644 --- a/fs/bcachefs/errcode.h +++ b/fs/bcachefs/errcode.h @@ -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);