From patchwork Fri Jun 23 21:14:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 112311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6046295vqr; Fri, 23 Jun 2023 14:19:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6voCc7OCZ+FFfvEMb3ok8AQpRB9akOtZY00P6xz2fd2QYBwGqQ2Kgr1nMyw5G9hkODnEw9 X-Received: by 2002:a17:903:446:b0:1b1:86ad:3347 with SMTP id iw6-20020a170903044600b001b186ad3347mr299895plb.3.1687555147604; Fri, 23 Jun 2023 14:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687555147; cv=none; d=google.com; s=arc-20160816; b=1FtuYgORTjBahVaf+j9SXri5tu5LMUR/yDgw6QKcj2gE0gAvgTe1OvQ0AMJdZ5mloF QeWNfytq4Dc1ZS2d5RiAN9BmyMV8wCpwJU/u9o1sKDmpvqQY9YPqI2sB64iYcC8VVQQk o7GmOP7AiPJAil8T150RkyifhxG9Mu1LU3TxiQf6lj4jBa+R9mg8MMRR8Lok2F7e9Pou R+EpsDuQwQdgIUR8ONGPKDPIWG9Q6tGbCL08WpmhGbtnL5xqkyqMOXzhLy6c3RNBoW7k SgbLDII99dmcImlHAncEcEXfEz4MAkSo4O4NbLVpxuAv2xMC2XGA/OIQlnG8qyA+ZpT1 S+mw== 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=42OKv4WqZGQxlnFHmnIuYt+rtnNJuJHuQ6K07YbNUj8=; fh=SQjqolBeMpJhg+n3dLQTExtFoPdMXR2KVoU8KnYenBc=; b=RBxMXCkAijx0FJ8BmvJddXCU2gvzEhdAHxieX3cTanM4RlKseoubgeh6DqvwOIkQn7 CuHUXXWcMm+Ni9/weJ+UML9xbqbUiodX772XgXCF6mUcvemGaNbmcTat4N8lFBfDq+Ip sXvSGVVYz+iE/w3hpwO0xzyQa9gDyjCGmZNqicjAihTysnFjedz9uFUQef8PDoNyGMdK z5LzZ0vkJ/1TJZ9JrDvSU7Pen1xn2somQHARfSXvYbcgGH3hfj5T8L+PrYV5WpTjVQcB Hu5nfKoTwv4E03Ax5rTcoZErmCzgzFS30xWhc8qHJZeydBM9BZpJjNKO8nWY6WCstv4c TDWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=GXBNYgmL; 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 bf11-20020a170902b90b00b001a68f933777si50629plb.245.2023.06.23.14.18.55; Fri, 23 Jun 2023 14:19:07 -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=GXBNYgmL; 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 S232888AbjFWVP6 (ORCPT + 99 others); Fri, 23 Jun 2023 17:15:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232827AbjFWVPX (ORCPT ); Fri, 23 Jun 2023 17:15:23 -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 D342D1993; Fri, 23 Jun 2023 14:15:19 -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=42OKv4WqZGQxlnFHmnIuYt+rtnNJuJHuQ6K07YbNUj8=; b=GXBNYgmL2uYfs6qFigazu5bHqzJHBpCz8l880MNXwd+9eRslqwZ3OOsI Mg6LYxvrebz27/FhrAyaK87WAa+UpTYqEiIKSJflTdI9YiVVutKzyTKHQ OMrvn1ry8QKjC8losr/ymVYFeWIWjK52PpQAd1FD2UAhzi/Qrd3wzTeZP s=; 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="59686173" 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: Oded Gabbay Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/26] habanalabs: use array_size Date: Fri, 23 Jun 2023 23:14:46 +0200 Message-Id: <20230623211457.102544-16-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?1769529826190922912?= X-GMAIL-MSGID: =?utf-8?q?1769529826190922912?= Use array_size to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @@ expression E1, E2; constant C1, C2; identifier alloc = {vmalloc,vzalloc}; @@ ( alloc(C1 * C2,...) | alloc( - (E1) * (E2) + array_size(E1, E2) ,...) ) // Signed-off-by: Julia Lawall --- drivers/accel/habanalabs/common/device.c | 3 ++- drivers/accel/habanalabs/common/state_dump.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index fabfc501ef54..8e2edefa6d3c 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -2572,7 +2572,8 @@ static void hl_capture_user_mappings(struct hl_device *hdev, bool is_pmmu) */ vfree(pgf_info->user_mappings); pgf_info->user_mappings = - vzalloc(pgf_info->num_of_user_mappings * sizeof(struct hl_user_mapping)); + vzalloc(array_size(pgf_info->num_of_user_mappings, + sizeof(struct hl_user_mapping))); if (!pgf_info->user_mappings) { pgf_info->num_of_user_mappings = 0; goto finish; diff --git a/drivers/accel/habanalabs/common/state_dump.c b/drivers/accel/habanalabs/common/state_dump.c index 3a9931f24259..324cb7c9bc26 100644 --- a/drivers/accel/habanalabs/common/state_dump.c +++ b/drivers/accel/habanalabs/common/state_dump.c @@ -272,7 +272,7 @@ static u32 *hl_state_dump_read_sync_objects(struct hl_device *hdev, u32 index) base_addr = sds->props[SP_SYNC_OBJ_BASE_ADDR] + sds->props[SP_NEXT_SYNC_OBJ_ADDR] * index; - sync_objects = vmalloc(sds->props[SP_SYNC_OBJ_AMOUNT] * sizeof(u32)); + sync_objects = vmalloc(array_size(sds->props[SP_SYNC_OBJ_AMOUNT], sizeof(u32))); if (!sync_objects) return NULL; @@ -453,8 +453,8 @@ hl_state_dump_alloc_read_sm_block_monitors(struct hl_device *hdev, u32 index) s64 base_addr; /* Base addr can be negative */ int i; - monitors = vmalloc(sds->props[SP_MONITORS_AMOUNT] * - sizeof(struct hl_mon_state_dump)); + monitors = vmalloc(array_size(sds->props[SP_MONITORS_AMOUNT], + sizeof(struct hl_mon_state_dump))); if (!monitors) return NULL;