Message ID | 20230627144339.144478-4-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 k13csp8252694vqr; Tue, 27 Jun 2023 07:46:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ZXJ4ISH1V6XARoV6Ru3rVZBZmBgZ42tlED9+hDvJiJukxtdwUbY9QSlFsm4vMRVJn9w5a X-Received: by 2002:a05:6a00:b4e:b0:67f:d5e7:4604 with SMTP id p14-20020a056a000b4e00b0067fd5e74604mr245351pfo.13.1687877187810; Tue, 27 Jun 2023 07:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877187; cv=none; d=google.com; s=arc-20160816; b=Jlhk4zYpB/KUfiPcslzx3lEqjvleNzkNHCPBrjr0Z2ohXpYnGMMzv47BcVZpm1NW+q 0G5dhxlMCNHAsg7xhIp/Uowa9oll0oGcN8eNvCn0EtAUZmQsIB15hu66yPxTS+nv/Mue 1M0W2b2PCjlbByIc7tCPM/ec/JfnF0VpOJPiQmWnZX/2D94Ffb7xJbXjW5wbKgZyPD+Q pcw/Ny6BITDABS8ozVeiTsAZVGh9qV2U9/2sY45WVh87Aq76LQkBDWT8jGsOFnhAXnU7 VWCanctcRQL6EKgRtn931fDZzlJPohi8k4pZWEY0zYqSzT1+zh5XaObLKByVDaNRu9Hd xF7w== 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=e/q9GJUjVjbhzGKibBqdfdyRa1uJDPYc59CeSzfnNk0=; fh=KDjSc6TiaTxYeTQgAIDgbheP2RhMXxXkYk4QBAdMl5w=; b=HoQVC/y0kBQAa85MifuXJcvmPWRcA0AfQjcX0QQRSmeAsUv3YKlB0X0U1WqP0Yvxru wxSSy8WjhoIFu3nWgtag7RB18v/MDqY2b74DCGEPY4UCXrAh0x9HVpa0EboAApLt06CN usv2vrnDbT75kcnTi2bKboiGEz6Dyk2Tl52hvKy8x2xf9rX80f3eP81OVw8m4ukKAans sUMnazD5aUC2DNHuSD842/PGh07bJiORhULcKnd+VlSFTPaRkPGepmgbbG6VUrlpc3YF 9MFGScESNWNswRnUy3yecqnl55NcysYLYNDBxRyyoETHgAKzI2TYd8yXJicBYO3RN0Rc /Ysw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=LFjLqDcU; 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 y23-20020a056a001c9700b0066888630a21si7197675pfw.67.2023.06.27.07.46.15; Tue, 27 Jun 2023 07:46:27 -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=LFjLqDcU; 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 S231960AbjF0Opl (ORCPT <rfc822;nicolai.engesland@gmail.com> + 99 others); Tue, 27 Jun 2023 10:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232169AbjF0OpF (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 27 Jun 2023 10:45:05 -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 9313B2D69; Tue, 27 Jun 2023 07:44:46 -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=e/q9GJUjVjbhzGKibBqdfdyRa1uJDPYc59CeSzfnNk0=; b=LFjLqDcUJOS8QiGxmMwTJ1y4Iep+0HGsVtpDuCawBY5+SQrzARKEYY+e LpJ/2nlUx2u6cO9WYFeUn5ZI5IackFgqx7NrkFGfOUSrq5MH+vXpPKEWq 4rRq0ltEIc/oqu2mZbmlmaagNsebxFirot+mQAJKsleackI83o/NMh+pZ A=; 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="114936320" 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:51 +0200 From: Julia Lawall <Julia.Lawall@inria.fr> To: =?utf-8?q?Noralf_Tr=C3=B8nnes?= <noralf@tronnes.org> Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/24] drm/gud: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:18 +0200 Message-Id: <20230627144339.144478-4-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?1769867510138960889?= X-GMAIL-MSGID: =?utf-8?q?1769867510138960889?= |
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. Two patches are thus dropped from the series.
drivers/gpu/drm/gud/gud_pipe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Am 27.06.23 um 16:43 schrieb Julia Lawall: > 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> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> > > --- > v2: Use vmalloc_array and vcalloc instead of array_size. > This also leaves a multiplication of a constant by a sizeof > as is. Two patches are thus dropped from the series. > > drivers/gpu/drm/gud/gud_pipe.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff -u -p a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c > --- a/drivers/gpu/drm/gud/gud_pipe.c > +++ b/drivers/gpu/drm/gud/gud_pipe.c > @@ -390,7 +390,7 @@ static int gud_fb_queue_damage(struct gu > mutex_lock(&gdrm->damage_lock); > > if (!gdrm->shadow_buf) { > - gdrm->shadow_buf = vzalloc(fb->pitches[0] * fb->height); > + gdrm->shadow_buf = vcalloc(fb->pitches[0], fb->height); > if (!gdrm->shadow_buf) { > mutex_unlock(&gdrm->damage_lock); > return -ENOMEM; > -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
diff -u -p a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c --- a/drivers/gpu/drm/gud/gud_pipe.c +++ b/drivers/gpu/drm/gud/gud_pipe.c @@ -390,7 +390,7 @@ static int gud_fb_queue_damage(struct gu mutex_lock(&gdrm->damage_lock); if (!gdrm->shadow_buf) { - gdrm->shadow_buf = vzalloc(fb->pitches[0] * fb->height); + gdrm->shadow_buf = vcalloc(fb->pitches[0], fb->height); if (!gdrm->shadow_buf) { mutex_unlock(&gdrm->damage_lock); return -ENOMEM;