* [PATCH] ublk: fix 'warn: variable dereferenced before check 'req'' from Smatch
@ 2023-08-11 13:52 Ming Lei
2023-08-11 14:13 ` Jens Axboe
2023-08-11 14:44 ` Dan Carpenter
0 siblings, 2 replies; 3+ messages in thread
From: Ming Lei @ 2023-08-11 13:52 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Ming Lei, Andreas Hindborg, Dan Carpenter
The added check of 'req_op(req) == REQ_OP_ZONE_APPEND' should have been
done after the request is confirmed as valid.
Actually here, the request should always been true, so add one
WARN_ON_ONCE(!req), meantime move the zone_append check after
checking the request.
Cc: Andreas Hindborg <a.hindborg@samsung.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Fixes: 29802d7ca33b ("ublk: enable zoned storage support")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
drivers/block/ublk_drv.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 3650ef209344..be76db54db1f 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1400,11 +1400,13 @@ static void ublk_commit_completion(struct ublk_device *ub,
/* find the io request and complete */
req = blk_mq_tag_to_rq(ub->tag_set.tags[qid], tag);
+ if (WARN_ON_ONCE(unlikely(!req)))
+ return;
if (req_op(req) == REQ_OP_ZONE_APPEND)
req->__sector = ub_cmd->zone_append_lba;
- if (req && likely(!blk_should_fake_timeout(req->q)))
+ if (likely(!blk_should_fake_timeout(req->q)))
ublk_put_req_ref(ubq, req);
}
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ublk: fix 'warn: variable dereferenced before check 'req'' from Smatch
2023-08-11 13:52 [PATCH] ublk: fix 'warn: variable dereferenced before check 'req'' from Smatch Ming Lei
@ 2023-08-11 14:13 ` Jens Axboe
2023-08-11 14:44 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2023-08-11 14:13 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-block, Andreas Hindborg, Dan Carpenter
On Fri, 11 Aug 2023 21:52:16 +0800, Ming Lei wrote:
> The added check of 'req_op(req) == REQ_OP_ZONE_APPEND' should have been
> done after the request is confirmed as valid.
>
> Actually here, the request should always been true, so add one
> WARN_ON_ONCE(!req), meantime move the zone_append check after
> checking the request.
>
> [...]
Applied, thanks!
[1/1] ublk: fix 'warn: variable dereferenced before check 'req'' from Smatch
commit: e24721e441a7c640e4e7b2b63c23c06d9a750880
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ublk: fix 'warn: variable dereferenced before check 'req'' from Smatch
2023-08-11 13:52 [PATCH] ublk: fix 'warn: variable dereferenced before check 'req'' from Smatch Ming Lei
2023-08-11 14:13 ` Jens Axboe
@ 2023-08-11 14:44 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2023-08-11 14:44 UTC (permalink / raw)
To: Ming Lei; +Cc: Jens Axboe, linux-block, Andreas Hindborg
On Fri, Aug 11, 2023 at 09:52:16PM +0800, Ming Lei wrote:
> The added check of 'req_op(req) == REQ_OP_ZONE_APPEND' should have been
> done after the request is confirmed as valid.
>
> Actually here, the request should always been true, so add one
> WARN_ON_ONCE(!req), meantime move the zone_append check after
> checking the request.
>
> Cc: Andreas Hindborg <a.hindborg@samsung.com>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Fixes: 29802d7ca33b ("ublk: enable zoned storage support")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> drivers/block/ublk_drv.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3650ef209344..be76db54db1f 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -1400,11 +1400,13 @@ static void ublk_commit_completion(struct ublk_device *ub,
>
> /* find the io request and complete */
> req = blk_mq_tag_to_rq(ub->tag_set.tags[qid], tag);
> + if (WARN_ON_ONCE(unlikely(!req)))
WARN_ON_ONCE() already has an unlikely() built in.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-11 14:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-11 13:52 [PATCH] ublk: fix 'warn: variable dereferenced before check 'req'' from Smatch Ming Lei
2023-08-11 14:13 ` Jens Axboe
2023-08-11 14:44 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox