diff mbox series

scsi: Delete unnecessary allocate buffer for every loop when print command

Message ID 20200717090921.29243-2-yebin10@huawei.com (mailing list archive)
State Mainlined
Commit 811f39479c0c2d4da959b8d915f2f699d70ab143
Headers show
Series scsi: Delete unnecessary allocate buffer for every loop when print command | expand

Commit Message

Ye Bin July 17, 2020, 9:09 a.m. UTC
We can allocate buffer once, and reuse it. There is unnecessary allocate
 buffer for every loop.

Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 drivers/scsi/scsi_logging.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Martin K. Petersen July 25, 2020, 2:50 a.m. UTC | #1
On Fri, 17 Jul 2020 17:09:21 +0800, Ye Bin wrote:

> We can allocate buffer once, and reuse it. There is unnecessary allocate
>  buffer for every loop.

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: core: Delete unnecessary buffer allocation for every loop iteration
      https://git.kernel.org/mkp/scsi/c/811f39479c0c
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c
index c91fa3feb930..8ea44c6595ef 100644
--- a/drivers/scsi/scsi_logging.c
+++ b/drivers/scsi/scsi_logging.c
@@ -205,13 +205,9 @@  void scsi_print_command(struct scsi_cmnd *cmd)
 		/* Print opcode in one line and use separate lines for CDB */
 		off += scnprintf(logbuf + off, logbuf_len - off, "\n");
 		dev_printk(KERN_INFO, &cmd->device->sdev_gendev, "%s", logbuf);
-		scsi_log_release_buffer(logbuf);
 		for (k = 0; k < cmd->cmd_len; k += 16) {
 			size_t linelen = min(cmd->cmd_len - k, 16);
 
-			logbuf = scsi_log_reserve_buffer(&logbuf_len);
-			if (!logbuf)
-				break;
 			off = sdev_format_header(logbuf, logbuf_len,
 						 scmd_name(cmd),
 						 cmd->request->tag);
@@ -224,9 +220,8 @@  void scsi_print_command(struct scsi_cmnd *cmd)
 			}
 			dev_printk(KERN_INFO, &cmd->device->sdev_gendev, "%s",
 				   logbuf);
-			scsi_log_release_buffer(logbuf);
 		}
-		return;
+		goto out;
 	}
 	if (!WARN_ON(off > logbuf_len - 49)) {
 		off += scnprintf(logbuf + off, logbuf_len - off, " ");
@@ -236,6 +231,7 @@  void scsi_print_command(struct scsi_cmnd *cmd)
 	}
 out_printk:
 	dev_printk(KERN_INFO, &cmd->device->sdev_gendev, "%s", logbuf);
+out:
 	scsi_log_release_buffer(logbuf);
 }
 EXPORT_SYMBOL(scsi_print_command);