All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vasily Averin <vvs@openvz.org>
To: Christoph Hellwig <hch@infradead.org>, Jens Axboe <axboe@kernel.dk>
Cc: kernel@openvz.org, linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org
Subject: [PATCH v2] blk-mq: fix incorrect blk_status_t casts
Date: Wed, 18 May 2022 15:45:08 +0300	[thread overview]
Message-ID: <55475ea9-5f6c-fa19-b52d-93fb89209850@openvz.org> (raw)
In-Reply-To: <YoH0/2FBC2YS9kk5@infradead.org>

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


  reply	other threads:[~2022-05-18 12:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-14 10:03 [PATCH] blk-mq: use force attribute for blk_status_t casts Vasily Averin
2022-05-14 21:24 ` Jens Axboe
2022-05-16  6:53 ` Christoph Hellwig
2022-05-18 12:45   ` Vasily Averin [this message]
2022-05-18 20:35     ` [PATCH v2] blk-mq: fix incorrect " Chaitanya Kulkarni
2022-05-19  7:53     ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55475ea9-5f6c-fa19-b52d-93fb89209850@openvz.org \
    --to=vvs@openvz.org \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=kernel@openvz.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.