From patchwork Wed Jan 30 07:07:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10787773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAD4F91E for ; Wed, 30 Jan 2019 07:07:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC1522E0A5 for ; Wed, 30 Jan 2019 07:07:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C03922E0C3; Wed, 30 Jan 2019 07:07:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60B572E0C2 for ; Wed, 30 Jan 2019 07:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725827AbfA3HHh (ORCPT ); Wed, 30 Jan 2019 02:07:37 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:7417 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725819AbfA3HHh (ORCPT ); Wed, 30 Jan 2019 02:07:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1548832057; x=1580368057; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=yDY6Bxg0WQYXWhw2/9yjrnlxh8XWBxe5hK4cI3np5xA=; b=NVniTHUnPz8+VHdb2P8oPDcvR0KOkMwanM3/mvCHVGDOgPAl6hECAdeo lM9qgXBRqlZ36RfcFRXUgwK994ouO6DdR6w2zQquerhcYKwuBx+6uMaOA fG0/4a46jARrq2TNe0/A3k1QINLDAJp89UPkjg+eAXp3AUlvmz3kVvpb1 Y6hl9QfXqzwdgUj1qs58l7ipfcfabHY3JlXkBg25x+wUWv3Sp369xc2nu X+p6qnYdkbOfyc77DS6AOrNVT+KkZfwgVlEHI1WTlFFtQR6hokXbjypDv Kq1h/T2EUqom7yVImOuQ7ZvqFiK+E6EKaWZ5UOi45mWnntS5EuQw0zFm4 w==; X-IronPort-AV: E=Sophos;i="5.56,540,1539619200"; d="scan'208";a="101872651" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Jan 2019 15:07:37 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 29 Jan 2019 22:46:38 -0800 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jan 2019 23:07:36 -0800 From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" Subject: [PATCH] scsi: sd: Improve sd_print_capacity() Date: Wed, 30 Jan 2019 16:07:34 +0900 Message-Id: <20190130070734.17562-1-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/scsi/sd.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 */