Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp59849lfe; Fri, 15 Apr 2022 19:28:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTgtTfeD+J0TXAh+NnAgITGqUAF7OTSmDCGlWFpmgIbnCH5Jq5O5uP7x29thjL4bLple+3 X-Received: by 2002:a17:903:1cc:b0:158:5db4:9073 with SMTP id e12-20020a17090301cc00b001585db49073mr1556735plh.154.1650076115384; Fri, 15 Apr 2022 19:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076115; cv=none; d=google.com; s=arc-20160816; b=Zq3aIbyD3uG2Rj2oN3XuGWhRgL3+DK6fpi28Kdim+Ix8kB4hovupAQ9J/oAv6WkjRH LTqQt+DoZ9+HCZ5p3GsbGlM9bCI8NgFK7vHigqq9s9MRWsFATTs8WTM4bEZzwbRh6TVs WTLr58Y3cqATFN+0JFRTEu/LvcsjvnKQpf2Satst7vymdnTgEFKyjtPHjDqbMAJCZtDt YyqZ7Bi9sYOquHgdwd9risMKWxfK/D41YNwsTzO0wuXLPi+NuZvbdfEvnon8I+6vwaFu wLf5zIlrYAm//elxE16Pjull4k8TmRAM59WkIAdBfD8IRYKiMffi3Vsbk7w18Y7nC7cO 8CDg== 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=F1/ak3cPJAhqZSFaEd/39mlknZv79WLRKv1MSk9Ido4=; b=FKnNXeDRqZz1k47znfWooyhUdqOD7cE/WS/GfH+QwVUssJ7LE6Qu1yluFWCzxh7Yxq CS6LdUZy2PZV8SWfJ7nDWkeWkFrJCNxuw5wD+cwUGYujyDtukXwwWAZi97npu6yHEBxS w+kDR7c71XTUkZsOQhcXqIfiy2joqnAbydIH20ZvS/FkBYSLCpQrUaUGt5aCthqTKVcE a4pG6R3NQSxh8mZQGgJmHTHlndh7lJRylHMcrMPG2jabuo85V6PwE7i0dEycSvHTyu2t WFkck80ZoQPmSH/buQvclMca0Lcji0QLDPGEm/bpx8z+5scBDb/vm3XYNonAGeOcj7Kx JX4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HR42KTW9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h14-20020a170902f70e00b00153b2d16513si2627155plo.283.2022.04.15.19.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:28:35 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HR42KTW9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B044B16219D; Fri, 15 Apr 2022 18:40:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbiDNNRz (ORCPT + 99 others); Thu, 14 Apr 2022 09:17:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243758AbiDNNRY (ORCPT ); Thu, 14 Apr 2022 09:17:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B9B58F98A; Thu, 14 Apr 2022 06:14:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id CF75BB8296A; Thu, 14 Apr 2022 13:14:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 246E8C385A5; Thu, 14 Apr 2022 13:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649942096; bh=jMe3cv4kv99rOLCXIlW8C4+xmynCfB84cP/ysUHi+Nw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HR42KTW9XsAAuuBHpEsK0OuYLKzhSp/VW4G9xSOPWLXQRoFC/0RocsLNg19m+KTQ8 CCAeFMO8jq1AqUvOu3CzfmNaX7nJYJgQVOYcVUZO19MIVKGlpkrGmuiPDut5X1ta+t G28sf2T/eJ8Zx48RdbkDyXDc8cpOPMaTPaaMbu+A= 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.19 014/338] block: Add a helper to validate the block size Date: Thu, 14 Apr 2022 15:08:37 +0200 Message-Id: <20220414110839.298193727@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110838.883074566@linuxfoundation.org> References: <20220414110838.883074566@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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); #define BLK_RL_SYNCFULL (1U << 0)