Message ID | 20230623211457.102544-3-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 k13csp6048654vqr; Fri, 23 Jun 2023 14:24:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CFeQaTXK6S+h8MQDY0twwPdAgUaGovdMeZWVx400zXZdTZc1YaZyB1zLjxsdRXEnzbi3a X-Received: by 2002:a05:6a00:21c2:b0:65a:710a:7855 with SMTP id t2-20020a056a0021c200b0065a710a7855mr17143129pfj.26.1687555479819; Fri, 23 Jun 2023 14:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687555479; cv=none; d=google.com; s=arc-20160816; b=itZyw6ACQ4Sj1ZdQ2EQlxvsgx4dxmJdIWcvGWiLrKAS8xBZlbyL7gVnR4REKxeCIl6 tCef1Is6WPwFgP0tozPMgnXj7XKUAS1W9wdKHzwo8h3QIsi2sOIq21PKAnNcMgOk3xil TL6jOPBh/412882D/iW9elAguiJDWmsCRRe+DZE18Wf98Ehyod0nBkf9xluUdFzVVFPO o8/5bbx+aeDIK4oUtGpfDAmjbRtOncTIT0eIxnihsqFhhRCNwUCKztOatneVfgk1dohZ Uw333JTkDKxO0rlk0igx4LA8Ug1kGpNPU+4YVlPZ5c3uw+6Bh8zw9AJvDPT7B5oglMaJ 4iwg== 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=6uQt9cKBk2Sag9c2YWWjAaGPZs3k3Hvob+itlodbJvE=; fh=Cqc/z/U6Zn38c+j1JjCoDjkQ1/zqQ8NO+by02VHnZBE=; b=GmwLqfNg0DqOPEJS2vek92zjbu5LrmYp3LK7d2LV9z0y87xVaLW0/7cTz6A5inVMKv 2GR+EqsGvu+cRVO1cxlADFXG52PzeMDb/1ptGGnrsoFMhcG1rQT2tH68XkvwCE+cSxzQ r1zlliecun27hoq0y0N2q/dfQDb7Pbpto+Ahx1cdYwG0tnWmDkbd2lPFV4BA71x+1u9r 0m3ZvVe0yIKjMPaUlMMxTO4mvBy/3dGrd6Njxp18xEHCWsGoivKuxXl3ibTEGItMSxfH PbYsltteXmmINb0aWGxB/zshTocaLgoSObP5etBc0j+nu5ydqmJzORFOGnlIIYRwpI94 DOQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=uUeK7v84; 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 b2-20020a6567c2000000b0054402b987ecsi244296pgs.803.2023.06.23.14.24.25; Fri, 23 Jun 2023 14:24:39 -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=uUeK7v84; 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 S231702AbjFWVTA (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Fri, 23 Jun 2023 17:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbjFWVSb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 23 Jun 2023 17:18:31 -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 D82ED294E; Fri, 23 Jun 2023 14:17:47 -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=6uQt9cKBk2Sag9c2YWWjAaGPZs3k3Hvob+itlodbJvE=; b=uUeK7v84Q78fePqXn2J06hqIJHU44vOesDD7hu1wYYvYAjqJ0J/cmLDe UQgoZjPb5/RNMRv/6e8PHGv3hzro41BQHfbx/RndVD2XB7GRo04sYh6fK tpHpLxNHWHvUskJqhO23GItuTkGYflimreyRkgYm+KNieGnnWye4tIA+W c=; 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="59686160" 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:10 +0200 From: Julia Lawall <Julia.Lawall@inria.fr> To: Veerasenareddy Burru <vburru@marvell.com> Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Abhijit Ayarekar <aayarekar@marvell.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/26] octeon_ep: use array_size Date: Fri, 23 Jun 2023 23:14:33 +0200 Message-Id: <20230623211457.102544-3-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=unavailable 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?1769530174806075844?= X-GMAIL-MSGID: =?utf-8?q?1769530174806075844?= |
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/net/ethernet/marvell/octeon_ep/octep_rx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Jun 23, 2023 at 11:14:33PM +0200, 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> Reviewed-by: Simon Horman <simon.horman@corigine.com>
On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote: > - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE); > + oq->buff_info = vzalloc(array_size(oq->max_count, OCTEP_OQ_RECVBUF_SIZE)); vcalloc seems to exist, is there a reason array_size() is preferred?
Le 25/06/2023 à 00:28, Jakub Kicinski a écrit : > On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote: >> - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE); >> + oq->buff_info = vzalloc(array_size(oq->max_count, OCTEP_OQ_RECVBUF_SIZE)); > > vcalloc seems to exist, is there a reason array_size() is preferred? Hi, just for your information, I've just sent [1]. CJ [1]: https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/
On Sun, 25 Jun 2023, Christophe JAILLET wrote: > Le 25/06/2023 à 00:28, Jakub Kicinski a écrit : > > On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote: > > > - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE); > > > + oq->buff_info = vzalloc(array_size(oq->max_count, > > > OCTEP_OQ_RECVBUF_SIZE)); > > > > vcalloc seems to exist, is there a reason array_size() is preferred? > > Hi, > > just for your information, I've just sent [1]. > > CJ > > [1]: > https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/ For some reason, I have only received Christophe's mail, not Jakub's... In any case, thanks for pointing out the existence of these functions. I just redid what Kees did in 2018, when I guess these functions didn't exist. I will look more carefully to see what functions are now available and resend the whole thing. Thanks! julia
Le 25/06/2023 à 22:25, Julia Lawall a écrit : > > > On Sun, 25 Jun 2023, Christophe JAILLET wrote: > >> Le 25/06/2023 à 00:28, Jakub Kicinski a écrit : >>> On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote: >>>> - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE); >>>> + oq->buff_info = vzalloc(array_size(oq->max_count, >>>> OCTEP_OQ_RECVBUF_SIZE)); >>> >>> vcalloc seems to exist, is there a reason array_size() is preferred? >> >> Hi, >> >> just for your information, I've just sent [1]. >> >> CJ >> >> [1]: >> https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/ > > For some reason, I have only received Christophe's mail, not Jakub's... > > In any case, thanks for pointing out the existence of these functions. I > just redid what Kees did in 2018, when I guess these functions didn't > exist. I will look more carefully to see what functions are now available > and resend the whole thing. Hi, should you want to go 1 step further and simplify some code: git grep v[mz]alloc.*array_size\( | wc -l 174 CJ > > Thanks! > > julia
On Sun, 25 Jun 2023, Christophe JAILLET wrote: > Le 25/06/2023 à 22:25, Julia Lawall a écrit : > > > > > > On Sun, 25 Jun 2023, Christophe JAILLET wrote: > > > > > Le 25/06/2023 à 00:28, Jakub Kicinski a écrit : > > > > On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote: > > > > > - oq->buff_info = vzalloc(oq->max_count * > > > > > OCTEP_OQ_RECVBUF_SIZE); > > > > > + oq->buff_info = vzalloc(array_size(oq->max_count, > > > > > OCTEP_OQ_RECVBUF_SIZE)); > > > > > > > > vcalloc seems to exist, is there a reason array_size() is preferred? > > > > > > Hi, > > > > > > just for your information, I've just sent [1]. > > > > > > CJ > > > > > > [1]: > > > https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/ > > > > For some reason, I have only received Christophe's mail, not Jakub's... > > > > In any case, thanks for pointing out the existence of these functions. I > > just redid what Kees did in 2018, when I guess these functions didn't > > exist. I will look more carefully to see what functions are now available > > and resend the whole thing. > > Hi, > > should you want to go 1 step further and simplify some code: > > git grep v[mz]alloc.*array_size\( | wc -l > 174 Yes, thanks for the suggestion. julia > > CJ > > > > > Thanks! > > > > julia > >
diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c index 392d9b0da0d7..185b7e50ee77 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c @@ -158,7 +158,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no) goto desc_dma_alloc_err; } - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE); + oq->buff_info = vzalloc(array_size(oq->max_count, OCTEP_OQ_RECVBUF_SIZE)); if (unlikely(!oq->buff_info)) { dev_err(&oct->pdev->dev, "Failed to allocate buffer info for OQ-%d\n", q_no);