Message ID | 20230623211457.102544-24-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 k13csp6046702vqr; Fri, 23 Jun 2023 14:20:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D9JD01Mvqw3ohr0ozb6l7xKgFHuE6suTrNDyHzXr49MM1XAd1tyWi6bbMaB+s3w/xhKTy X-Received: by 2002:a05:6a20:2588:b0:106:5dff:5db5 with SMTP id k8-20020a056a20258800b001065dff5db5mr38305082pzd.1.1687555207222; Fri, 23 Jun 2023 14:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687555207; cv=none; d=google.com; s=arc-20160816; b=qgn/kpzEMcuhcX8ONebV6M6+Zr8T/7/TkpeTV84gbSu+L0KA+CsHBooQy0YWBqBy0Q P2pYnXnatghV6l6p/MD3dIkn69upXFhsDSXzbF30OvU1U0WBnJ9CvqksCMWrmIDC8Q3P AZpf1hGj2Y164yMRcUtooUPgeUSgQx7bMV84j46OOkupkglm7aW3ID0XCcC9B/ImRvFk Xx8FUoKflM6n1onhjzfrlNW1lPm05P+52zu8IF0nQZlYxqp7SDqpgKYs1pQhOxYXBxIX JSCgVLB16Fcy1imW0gUEthRrlBsxIJ2UHzjOw/kmhRzTaCh7tM+eGLzZz0a3hI6WtxR9 O+Jw== 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=W1WB9Wb0BvRRcBkbSVITYF4i4Xscr+EN0kvgwOJ6wOs=; fh=Rdk+OWmudmdPt+m21oN6e9kPfmvlv0u9RO9HC7/sCwc=; b=ssZvChMAHClyDoQ/bbl/8eRhUhGhE0kdQy2gV/pKq2ytimGjaANVfP9wb/o4k3UP4/ wOBKj2FOlkg3Nzo9V+iiSpu5g+73zmpzXzIgk4nwKcDsewoCwmpMfNcf1yMAKE3+ZcFm Q+eSHLXYbNEUg1hfYaH35dSQAGYu8A/qBledyVGiVysR3413lX2XWS+1HZSLkYkRm5XA x3ak28SXV7iLTrl7ac7vBZ0yAHM0HbNsm2/q3Gqbs6JfYPobHBq3EWD43vk50eLxVh3l dSz/GxXsc2g9C2KFUThau0Q9kIGMXyxJa4Xhis6K9bbEjOG0O5XL4Kv2UNhllNqyy0/w kF5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b="WmG/JpBr"; 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 q37-20020a631f65000000b0054f73ee92basi280155pgm.8.2023.06.23.14.19.54; Fri, 23 Jun 2023 14:20: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="WmG/JpBr"; 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 S232951AbjFWVQl (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Fri, 23 Jun 2023 17:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232895AbjFWVQA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 23 Jun 2023 17:16:00 -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 ED00B295E; Fri, 23 Jun 2023 14:15:28 -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=W1WB9Wb0BvRRcBkbSVITYF4i4Xscr+EN0kvgwOJ6wOs=; b=WmG/JpBrM0La8Q7SPsscDO+9vwp6o00kURhYuE4MeUme0ls/EvAKTJhY mp+BcN1WhFW8+h7eRAujDv59DBrIbAx6oxgu581730TSsqjI0R/hG8vwc R2wBhiJozXLBTfyUjGNSc07qmFKw/jr6X7BSNFOgHP2+n6nDAix+z1p0U Q=; 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="59686181" 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:14 +0200 From: Julia Lawall <Julia.Lawall@inria.fr> To: Sakari Ailus <sakari.ailus@linux.intel.com> Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Bingbu Cao <bingbu.cao@intel.com>, Tianshu Qiu <tian.shu.qiu@intel.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 23/26] media: staging: imgu: use array_size Date: Fri, 23 Jun 2023 23:14:54 +0200 Message-Id: <20230623211457.102544-24-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 Content-Transfer-Encoding: 8bit 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: <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?1769529889227792498?= X-GMAIL-MSGID: =?utf-8?q?1769529889227792498?= |
Series |
use array_size
|
|
Commit Message
Julia Lawall
June 23, 2023, 9:14 p.m. UTC
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
drivers/staging/media/ipu3/ipu3-mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Julia, Thanks for your patch. On 6/24/23 5:14 AM, Julia Lawall wrote: > Use array_size to protect against multiplication overflows. > > The changes were done using the following Coccinelle semantic patch: > > // <smpl> > @@ > expression E1, E2; > constant C1, C2; > identifier alloc = {vmalloc,vzalloc}; > @@ > > ( > alloc(C1 * C2,...) > | > alloc( > - (E1) * (E2) > + array_size(E1, E2) > ,...) > ) > // </smpl> > > Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> > > --- > drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c > index cb9bf5fb29a5..9c4adb815c94 100644 > --- a/drivers/staging/media/ipu3/ipu3-mmu.c > +++ b/drivers/staging/media/ipu3/ipu3-mmu.c > @@ -464,7 +464,7 @@ struct imgu_mmu_info *imgu_mmu_init(struct device *parent, void __iomem *base) > * Allocate the array of L2PT CPU pointers, initialized to zero, > * which means the dummy L2PT allocated above. > */ > - mmu->l2pts = vzalloc(IPU3_PT_PTES * sizeof(*mmu->l2pts)); > + mmu->l2pts = vzalloc(array_size(IPU3_PT_PTES, sizeof(*mmu->l2pts))); > if (!mmu->l2pts) > goto fail_l2pt; > > Reviewed-by: Bingbu Cao <bingbu.cao@intel.com>
On Fri, 23 Jun 2023, Julia Lawall wrote: > Use array_size to protect against multiplication overflows. > > The changes were done using the following Coccinelle semantic patch: > > // <smpl> > @@ > expression E1, E2; > constant C1, C2; > identifier alloc = {vmalloc,vzalloc}; > @@ > > ( > alloc(C1 * C2,...) > | > alloc( > - (E1) * (E2) > + array_size(E1, E2) > ,...) > ) > // </smpl> > > Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> > > --- > drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c > index cb9bf5fb29a5..9c4adb815c94 100644 > --- a/drivers/staging/media/ipu3/ipu3-mmu.c > +++ b/drivers/staging/media/ipu3/ipu3-mmu.c > @@ -464,7 +464,7 @@ struct imgu_mmu_info *imgu_mmu_init(struct device *parent, void __iomem *base) > * Allocate the array of L2PT CPU pointers, initialized to zero, > * which means the dummy L2PT allocated above. > */ > - mmu->l2pts = vzalloc(IPU3_PT_PTES * sizeof(*mmu->l2pts)); > + mmu->l2pts = vzalloc(array_size(IPU3_PT_PTES, sizeof(*mmu->l2pts))); > if (!mmu->l2pts) > goto fail_l2pt; I think that this patch can be dropped. Since it is a multiplcation of two constants, if there is an overflow, I guess the compiler would detect it? julia
Hi Julia, Bingbu, On Tue, Jun 27, 2023 at 07:35:47PM +0200, Julia Lawall wrote: > > > On Fri, 23 Jun 2023, Julia Lawall wrote: > > > Use array_size to protect against multiplication overflows. > > > > The changes were done using the following Coccinelle semantic patch: > > > > // <smpl> > > @@ > > expression E1, E2; > > constant C1, C2; > > identifier alloc = {vmalloc,vzalloc}; > > @@ > > > > ( > > alloc(C1 * C2,...) > > | > > alloc( > > - (E1) * (E2) > > + array_size(E1, E2) > > ,...) > > ) > > // </smpl> > > > > Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> > > > > --- > > drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c > > index cb9bf5fb29a5..9c4adb815c94 100644 > > --- a/drivers/staging/media/ipu3/ipu3-mmu.c > > +++ b/drivers/staging/media/ipu3/ipu3-mmu.c > > @@ -464,7 +464,7 @@ struct imgu_mmu_info *imgu_mmu_init(struct device *parent, void __iomem *base) > > * Allocate the array of L2PT CPU pointers, initialized to zero, > > * which means the dummy L2PT allocated above. > > */ > > - mmu->l2pts = vzalloc(IPU3_PT_PTES * sizeof(*mmu->l2pts)); > > + mmu->l2pts = vzalloc(array_size(IPU3_PT_PTES, sizeof(*mmu->l2pts))); > > if (!mmu->l2pts) > > goto fail_l2pt; > > I think that this patch can be dropped. Since it is a multiplcation of > two constants, if there is an overflow, I guess the compiler would detect > it? Indeed. vcalloc() would be perhaps nicer but the original isn't wrong either.
diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb29a5..9c4adb815c94 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -464,7 +464,7 @@ struct imgu_mmu_info *imgu_mmu_init(struct device *parent, void __iomem *base) * Allocate the array of L2PT CPU pointers, initialized to zero, * which means the dummy L2PT allocated above. */ - mmu->l2pts = vzalloc(IPU3_PT_PTES * sizeof(*mmu->l2pts)); + mmu->l2pts = vzalloc(array_size(IPU3_PT_PTES, sizeof(*mmu->l2pts))); if (!mmu->l2pts) goto fail_l2pt;