Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2974030pxb; Mon, 18 Apr 2022 12:22:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqNj23ZEGsy/O/sCqwr/cve2tHIleaS2MgvpefhCZmPJ43RmUfIzcg4tkjZla9yzWorEqW X-Received: by 2002:a63:68c6:0:b0:380:3fbc:dfb6 with SMTP id d189-20020a6368c6000000b003803fbcdfb6mr11459199pgc.326.1650309734550; Mon, 18 Apr 2022 12:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650309734; cv=none; d=google.com; s=arc-20160816; b=RSjyxAEqTsl+R0TtNFwqpBgCbcdki2SeVOUE9irilUQcayHpH/eovqn3vhWHuHRE0y R5fkiAO5fTnW/Xxo2axcDZTuw4V/1YxE5pp/CmuEMdSJOySkFRzKDgTGnvv5u2eeSr0v Rrd7nG3Z9GzlUiu2WcsW+V1lz90ZzBUMf8HBl9uD3DEtjEb16s/0310IGkNKvkxZo/50 WXYZRqqsBmxY5rtbIS0jP8bwtDUxKit3cAKz4VsGJ1OOPA5M611g7RpLkf834lQ10Ln/ cSCrzfy2SbXFvie9vYlTVZ8lfTAiPGY8GhY++80bw406lSrllIiOpt5EAPG7crwfNTsv FWeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e7yFJWsXIrR+6zqlAPg01UCfwiTtmX051yaCwOaqkD8=; b=I5RGnDrw/NrfA4QM4rp8/7zuHPmuEoSS4Cb3voT0sSgDyiQ1gZi1HjdSWU2YiToH1E eY9FT4GvgtUUrgq5O6KnZ0d2FC/xYHR/aQ+ZtQsYrgdW4n11MlMn96vcFLb/1HPzMLId QI7bufIYkkR4YoctzToL5+vcdWALPP+BGgh7WhZSbbH97Shr64Y2ngzJJq7uSMe0rEx0 NhUyU5WL4+lxstWEAirRJf6tUjRCPiRKTFnrw6cIrHWev8rQFxxBrkR1KKsC8pwbKjT/ hgQu4qTnSvhCO7MJEl/3jUAqVujl8AY3gqapwg2vPV48TAaT7k+a0Q5D0D8r3G+PMVQ9 rgRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LYNJXzGG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a170902788a00b00153b2d16561si8987472pll.361.2022.04.18.12.21.57; Mon, 18 Apr 2022 12:22:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LYNJXzGG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243473AbiDRNdw (ORCPT + 99 others); Mon, 18 Apr 2022 09:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241215AbiDRNG7 (ORCPT ); Mon, 18 Apr 2022 09:06:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0FEA2A254; Mon, 18 Apr 2022 05:47:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4D4BE6101A; Mon, 18 Apr 2022 12:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48FEFC385A1; Mon, 18 Apr 2022 12:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286040; bh=bDq4CJx1GKP2PLiTe4/HEQW+6US9MEefoAoHfnXwjMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LYNJXzGGcW0VVR3BzgZ87GUrJrlUDIv56iNYMB+z3S4sP65ZWmsce7pInK1sLtNdO JksW+mT2I334I/OduF1SZvwbUXAK+kd4C+UWiW9iUgoyscvcwa0ohCB7I2RO75Abi8 j/SXBBWTp8D0sGTflukeug0kLBLj5ewINT6p6l74= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xie Yongji , Jens Axboe , Lee Jones Subject: [PATCH 4.14 011/284] block: Add a helper to validate the block size Date: Mon, 18 Apr 2022 14:09:52 +0200 Message-Id: <20220418121211.018253515@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie Yongji commit 570b1cac477643cbf01a45fa5d018430a1fddbce upstream. There are some duplicated codes to validate the block size in block drivers. This limitation actually comes from block layer, so this patch tries to add a new block layer helper for that. Signed-off-by: Xie Yongji Link: https://lore.kernel.org/r/20211026144015.188-2-xieyongji@bytedance.com Signed-off-by: Jens Axboe Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman --- include/linux/blkdev.h | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -56,6 +56,14 @@ struct blk_stat_callback; */ #define BLKCG_MAX_POLS 3 +static inline int blk_validate_block_size(unsigned int bsize) +{ + if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize)) + return -EINVAL; + + return 0; +} + typedef void (rq_end_io_fn)(struct request *, blk_status_t); #define BLK_RL_SYNCFULL (1U << 0)