Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp618773ybh; Tue, 21 Jul 2020 03:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrWOBr4qsxY1skyxIq/h+dFDL5adudtIgBDE6Q3HU75cPFl8DCxcMFpI6Gtm6TOMp11sJS X-Received: by 2002:a50:ccc7:: with SMTP id b7mr26519586edj.9.1595328905859; Tue, 21 Jul 2020 03:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595328905; cv=none; d=google.com; s=arc-20160816; b=yFtHjHedIjSE9aZYZScKZ46qAkkcDujSyQG3w+2TYX1Ou1QxZZabCgGgeNToS5tj+Z sncHm6kGTJnzSl6UMhRbEdi6Ag2r7X+bWrCNluBu3ZOmzbG1jlZxu2oi5fBY/OHyxWxS a6JPz8AZdFOCI0WCEbwwsEcHL8v7tnulFwS5T+076uGkriemn5B5FjIUMLDwDGlh5y2S +zG/C7/fWWRnlU+neJ4uMM2Z2kBM/6NvLPv/Ne3bRgljLaMEyto0XULH87smKcreDMsp x1qUsoPO/DbGLPmetdOn8CW68g85e7bNWEB8l1vbjnWdqUpwEw+wm3H07Gc7nTtV9sV/ TlcA== 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=cmSsOYM3N+BuN/CNETLIG8cntCXD0+KnIyiVkfU5Fy8=; b=xTr0h/5/2wf52JG4w1Me4Y/d5GjYiabNvuZpKgbSD4yiJ4AdaEK7nF7/lEN0SrNm0P DVTqBfu5wtQkAZ12kKJo+xwLmaVvC0BnSBL/S9vFsS/Ru2eitKDfws/Rfsod7i/jMzqJ s2cxGdP1nKKknVD8vc1nwkvbeXACYj8me0icK2Y7puHfHnsQqHai9d8PuMo4NlSLQPlI k8fn5l5f74VC1xJinsTHGT5k5jETQJbLDzUeUXXcPZrGRU+xUeT8wG5X0vAipg0we1Pg dECPGXJwqnKQmL0tpQyOGFnlPo4IMBAx1GnleAHyo63QYFuAp7ugnZv9MqyvmLYIyXfa BSTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LBDjojBG; 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 f12si12306308ejw.135.2020.07.21.03.54.42; Tue, 21 Jul 2020 03:55:05 -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=LBDjojBG; 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 S1729407AbgGUKyU (ORCPT + 99 others); Tue, 21 Jul 2020 06:54:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43009 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729389AbgGUKyT (ORCPT ); Tue, 21 Jul 2020 06:54:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595328858; 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=cmSsOYM3N+BuN/CNETLIG8cntCXD0+KnIyiVkfU5Fy8=; b=LBDjojBGJUpxUHU+TZBA0adCebN9ADDFbyUpRCXqliMOBFSR3kcPyAhWI9a1K+Rx7fLIca GkKEJVmTmIcBHAv5wVbbdHezUUSkcal0fSBNyI7+AWuZ5WPXu1scssWLUttd3zuAl157Xs V6Ks6T4gG0l6foTPVIuqULOgqCoY3Lc= 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-442-e_rhm3fDNaaAvpbYUw1vLw-1; Tue, 21 Jul 2020 06:54:14 -0400 X-MC-Unique: e_rhm3fDNaaAvpbYUw1vLw-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 B1F1DE929; Tue, 21 Jul 2020 10:54:11 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF55A7621A; Tue, 21 Jul 2020 10:54:01 +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 03/10] block: loop: use blk_is_valid_logical_block_size Date: Tue, 21 Jul 2020 13:52:32 +0300 Message-Id: <20200721105239.8270-4-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 This allows to remove loop's own check for supported block size Signed-off-by: Maxim Levitsky --- drivers/block/loop.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 475e1a738560d..9984c8f824271 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -228,19 +228,6 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) blk_mq_unfreeze_queue(lo->lo_queue); } -/** - * loop_validate_block_size() - validates the passed in block size - * @bsize: size to validate - */ -static int -loop_validate_block_size(unsigned short bsize) -{ - if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize)) - return -EINVAL; - - return 0; -} - /** * loop_set_size() - sets device size and notifies userspace * @lo: struct loop_device to set the size for @@ -1119,9 +1106,10 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, } if (config->block_size) { - error = loop_validate_block_size(config->block_size); - if (error) + if (!blk_is_valid_logical_block_size(config->block_size)) { + error = -EINVAL; goto out_unlock; + } } error = loop_set_status_from_info(lo, &config->info); @@ -1607,9 +1595,8 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg) if (lo->lo_state != Lo_bound) return -ENXIO; - err = loop_validate_block_size(arg); - if (err) - return err; + if (!blk_is_valid_logical_block_size(arg)) + return -EINVAL; if (lo->lo_queue->limits.logical_block_size == arg) return 0; -- 2.26.2