From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAC9E5257 for ; Thu, 29 Jun 2023 07:34:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688024079; x=1719560079; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=/axrSWOdtVz/Ckd0cZbOJm+/YGfdBtp+s+fpBkWAL+M=; b=KoUp4AERObC8dxqV0BgNgGgyeSBE0QSqfXdwyzAKGjUdthoUTRo1xlUR XZs8iienuP3RNCLaebwZxtR6rGZJkMSTuzYNKBU5aYyteF2wKz2pXvEQP SoOgQj7FgDwsmd+tdm2s/OUqf5n8zZR7O/Nkg8UeRHJJ17gyRYtuN51Wo 3bxaNXybVzhAXPecuOJxTw+rQdfahYkuBVYBjz79VW725l3bXagqjBszK 27Gz4Q+zT8l1sHMQE95VIeb1KfrbGe2n+RZlDGpvfPgDQtYraAfJmh2uE b7cCs0Q5+DSsQIQ4HkKcw6z1spxQtSF6e0MXMNffO9eiTixu1EupJ5mE8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="364592007" X-IronPort-AV: E=Sophos;i="6.01,167,1684825200"; d="scan'208";a="364592007" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2023 00:34:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="720472979" X-IronPort-AV: E=Sophos;i="6.01,167,1684825200"; d="scan'208";a="720472979" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2023 00:34:36 -0700 Received: from kekkonen.localdomain (localhost [127.0.0.1]) by kekkonen.fi.intel.com (Postfix) with SMTP id E0FA01207EB; Thu, 29 Jun 2023 10:34:33 +0300 (EEST) Date: Thu, 29 Jun 2023 07:34:33 +0000 From: Sakari Ailus To: Julia Lawall Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Bingbu Cao , Tianshu Qiu , Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 23/26] media: staging: imgu: use array_size Message-ID: References: <20230623211457.102544-1-Julia.Lawall@inria.fr> <20230623211457.102544-24-Julia.Lawall@inria.fr> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: > > > > // > > @@ > > 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/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. -- Kind regards, Sakari Ailus