lkml.org 
[lkml]   [2022]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH v2] blk-mq: fix incorrect blk_status_t casts
Fixes sparse warnings:
block/blk-mq.c:1163:36: sparse:
warning: cast from restricted blk_status_t
block/blk-mq.c:1251:17: sparse:
warning: cast to restricted blk_status_t

blk_status_t type is bitwaise and requires __force for any casts.

Signed-off-by: Vasily Averin <vvs@openvz.org>
---
v2: introduced request_blk_status_en/decode helpers
thanks Christoph Hellwig for the hint
---
block/blk-mq.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 84d749511f55..8f067b021af3 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1151,6 +1151,16 @@ void blk_mq_start_request(struct request *rq)
}
EXPORT_SYMBOL(blk_mq_start_request);

+static void *request_blk_status_encode(blk_status_t status)
+{
+ return (void *)(__force uintptr_t)status;
+}
+
+static blk_status_t request_blk_status_decode(void *ptr)
+{
+ return (__force blk_status_t)(uintptr_t)ptr;
+}
+
/**
* blk_end_sync_rq - executes a completion event on a request
* @rq: request to complete
@@ -1160,7 +1170,7 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error)
{
struct completion *waiting = rq->end_io_data;

- rq->end_io_data = (void *)(uintptr_t)error;
+ rq->end_io_data = request_blk_status_encode(error);

/*
* complete last, if this is a stack request the process (and thus
@@ -1228,6 +1238,7 @@ static void blk_rq_poll_completion(struct request *rq, struct completion *wait)
* for execution and wait for completion.
* Return: The blk_status_t result provided to blk_mq_end_request().
*/
+
blk_status_t blk_execute_rq(struct request *rq, bool at_head)
{
DECLARE_COMPLETION_ONSTACK(wait);
@@ -1248,7 +1259,7 @@ blk_status_t blk_execute_rq(struct request *rq, bool at_head)
else
wait_for_completion_io(&wait);

- return (blk_status_t)(uintptr_t)rq->end_io_data;
+ return request_blk_status_decode(rq->end_io_data);
}
EXPORT_SYMBOL(blk_execute_rq);

--
2.31.1
\
 
 \ /
  Last update: 2022-05-18 14:49    [W:0.062 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site