Message ID | 20230627144339.144478-21-Julia.Lawall@inria.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8268572vqr; Tue, 27 Jun 2023 08:07:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+qLsurYRW1chutvJ0ggq9aaPGkGXZplVXrsEJjY0eooYi84WUU9vFEgHIXHxNAmdo/C8d X-Received: by 2002:a17:906:64db:b0:98d:5ae2:f1c with SMTP id p27-20020a17090664db00b0098d5ae20f1cmr11369372ejn.34.1687878476869; Tue, 27 Jun 2023 08:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878476; cv=none; d=google.com; s=arc-20160816; b=L6zwzDGHfu6ogTF+D0pReWZOozUy1DpvdksmnM/g1C44v6Yu+v14VgcKtGySrQXQFs uyh4okFrSrtB+Xb2ehkyLTMgM5WfHyayLDCEE4r/2H7vRbV7Sj6KzPP+rbN0HuvEz53I WR05TlRFCjc57M8aSVGUpEnQBRkR/h6U105Adf7GV0JYbIjOg//q56iDfQXedT63a+BJ NbmWsfCzr4iebvTL9gtb6OdPP57Bpn8TFPGudjn2WikiCG9OCFLcWell6JvnnutRjBwC YJ/xKHIN7IaJ3vZZ86piWrRaDaF8ApRpB8CSMtPWTLfFcfushIXbkdsr9dGCKTG+RxhQ 6/0w== 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=VbQwbhgrDYedmuD3Y7RCVQ57pP4c57YQ3unyPj5Q6N4=; fh=xG++Ct94g/YGAS8zVkboMlT523ejGRcTzzsL3xuTrg4=; b=ZGIDeYu+4m52E7z5SWAoMnhPMScIy0KFWTnujaOYq6OhsHafpmv4MHTl8JnAKuPo3C ge2TXUIsgcR3q/dgiDg+/R5FybVGjffwUOFf0Dxm6+Y6EGGJY/fIyMdDCF9p7+WQwpsS V/FQ9SrEcNOM/yhBLZt7TBafq0mc1QMZqkxVJuIXXI9ywle2IcjcVtwu5Co3FXWRxuCf Xi+Cxf6SYa1acibdsKIVTHVQ8tfUaScdn7zZfmnjdwjsGNpayw2Hh7ozIBk4EuLTtOnY cgN1yBTxUpxToHJc6vGQQCOzKaRwSM68Zwt/gsU0uzN0aVmO9ldSmZTBYSU/PDgWwBa4 I2SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=nMz70TxR; 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 m19-20020a1709066d1300b00988a13c6a90si4202136ejr.601.2023.06.27.08.07.15; Tue, 27 Jun 2023 08:07:56 -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=nMz70TxR; 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 S232224AbjF0Oq6 (ORCPT <rfc822;nicolai.engesland@gmail.com> + 99 others); Tue, 27 Jun 2023 10:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbjF0Op4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 27 Jun 2023 10:45:56 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A5F41A2; Tue, 27 Jun 2023 07:45:25 -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=VbQwbhgrDYedmuD3Y7RCVQ57pP4c57YQ3unyPj5Q6N4=; b=nMz70TxR38nwlO049zqy5wzxY7CBD7tWCsU5Sn6Y6MlVDUptwIcjVDE5 p6BL4QWGL3Ag4tQzyaC7hjRzFtGLZRTZymYhHQTTx2ihXgi3j+8n0iMOR bFTgYsROCO8yKBSy3R85gXtUQz94fVgblUf+B/eGNjmAxR9FgkimEm8r1 c=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936343" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall <Julia.Lawall@inria.fr> To: Ian Abbott <abbotti@mev.co.uk> Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, H Hartley Sweeten <hsweeten@visionengravers.com>, linux-kernel@vger.kernel.org Subject: [PATCH v2 20/24] comedi: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:35 +0200 Message-Id: <20230627144339.144478-21-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769868862189629662?= X-GMAIL-MSGID: =?utf-8?q?1769868862189629662?= |
Series |
use vmalloc_array and vcalloc
|
|
Commit Message
Julia Lawall
June 27, 2023, 2:43 p.m. UTC
Use vmalloc_array and vcalloc to protect against
multiplication overflows.
The changes were done using the following Coccinelle
semantic patch:
// <smpl>
@initialize:ocaml@
@@
let rename alloc =
match alloc with
"vmalloc" -> "vmalloc_array"
| "vzalloc" -> "vcalloc"
| _ -> failwith "unknown"
@@
size_t e1,e2;
constant C1, C2;
expression E1, E2, COUNT, x1, x2, x3;
typedef u8;
typedef __u8;
type t = {u8,__u8,char,unsigned char};
identifier alloc = {vmalloc,vzalloc};
fresh identifier realloc = script:ocaml(alloc) { rename alloc };
@@
(
alloc(x1*x2*x3)
|
alloc(C1 * C2)
|
alloc((sizeof(t)) * (COUNT))
|
- alloc((e1) * (e2))
+ realloc(e1, e2)
|
- alloc((e1) * (COUNT))
+ realloc(COUNT, e1)
|
- alloc((E1) * (E2))
+ realloc(E1, E2)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
v2: Use vmalloc_array and vcalloc instead of array_size.
This also leaves a multiplication of a constant by a sizeof
as is. The position of this patch in the series changed
accordingly.
drivers/comedi/comedi_buf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff -u -p a/drivers/comedi/comedi_buf.c b/drivers/comedi/comedi_buf.c --- a/drivers/comedi/comedi_buf.c +++ b/drivers/comedi/comedi_buf.c @@ -89,7 +89,7 @@ comedi_buf_map_alloc(struct comedi_devic bm->dma_hw_dev = get_device(dev->hw_dev); } - bm->page_list = vzalloc(sizeof(*buf) * n_pages); + bm->page_list = vcalloc(n_pages, sizeof(*buf)); if (!bm->page_list) goto err; @@ -169,7 +169,7 @@ static void __comedi_buf_alloc(struct co buf = &bm->page_list[0]; async->prealloc_buf = buf->virt_addr; } else { - pages = vmalloc(sizeof(struct page *) * n_pages); + pages = vmalloc_array(n_pages, sizeof(struct page *)); if (!pages) return;