From patchwork Fri Jun 23 21:14:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 112309 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6045679vqr; Fri, 23 Jun 2023 14:17:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wf8K4yH24gLJRpgr5TSMZpIXv17K1DhjDkIyIM800OGfO8iSKDQrf1YePKe1n43R6OqpV X-Received: by 2002:a17:90a:648a:b0:25e:8ff2:3cde with SMTP id h10-20020a17090a648a00b0025e8ff23cdemr21913142pjj.6.1687555056938; Fri, 23 Jun 2023 14:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687555056; cv=none; d=google.com; s=arc-20160816; b=NxI17MtNU7yp7AO4yQUX+RYVcjYEaaLmOxKckPmmTZVAQ6GUUHNviHmwy6A7IYff+0 J+8xtHMfVHOJZ0Ghp1wQkIW1gSaXpiBKI8iyMSJPlt6om4hVciS6fLD/nFbBFG1ktue6 R3NdTECnP4di8Pc35npS3YSRXk4vHUvwWL5u9pVr6WPZD0BO8GrdX0ZdxhExwGzH1rhA QX86DZL1EPZ++WtPoGxHlos5l6C/rhK9zKf4WltWN47945p1NCAMcY+dsgb4s/rpgADF 4iNWH+GuH4btP+VmR4Zo5ArtFpMR3Ll38dugcxjLc0+FkPx97hK8EnN1phHXSztQ+BE0 KhLw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x3yaNVdlz5Bh0UGifQdHJbRNelT3AqwxtCVAxF/u48k=; fh=0D+SbFijWVFjdZJfrLsJG5Vji/MCOullDsmz1TAcCEI=; b=aCsRxfS3da/vWZuKxAuf62vM7nOd5yhc9LOUdlYV9I5Xke9CSsVvVlCxqE6WVfB5w5 8Fn8kW1G1JU9ur5M/8bUElZhcoU/XvgTdRhQBdRDTbXmLyz+17DYqoc+f15TR2LDg+u/ RbrD8uivFOfHV+Bqct66/iSuWbrg7Qrrj8/rbrq7CPHDLxfURVRv1FU+Ili2UPYK0fS2 UNN5bha/UBNzv+tRF8ST1WCEyeSPhwGUhXt9EOOhDTfi+phZrp4JZb70v1kAakwyDc8B OzgykyVBqrEUL1h4l80MWHKISjmOYeP/CpBwGfd3pu1VT/9//cGx283drOQ4/nxvJ2HO 67yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=sNuULnbO; 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=inria.fr Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k191-20020a6384c8000000b0055336060f9csi241075pgd.376.2023.06.23.14.17.24; Fri, 23 Jun 2023 14:17:36 -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=@inria.fr header.s=dc header.b=sNuULnbO; 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=inria.fr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232229AbjFWVPs (ORCPT + 99 others); Fri, 23 Jun 2023 17:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232606AbjFWVPT (ORCPT ); Fri, 23 Jun 2023 17:15:19 -0400 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F38DC189; Fri, 23 Jun 2023 14:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x3yaNVdlz5Bh0UGifQdHJbRNelT3AqwxtCVAxF/u48k=; b=sNuULnbON7T/smAo1vy+hUeK7qzpB4L0U0WEzRGcLRjj35A0uv04T47r HhaE8Acqn6AyPeJcGYBY//20g98EBYjzxgvucmJdaMVYNEBf++OQ6gIGw sFqzU/KewLXJwN6gKkHVTf9uMYUZ0FSGbX1pUYVobDoMR7mMYrrbSVaKA 8=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Julia.Lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.01,153,1684792800"; d="scan'208";a="59686170" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2023 23:15:12 +0200 From: Julia Lawall To: Chris Mason Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/26] btrfs: zoned: use array_size Date: Fri, 23 Jun 2023 23:14:43 +0200 Message-Id: <20230623211457.102544-13-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230623211457.102544-1-Julia.Lawall@inria.fr> References: <20230623211457.102544-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769529731257639785?= X-GMAIL-MSGID: =?utf-8?q?1769529731257639785?= Use array_size to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @@ size_t e1,e2; expression COUNT; identifier alloc = {vmalloc,vzalloc,kvmalloc,kvzalloc}; @@ ( alloc( - (e1) * (e2) + array_size(e1, e2) ,...) | alloc( - (e1) * (COUNT) + array_size(COUNT, e1) ,...) ) // Signed-off-by: Julia Lawall Reviewed-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- fs/btrfs/zoned.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 39828af4a4e8..0550ce98dcae 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -464,8 +464,9 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) * use the cache. */ if (populate_cache && bdev_is_zoned(device->bdev)) { - zone_info->zone_cache = vzalloc(sizeof(struct blk_zone) * - zone_info->nr_zones); + zone_info->zone_cache = + vzalloc(array_size(zone_info->nr_zones, + sizeof(struct blk_zone))); if (!zone_info->zone_cache) { btrfs_err_in_rcu(device->fs_info, "zoned: failed to allocate zone cache for %s",