Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00590C433FE for ; Fri, 19 Nov 2021 17:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB76B611BF for ; Fri, 19 Nov 2021 17:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235559AbhKSRls (ORCPT ); Fri, 19 Nov 2021 12:41:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:42904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236834AbhKSRlc (ORCPT ); Fri, 19 Nov 2021 12:41:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2011161A62; Fri, 19 Nov 2021 17:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637343510; bh=ZqzyGJyCGAz6V9SAWtx+EK8SN4ueM5itf9a0u1eBWAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4m7MmzaXGsLD1PGUnxflsKrDPzlckHu8B/9jRzIeNDSCtJLi+r2Sz0qtqnRcR8Md nN//zVyun3DDXYj2A+aZlohBhbiuhndHSoHF1k2b40brByLWSsiApbLwVtG53jc7H7 JfVbc/nXsuT7UalPmk85Mr1ZudS4xVX/f7hiTrPc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xie Yongji , Jens Axboe , Tadeusz Struk Subject: [PATCH 5.10 02/21] block: Add a helper to validate the block size Date: Fri, 19 Nov 2021 18:37:37 +0100 Message-Id: <20211119171443.973003563@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211119171443.892729043@linuxfoundation.org> References: <20211119171443.892729043@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Tadeusz Struk 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 @@ -59,6 +59,14 @@ struct blk_keyslot_manager; */ #define BLKCG_MAX_POLS 5 +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); /*