[PATCH 2/5] block: make blk_rq_map_kern() to accept a NULL buffer
Hannes Reinecke
hare at suse.de
Thu Feb 9 06:38:17 PST 2023
We really should accept a NULL buffer as argument, avoiding conditional
coding in the caller.
Signed-off-by: Hannes Reinecke <hare at suse.de>
---
block/blk-map.c | 2 +-
drivers/block/pktcdvd.c | 10 ++++------
drivers/nvme/host/core.c | 8 +++-----
drivers/scsi/scsi_ioctl.c | 8 +++-----
drivers/scsi/scsi_lib.c | 11 +++++------
5 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/block/blk-map.c b/block/blk-map.c
index 859590be077e..4615386b85d3 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -783,7 +783,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
if (len > (queue_max_hw_sectors(q) << 9))
return -EINVAL;
if (!len || !kbuf)
- return -EINVAL;
+ return 0;
if (!blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) ||
blk_queue_may_bounce(q))
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 2f1a92509271..9e49cca82bfd 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -694,12 +694,10 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
return PTR_ERR(rq);
scmd = blk_mq_rq_to_pdu(rq);
- if (cgc->buflen) {
- ret = blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen,
- GFP_NOIO);
- if (ret)
- goto out;
- }
+ ret = blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen,
+ GFP_NOIO);
+ if (ret)
+ goto out;
scmd->cmd_len = COMMAND_SIZE(cgc->cmd[0]);
memcpy(scmd->cmnd, cgc->cmd, CDROM_PACKET_SIZE);
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ad2bcb412944..78da9c6cbba8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1044,11 +1044,9 @@ int __nvme_submit_sync_cmd(struct request *req, union nvme_result *result,
{
int ret;
- if (buffer && bufflen) {
- ret = blk_rq_map_kern(req->q, req, buffer, bufflen, GFP_KERNEL);
- if (ret)
- goto out;
- }
+ ret = blk_rq_map_kern(req->q, req, buffer, bufflen, GFP_KERNEL);
+ if (ret)
+ goto out;
ret = nvme_execute_rq(req, at_head);
if (result && ret >= 0)
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 1126a265d5ee..1e182d71ce74 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -581,11 +581,9 @@ static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode,
break;
}
- if (bytes) {
- err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
- if (err)
- goto error;
- }
+ err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
+ if (err)
+ goto error;
blk_execute_rq(rq, false);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 9ed1ebcb7443..b15ddf6820a3 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -221,12 +221,11 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
if (IS_ERR(req))
return PTR_ERR(req);
- if (bufflen) {
- ret = blk_rq_map_kern(sdev->request_queue, req,
- buffer, bufflen, GFP_NOIO);
- if (ret)
- goto out;
- }
+ ret = blk_rq_map_kern(sdev->request_queue, req,
+ buffer, bufflen, GFP_NOIO);
+ if (ret)
+ goto out;
+
scmd = blk_mq_rq_to_pdu(req);
scmd->cmd_len = COMMAND_SIZE(cmd[0]);
memcpy(scmd->cmnd, cmd, scmd->cmd_len);
--
2.35.3
More information about the Linux-nvme
mailing list