From patchwork Fri Jun 23 21:14:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 112327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6053587vqr; Fri, 23 Jun 2023 14:37:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ486uGVy66QSTKs94L7k3YSYuwrjblj2SfVla3KHF8DAVHWWi9wf7naXUGryx7JDLDdbj7v X-Received: by 2002:a17:902:d543:b0:1b0:7c3c:31f7 with SMTP id z3-20020a170902d54300b001b07c3c31f7mr302406plf.28.1687556246545; Fri, 23 Jun 2023 14:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687556246; cv=none; d=google.com; s=arc-20160816; b=rYjTdV6DVuZ4jvl3ypU7hYdksLdF71gSJbFf75YUUTM7C6oZvRZxV7eBB8nWdw83eJ b5ISejDFek2KRkckYRVrznUfBHM1Cy0qJ6lPKya/3g8hVELbPVvegZgGfqpVp6YFIdl+ ixTvN2yMJInUPhHHJtpEmgLdBV5QxmCCIFYqCj2BR8mcntnpCNWoCicyDSQmWrHN6W21 Lqx11vcXc68XyTERIKFtc/pK/JCStE9pqiFGAV1Sehu+G9+GDNDJVCTwx9EYpS7y2BYc sBs5swODnpJ2BB6ojyqPtzN/qmV5Ld1JO7Cj2nZ/UPoAV5VP6lH2qmZpX++Ub3bmuO95 NoKA== 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=zjTOkHzHNJN2JwbbSn0B3jYr0f7hFN0oZZoh6lbquOQ=; fh=y0ETFeU6w6trYMg3qM1hoduOKRqZ5aMgSndi/hTfcWA=; b=RgHvQAmg/n9jdYEIxHfIHGFUI0P43D3zRlvygMcARg9KZQmX1phl9BeBRmD3I0mOg4 e94pwGZNQMh5uYBrO7DOqhopfldKMIvc8isgal2Ro16xuV1BYoxMcMaZBhdx3HJki8QI PBX7s7TvvDa5Vjv2w2YB8+jwX7F2GkJ39hPWPVn6QaQ2KETNrTRrtArPBoVLI3OcRq0d Dfv65RB4+A+OIRQnSP9mQMOiqBoszMAQptNpZiuxDjbp+h16fAQXFI0bxUvVhxfAmyoW vqtye7u8sRd+wYiSyMkjYzFAyKZAFzIZASRZ4gOZE5p27NxLDjtKwNwfv4OC47iQabtC /VOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=FPVhggAR; 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 q14-20020a170902bd8e00b001ab1279d418si54564pls.474.2023.06.23.14.37.13; Fri, 23 Jun 2023 14:37:26 -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=FPVhggAR; 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 S232893AbjFWVRD (ORCPT + 99 others); Fri, 23 Jun 2023 17:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232885AbjFWVQk (ORCPT ); Fri, 23 Jun 2023 17:16:40 -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 3D0FB30DE; Fri, 23 Jun 2023 14:15:37 -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=zjTOkHzHNJN2JwbbSn0B3jYr0f7hFN0oZZoh6lbquOQ=; b=FPVhggARCWGLgx/uc1XplQBbZp4QfJ3ScSLfue5dgqmPlrnQ4BiqzZpN IQ21XgRjNNOHEfdPKTVuJdURuqERB5NCaGfeDpyZ+YpyMYSfpq+KUPiuU +vQ3rGawBQbmwNRu052NXLgEaJzd/RusbfLOqx+1C3Tv2tUHQBsR4S4Tk g=; 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="59686190" 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:15 +0200 From: Julia Lawall To: Ian Abbott Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, H Hartley Sweeten , linux-kernel@vger.kernel.org Subject: [PATCH 26/26] comedi: use array_size Date: Fri, 23 Jun 2023 23:14:57 +0200 Message-Id: <20230623211457.102544-27-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?1769530978477526817?= X-GMAIL-MSGID: =?utf-8?q?1769530978477526817?= 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 --- drivers/comedi/comedi_buf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/comedi/comedi_buf.c b/drivers/comedi/comedi_buf.c index 393966c09740..32ad3e6e1ce8 100644 --- a/drivers/comedi/comedi_buf.c +++ b/drivers/comedi/comedi_buf.c @@ -89,7 +89,7 @@ comedi_buf_map_alloc(struct comedi_device *dev, enum dma_data_direction dma_dir, bm->dma_hw_dev = get_device(dev->hw_dev); } - bm->page_list = vzalloc(sizeof(*buf) * n_pages); + bm->page_list = vzalloc(array_size(n_pages, sizeof(*buf))); if (!bm->page_list) goto err; @@ -169,7 +169,7 @@ static void __comedi_buf_alloc(struct comedi_device *dev, buf = &bm->page_list[0]; async->prealloc_buf = buf->virt_addr; } else { - pages = vmalloc(sizeof(struct page *) * n_pages); + pages = vmalloc(array_size(n_pages, sizeof(struct page *))); if (!pages) return;