From patchwork Fri Oct 12 10:08:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10638313 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 691B413AD for ; Fri, 12 Oct 2018 10:08:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 566C02B841 for ; Fri, 12 Oct 2018 10:08:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A8472B846; Fri, 12 Oct 2018 10:08:58 +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 E35FE2B841 for ; Fri, 12 Oct 2018 10:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728361AbeJLRkg (ORCPT ); Fri, 12 Oct 2018 13:40:36 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:63720 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728346AbeJLRkg (ORCPT ); Fri, 12 Oct 2018 13:40:36 -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=1539338937; x=1570874937; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=sYtyFxZcEIfg3VQpWOdVzEFJNZ5/2WQ08/2D7cGXupE=; b=NcM1qbhOp64f6DWvVqrTQ0jycO8qKlBipIKs+A47lInu4pj37/gOLbQt 3t8ZnAfu+3OoOryAbJ29jKBvLgovWcmd7PRK1+XOoopZNOzygviejikXq G2B85Vyxuk0kazwUM5MejjB3sseyB54bC7bcrjvL5qJ4SXlxdmgQmcGZZ 9H+WA1Wa5OPHn2wFf6rVFm7uPgns1hB5j64V8SP76vlXYJAqlLwou28pK 8AhbqpZEKEQlHoAzI6k6O1DrUI1IhE7iG70qoq4uIw8Vs5/LP0nAVeBVP k55ULM+z6XP+kcg7/cv5MqEIyvNS+6wh5j7zeE1q7DqIW6qgOsSnDwSuS Q==; X-IronPort-AV: E=Sophos;i="5.54,371,1534780800"; d="scan'208";a="96419675" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 18:08:57 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 12 Oct 2018 02:54:16 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Oct 2018 03:08:56 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Christoph Hellwig , Matias Bjorling Subject: [PATCH v4 03/11] scsi: sd_zbc: Fix sd_zbc_check_zones() error checks Date: Fri, 12 Oct 2018 19:08:42 +0900 Message-Id: <20181012100850.23316-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012100850.23316-1-damien.lemoal@wdc.com> References: <20181012100850.23316-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 The unsigned 32 bits overflow check for the zone size value is already done within sd_zbc_check_zones() with the test: } else if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) { so there is no need to check again for an out of range value in sd_zbc_read_zones(). Simplify the code and fix sd_zbc_check_zones() error return to -EFBIG instead of -ENODEV if the zone size is too large. Change the return type of sd_zbc_check_zones() to an int for the error code and return the zone size (zone_blocks) through a u32 pointer to avoid overflowing the signed 32 return value. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Acked-by: Martin K. Petersen Reviewed-by: Christoph Hellwig --- drivers/scsi/sd_zbc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index ca73c46931c0..0678e1e108b0 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -373,7 +373,7 @@ static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp, * Returns the zone size in number of blocks upon success or an error code * upon failure. */ -static s64 sd_zbc_check_zones(struct scsi_disk *sdkp) +static int sd_zbc_check_zones(struct scsi_disk *sdkp, u32 *zblocks) { u64 zone_blocks = 0; sector_t max_lba, block = 0; @@ -381,7 +381,7 @@ static s64 sd_zbc_check_zones(struct scsi_disk *sdkp) unsigned char *rec; unsigned int buf_len; unsigned int list_length; - s64 ret; + int ret; u8 same; /* Get a buffer */ @@ -472,9 +472,10 @@ static s64 sd_zbc_check_zones(struct scsi_disk *sdkp) if (sdkp->first_scan) sd_printk(KERN_NOTICE, sdkp, "Zone size too large\n"); - ret = -ENODEV; + ret = -EFBIG; } else { - ret = zone_blocks; + *zblocks = zone_blocks; + ret = 0; } out_free: @@ -668,7 +669,7 @@ static int sd_zbc_setup(struct scsi_disk *sdkp, u32 zone_blocks) int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) { - int64_t zone_blocks; + u32 zone_blocks; int ret; if (!sd_is_zoned(sdkp)) @@ -687,12 +688,8 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) * Check zone size: only devices with a constant zone size (except * an eventual last runt zone) that is a power of 2 are supported. */ - zone_blocks = sd_zbc_check_zones(sdkp); - ret = -EFBIG; - if (zone_blocks != (u32)zone_blocks) - goto err; - ret = zone_blocks; - if (ret < 0) + ret = sd_zbc_check_zones(sdkp, &zone_blocks); + if (ret != 0) goto err; /* The drive satisfies the kernel restrictions: set it up */