Skip to content

Commit

Permalink
block: Fix off-by-one errors in blk_status_to_errno() and print_req_e…
Browse files Browse the repository at this point in the history
…rror()

This was detected by the smatch static analyzer.

Fixes: commit 2a842ac ("block: introduce new block status code type")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Bart Van Assche authored and Jens Axboe committed Jun 21, 2017
1 parent e0fc443 commit 34bd9c1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ int blk_status_to_errno(blk_status_t status)
{
int idx = (__force int)status;

if (WARN_ON_ONCE(idx > ARRAY_SIZE(blk_errors)))
if (WARN_ON_ONCE(idx >= ARRAY_SIZE(blk_errors)))
return -EIO;
return blk_errors[idx].errno;
}
Expand All @@ -179,7 +179,7 @@ static void print_req_error(struct request *req, blk_status_t status)
{
int idx = (__force int)status;

if (WARN_ON_ONCE(idx > ARRAY_SIZE(blk_errors)))
if (WARN_ON_ONCE(idx >= ARRAY_SIZE(blk_errors)))
return;

printk_ratelimited(KERN_ERR "%s: %s error, dev %s, sector %llu\n",
Expand Down

0 comments on commit 34bd9c1

Please sign in to comment.