From patchwork Tue Oct 10 20:54:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9997729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E4076601AE for ; Tue, 10 Oct 2017 20:54:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6EE528709 for ; Tue, 10 Oct 2017 20:54:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBBE72877E; Tue, 10 Oct 2017 20:54:44 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 5D44728709 for ; Tue, 10 Oct 2017 20:54:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933562AbdJJUyf (ORCPT ); Tue, 10 Oct 2017 16:54:35 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:55567 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933541AbdJJUy3 (ORCPT ); Tue, 10 Oct 2017 16:54:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1507668871; x=1539204871; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=JEAzLUAh5TjKrmJFX7b2silco31E3Rf+yjRsJMOLbzs=; b=bFKPjJ3fIjD+TN69VmyLw6aBqg4CTmMIcaOUDx/85cmkOjUKgg3qFPJZ 3Wv/87c8yhbt3n2ddb0/RGo23pGAu1q+WmLDTr3+F+eoQBR0FE9TQFX5Z LXNsQgZ2SoORR6ALhE4V5xfo6oeDr+jLoaAewClV8h6oPVhvKHMWvxaX0 Mv8j2RvAL1lWLCgeDH64A+7V76E33VW5Xtkzao8AnLmGawgnV52PG6vI9 EYkade/G1hU8elMXF0K/A2yS9cZ5Km/apPXxVeD32MfywejP9CqTeVT25 Ck0pif6dHBt0KdU3nGS9xdWMF6oZACMkzkWZxmaVTa/wfjzQeRrXRDjvq g==; X-IronPort-AV: E=Sophos;i="5.43,359,1503331200"; d="scan'208";a="57098097" Received: from sjappemgw11.hgst.com (HELO sjappemgw12.hgst.com) ([199.255.44.62]) by ob1.hgst.iphmx.com with ESMTP; 11 Oct 2017 04:54:30 +0800 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by sjappemgw12.hgst.com with ESMTP; 10 Oct 2017 13:54:28 -0700 From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: Christoph Hellwig , Bart Van Assche Subject: [PATCH 4/5] scsi: sd_zbc: Use well defined macros Date: Wed, 11 Oct 2017 05:54:24 +0900 Message-Id: <20171010205425.7376-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010205425.7376-1-damien.lemoal@wdc.com> References: <20171010205425.7376-1-damien.lemoal@wdc.com> 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 instead of open coding, use the min() macro to calculate a report zones reply buffer length in sd_zbc_check_zone_size() and the round_up() macro for calculating the number of zones in sd_zbc_setup(). No functional change is introduced by this patch. Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Bart Van Assche Reviewed-by: Christoph Hellwig --- drivers/scsi/sd_zbc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 7dbaf920679e..bbad851c1789 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -475,7 +475,7 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf) return 0; } -#define SD_ZBC_BUF_SIZE 131072 +#define SD_ZBC_BUF_SIZE 131072U /** * sd_zbc_check_zone_size - Check the device zone sizes @@ -526,10 +526,7 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp) /* Parse REPORT ZONES header */ list_length = get_unaligned_be32(&buf[0]) + 64; rec = buf + 64; - if (list_length < SD_ZBC_BUF_SIZE) - buf_len = list_length; - else - buf_len = SD_ZBC_BUF_SIZE; + buf_len = min(list_length, SD_ZBC_BUF_SIZE); /* Parse zone descriptors */ while (rec < buf + buf_len) { @@ -599,9 +596,8 @@ static int sd_zbc_setup(struct scsi_disk *sdkp) /* chunk_sectors indicates the zone size */ blk_queue_chunk_sectors(sdkp->disk->queue, logical_to_sectors(sdkp->device, sdkp->zone_blocks)); - sdkp->nr_zones = sdkp->capacity >> sdkp->zone_shift; - if (sdkp->capacity & (sdkp->zone_blocks - 1)) - sdkp->nr_zones++; + sdkp->nr_zones = + round_up(sdkp->capacity, sdkp->zone_blocks) >> sdkp->zone_shift; if (!sdkp->zones_wlock) { sdkp->zones_wlock = kcalloc(BITS_TO_LONGS(sdkp->nr_zones),