diff mbox series

scsi: sd: Improve sd_print_capacity()

Message ID 20190130070734.17562-1-damien.lemoal@wdc.com (mailing list archive)
State Mainlined
Commit d7e6db20944c8fb26073bc3ba9d5328992b82858
Headers show
Series scsi: sd: Improve sd_print_capacity() | expand

Commit Message

Damien Le Moal Jan. 30, 2019, 7:07 a.m. UTC
There is no need to call twice string_get_size() when the capacity
messages are not going to be printed. Reverse the message output
condition to return early and avoid executing string_get_size() when it
is not necessary.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/scsi/sd.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

Comments

Martin K. Petersen Feb. 5, 2019, 3:14 a.m. UTC | #1
Damien,

> There is no need to call twice string_get_size() when the capacity
> messages are not going to be printed. Reverse the message output
> condition to return early and avoid executing string_get_size() when
> it is not necessary.

Applied to 5.1/scsi-queue, thanks!
diff mbox series

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index b2da8a00ec33..49bb32682055 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2549,25 +2549,25 @@  sd_print_capacity(struct scsi_disk *sdkp,
 	int sector_size = sdkp->device->sector_size;
 	char cap_str_2[10], cap_str_10[10];
 
+	if (!sdkp->first_scan && old_capacity == sdkp->capacity)
+		return;
+
 	string_get_size(sdkp->capacity, sector_size,
 			STRING_UNITS_2, cap_str_2, sizeof(cap_str_2));
 	string_get_size(sdkp->capacity, sector_size,
-			STRING_UNITS_10, cap_str_10,
-			sizeof(cap_str_10));
+			STRING_UNITS_10, cap_str_10, sizeof(cap_str_10));
 
-	if (sdkp->first_scan || old_capacity != sdkp->capacity) {
-		sd_printk(KERN_NOTICE, sdkp,
-			  "%llu %d-byte logical blocks: (%s/%s)\n",
-			  (unsigned long long)sdkp->capacity,
-			  sector_size, cap_str_10, cap_str_2);
+	sd_printk(KERN_NOTICE, sdkp,
+		  "%llu %d-byte logical blocks: (%s/%s)\n",
+		  (unsigned long long)sdkp->capacity,
+		  sector_size, cap_str_10, cap_str_2);
 
-		if (sdkp->physical_block_size != sector_size)
-			sd_printk(KERN_NOTICE, sdkp,
-				  "%u-byte physical blocks\n",
-				  sdkp->physical_block_size);
+	if (sdkp->physical_block_size != sector_size)
+		sd_printk(KERN_NOTICE, sdkp,
+			  "%u-byte physical blocks\n",
+			  sdkp->physical_block_size);
 
-		sd_zbc_print_zones(sdkp);
-	}
+	sd_zbc_print_zones(sdkp);
 }
 
 /* called with buffer of length 512 */