Skip to contentSkip to conversation

scsi: core: Fix "scsi: core: add scsi_host_(block,unblock) helper function"

PATCH New Ye Bin 2 participants 3 messages Jul 17, 2020 – Jul 25, 2020 SCSI

lore
Share & tools
lore
author
#1 lore raw

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

In reply to Ye Bin

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

---
 drivers/scsi/scsi_logging.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/scsi/scsi_logging.c +2 -6
index c91fa3feb930..8ea44c6595ef 100644
@@ -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);
Signature · 1 line
2.25.4

Ye Bin

author
#0 lore raw

PATCH 1/1 scsi: core: Fix "scsi: core: add scsi_host_(block,unblock) helper function"

In commit 4dea170f4fb2 ("scsi: core: Fix incorrect usage of shost_for_each_device") fix usage of shost_for_each_device in function scsi_host_block.

Fix: 2bb955840c1d("scsi: core: add scsi_host_(block,unblock) helper function")

---
 drivers/scsi/scsi_lib.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +3 -1
index f3bf2648105c..65fde27b8b08 100644
@@ -2811,8 +2811,10 @@ scsi_host_block(struct Scsi_Host *shost)
 		mutex_lock(&sdev->state_mutex);
 		ret = scsi_internal_device_block_nowait(sdev);
 		mutex_unlock(&sdev->state_mutex);
-		if (ret)
+		if (ret) {
+			scsi_device_put(sdev);
 			break;
+		}
 	}
 
 	/*
Signature · 1 line
2.25.4
#2 lore raw

Re: [PATCH] scsi: Delete unnecessary allocate buffer for every loop when print command

In reply to Ye Bin
Quoted 2 lines · Ye Bin

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
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering