Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp619876ybh; Tue, 21 Jul 2020 03:57:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5xzalu+KydDmbuhcZFcp4KTJ5kO0Xuugs3SRg3L2n+IdpQvUqmkNXAnZoKmI7EpV/V1gw X-Received: by 2002:a05:6402:1777:: with SMTP id da23mr24776681edb.260.1595329034929; Tue, 21 Jul 2020 03:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595329034; cv=none; d=google.com; s=arc-20160816; b=x6BzmLI7W/rTgnoMlHtvPfL7VcGyvTCDgLcHrnqpptMyjvm/BqF2JEPIEAnHLXfSsT pYgIVU6Y8SpthnYlPK4eg/ndI1UFFVs0BlifYyna7vjuZW5mldOVeDQsvLosdOXo9jJu /xmVWU9Ij41hMLRJ8qj5IGd5s2oGrI/Wj/p/lt/MY9/Be2neoenB/sGZeNk+Zz/yZ66U OTWY+atafWnUMQM5kyk6GSl3+0Tna44D8l97aZ0BGhLXtwdr9ukGwX+XeBa+6IyUAua7 qqLWS47Fr1Z7ZPUzHx3N3SVYpTkf+05ABpLYr+CoRFS5t7Wm94VroHuibzT7W1AA2Cuo rbLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+3seadylwcW1rKfz25C5YjNc+LNMmMOgRxWnx3VfrYM=; b=Nhke0E8Q297HkIQ5a3cQZj0X9GLk+nY/9cxYkfairoxmgKoPsYxB56MMDrYgXG/wU4 vxBG3iGdI+FevYHLAHQZzQ0Q2Z+pxXoHkAgw5m5vcKdEk4YvGCjaKQ0GC0qDtn4E8wi8 ohQet6J8noMO1mL5594jPVOvVPyW7yHNxrkXHv7esHFvQdHQUaprYg8iGaDK3KvQfaS5 HiggWyK76ua2E76f+Pcy04pKyOlKhMVcJkPqCbXJcFx9JFR1bRPSD9g/6JCmF1C6Gf9v TyL52BVyVakztdn4W9K3lF1auYEeY0qAfkX31huHO14tE+SF2xoj51OlsmgiEn8vHH5e rctQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bx+EqnfP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si12516938edy.576.2020.07.21.03.56.51; Tue, 21 Jul 2020 03:57:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bx+EqnfP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729487AbgGUKzr (ORCPT + 99 others); Tue, 21 Jul 2020 06:55:47 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24247 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729482AbgGUKzq (ORCPT ); Tue, 21 Jul 2020 06:55:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595328945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+3seadylwcW1rKfz25C5YjNc+LNMmMOgRxWnx3VfrYM=; b=Bx+EqnfPFCBbu0xN3hG3h//8K66M/FNnZzK44GNUzQyBEmZxh+IO63Zinv+cK2Tl/D14nx fLG3mTXGkQ79SPVvDqU3RaquRxGPD/Gg1TY2zaaHgY/Ftq/VA5AapUtE1befrc97eMrwDA qrAgfnSWKbDjjaTWeubld6Q6+yRRyPs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-YSjNVmjPOw2mHuqqn-p2Cw-1; Tue, 21 Jul 2020 06:55:42 -0400 X-MC-Unique: YSjNVmjPOw2mHuqqn-p2Cw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07C091005504; Tue, 21 Jul 2020 10:55:39 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7482876216; Tue, 21 Jul 2020 10:55:26 +0000 (UTC) From: Maxim Levitsky To: linux-kernel@vger.kernel.org Cc: Keith Busch , Josef Bacik , linux-block@vger.kernel.org (open list:BLOCK LAYER), Sagi Grimberg , Jens Axboe , linux-nvme@lists.infradead.org (open list:NVM EXPRESS DRIVER), linux-scsi@vger.kernel.org (open list:SCSI CDROM DRIVER), Tejun Heo , Bart Van Assche , "Martin K. Petersen" , Damien Le Moal , Jason Wang , Maxim Levitsky , Stefan Hajnoczi , Colin Ian King , "Michael S. Tsirkin" , Paolo Bonzini , Ulf Hansson , Ajay Joshi , Ming Lei , linux-mmc@vger.kernel.org (open list:SONY MEMORYSTICK SUBSYSTEM), Christoph Hellwig , Satya Tangirala , nbd@other.debian.org (open list:NETWORK BLOCK DEVICE (NBD)), Hou Tao , Jens Axboe , virtualization@lists.linux-foundation.org (open list:VIRTIO CORE AND NET DRIVERS), "James E.J. Bottomley" , Alex Dubov , Maxim Levitsky Subject: [PATCH 10/10] block: scsi: sr: use blk_is_valid_logical_block_size Date: Tue, 21 Jul 2020 13:52:39 +0300 Message-Id: <20200721105239.8270-11-mlevitsk@redhat.com> In-Reply-To: <20200721105239.8270-1-mlevitsk@redhat.com> References: <20200721105239.8270-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Plus some tiny refactoring. Signed-off-by: Maxim Levitsky --- drivers/scsi/sr.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 0c4aa4665a2f9..0e96338029310 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -866,31 +866,26 @@ static void get_sectorsize(struct scsi_cd *cd) cd->capacity = max_t(long, cd->capacity, last_written); sector_size = get_unaligned_be32(&buffer[4]); - switch (sector_size) { - /* - * HP 4020i CD-Recorder reports 2340 byte sectors - * Philips CD-Writers report 2352 byte sectors - * - * Use 2k sectors for them.. - */ - case 0: - case 2340: - case 2352: + + /* + * HP 4020i CD-Recorder reports 2340 byte sectors + * Philips CD-Writers report 2352 byte sectors + * + * Use 2k sectors for them.. + */ + + if (!sector_size || sector_size == 2340 || sector_size == 2352) sector_size = 2048; - /* fall through */ - case 2048: - cd->capacity *= 4; - /* fall through */ - case 512: - break; - default: + + cd->capacity *= (sector_size >> SECTOR_SHIFT); + + if (!blk_is_valid_logical_block_size(sector_size)) { sr_printk(KERN_INFO, cd, "unsupported sector size %d.", sector_size); cd->capacity = 0; } cd->device->sector_size = sector_size; - /* * Add this so that we have the ability to correctly gauge * what the device is capable of. -- 2.26.2