Handle the errno_to_blk_status(0) case inline so that the compiler can optimize when it knows that errno is not 0. Likewise for blk_status_to_errno(BLK_STATUS_OK).
Signed-off-by: Andreas Gruenbacher <[email protected]> --- block/blk-core.c | 11 ++++++----- include/linux/blkdev.h | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 9b3100d171b7..381bdf66045b 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -133,7 +133,6 @@ inline const char *blk_op_str(enum req_op op) EXPORT_SYMBOL_GPL(blk_op_str); #define blk_errors(_) \ - _(BLK_STS_OK, 0, "") \ _(BLK_STS_NOTSUPP, -EOPNOTSUPP, "operation not supported") \ _(BLK_STS_TIMEOUT, -ETIMEDOUT, "timeout") \ _(BLK_STS_NOSPC, -ENOSPC, "critical space allocation") \ @@ -159,7 +158,7 @@ EXPORT_SYMBOL_GPL(blk_op_str); \ _(BLK_STS_INVAL, -EINVAL, "invalid") -blk_status_t errno_to_blk_status(int errno) +blk_status_t __errno_to_blk_status(int errno) { switch(errno) { #define _(_status, _errno, _name) \ @@ -171,9 +170,9 @@ blk_status_t errno_to_blk_status(int errno) return BLK_STS_IOERR; } } -EXPORT_SYMBOL_GPL(errno_to_blk_status); +EXPORT_SYMBOL_GPL(__errno_to_blk_status); -int blk_status_to_errno(blk_status_t status) +int __blk_status_to_errno(blk_status_t status) { switch(status) { #define _(_status, _errno, _name) \ @@ -185,11 +184,13 @@ int blk_status_to_errno(blk_status_t status) return -EIO; } } -EXPORT_SYMBOL_GPL(blk_status_to_errno); +EXPORT_SYMBOL_GPL(__blk_status_to_errno); const char *blk_status_to_str(blk_status_t status) { switch(status) { + case BLK_STS_OK: + return ""; #define _(_status, _errno, _name) \ case _status: \ return _name; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 70b671a9a7f7..a2451fbd53a8 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1011,8 +1011,22 @@ extern void blk_sync_queue(struct request_queue *q); /* Helper to convert REQ_OP_XXX to its string format XXX */ extern const char *blk_op_str(enum req_op op); -int blk_status_to_errno(blk_status_t status); -blk_status_t errno_to_blk_status(int errno); +int __blk_status_to_errno(blk_status_t status); +static inline int blk_status_to_errno(blk_status_t status) +{ + if (status == BLK_STS_OK) + return 0; + return __blk_status_to_errno(status); +} + +blk_status_t __errno_to_blk_status(int errno); +static inline blk_status_t errno_to_blk_status(int errno) +{ + if (errno == 0) + return BLK_STS_OK; + return __errno_to_blk_status(errno); +} + const char *blk_status_to_str(blk_status_t status); /* only poll the hardware once, don't continue until a completion was found */ -- 2.52.0
