[PATCH V2 3/5] nvmet: ignore discard return value

Chaitanya Kulkarni
2025-11-24T02:57:47Z

__blkdev_issue_discard() always returns 0, making the error checking
in nvmet_bdev_discard_range() dead code.

Kill the function nvmet_bdev_discard_range() and call
__blkdev_issue_discard() directly from nvmet_bdev_execute_discard(),
since no error handling is needed anymore for __blkdev_issue_discard()
call.

Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
drivers/nvme/target/io-cmd-bdev.c | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 8d246b8ca604..97d868d6e01a 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -362,29 +362,14 @@ u16 nvmet_bdev_flush(struct nvmet_req *req)
return 0;
}

-static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
- struct nvme_dsm_range *range, struct bio **bio)
-{
- struct nvmet_ns *ns = req->ns;
- int ret;
-
- ret = __blkdev_issue_discard(ns->bdev,
- nvmet_lba_to_sect(ns, range->slba),
- le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
- GFP_KERNEL, bio);
- if (ret && ret != -EOPNOTSUPP) {
- req->error_slba = le64_to_cpu(range->slba);
- return errno_to_nvme_status(req, ret);
- }
- return NVME_SC_SUCCESS;
-}
-
static void nvmet_bdev_execute_discard(struct nvmet_req *req)
{
+ struct nvmet_ns *ns = req->ns;
struct nvme_dsm_range range;
struct bio *bio = NULL;
+ sector_t nr_sects;
int i;
- u16 status;
+ u16 status = NVME_SC_SUCCESS;

for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) {
status = nvmet_copy_from_sgl(req, i * sizeof(range), &range,
@@ -392,9 +377,11 @@ static void nvmet_bdev_execute_discard(struct nvmet_req *req)
if (status)
break;

- status = nvmet_bdev_discard_range(req, &range, &bio);
- if (status)
- break;
+ nr_sects = le32_to_cpu(range.nlb) << (ns->blksize_shift - 9);
+ __blkdev_issue_discard(ns->bdev,
+ nvmet_lba_to_sect(ns, range.slba),
+ nr_sects,
+ GFP_KERNEL, &bio);
}

if (bio) {
--
2.40.0