block/blk-mq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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
Signed-off-by: Vasily Averin <vvs@openvz.org>
---
block/blk-mq.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 84d749511f55..1b887f2d4a19 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1160,7 +1160,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 = (void *)(__force uintptr_t)error;
/*
* complete last, if this is a stack request the process (and thus
@@ -1248,7 +1248,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 (__force blk_status_t)(uintptr_t)rq->end_io_data;
}
EXPORT_SYMBOL(blk_execute_rq);
--
2.31.1
No, no, no. Really, stop these patches that just make things worse now. __force casts are a really bad idea. Please just fix this in a way that does not require casting away these attributes as they are there for a reason!
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
Still a whole lot of casts. Take a look at my "cleanup blk_execute_rq*" for how think we can solve this in a much nicer way.
On 5/18/22 05:45, Vasily Averin wrote: > 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; > +} > + why not use blk_sts_encode() and blk_sts_decode() since both the functions neither accept request parameter nor return request in any form ? -ck > /** > * 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(). > */ > + white line ? > 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); >
On Sat, 14 May 2022 13:03:54 +0300, Vasily Averin wrote: > 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 > > > [...] Applied, thanks! [1/1] blk-mq: use force attribute for blk_status_t casts commit: cb9e061e974f8a3a8f2b8c89d93f34ffa7cacafb Best regards, -- Jens Axboe
© 2016 - 2024 Red Hat, Inc.