Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18148038rwd; Tue, 27 Jun 2023 12:20:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Nnb94k4WvdzTLsXnO49vp2TLkarCO7CUg3a42xwN84/1Sp7c/jP8RYcYGbcUSzHkVH8VJ X-Received: by 2002:a17:907:160c:b0:991:e849:e13b with SMTP id hb12-20020a170907160c00b00991e849e13bmr4713823ejc.10.1687893657836; Tue, 27 Jun 2023 12:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687893657; cv=none; d=google.com; s=arc-20160816; b=gzHcEBRMixu0shMZDj6bhv+hU2FVGOLWLBqvQC8U7RL8vBnmiBPcQrwIrRROtg6cOZ F2I58HHe8cOfvrx0u0cQUXtqR2kWcnQczAiqNmXB1PYZp1kXfU4mPWBFW1/USgIXjdU7 SPTvbZhvuKZTsS5sewwhKgFHvbOlZsbq4GgkXqqZgsVVU//uz44h9hMmkL0pcb2Y7Apt hKyJm+raH5Bn7YdKdmTQCsaOO+9ysDoL0tgH/sXxE5wYBBshHPJE5qs4hLpWfQDKCKGr YGux3nzUC9Utx2tMeAA+f1Ng2JLme4sTEGeNJGK9bHMuv6sM3DwSys5/K09PxACUqXRb RQ0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=XanXoDlHYuqu7WYlucQ21J3KG2JUv31j1KTL+YaYRcw=; fh=FEH4yseDZ0XsiX7SX8xKBDfdsCufTmzF9HTr2YTAQe0=; b=zyA1EpV+4kx5sm9K0nZ/KMmJolfwR15zkMxJ8Fn4LwhyKDRuHQweYDRzSQ2ntjXgcz Qlegb51F1cwfNKG9efM+qXzNZ+ocIu+syY0hrN+mnUoFJGSTd+HPU4idPxeRAfIz60kM U5GtAzO1fS2h0W3nkpRkFoAHIy9Go9F/IrVHNJe5R9UZUDsVIb0RubrPV5kPvYndl9dB okipjDuZSyU6Gu3DPBMfMxuEZAvSXwCn7bG0zNqvd62HnltccmcFacLqWFvtstGfC5YV 9otltUkBh/QcDBQbPpNRQK4Y0tK6AQnmOdZV4Tj5PvUKUutfv0i7132IxiKb8n25ZhQb iyHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=tPrpWdnP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a170906a41300b0098730845081si4535269ejz.599.2023.06.27.12.20.31; Tue, 27 Jun 2023 12:20:57 -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=@google.com header.s=20221208 header.b=tPrpWdnP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbjF0Swm (ORCPT + 99 others); Tue, 27 Jun 2023 14:52:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjF0Swl (ORCPT ); Tue, 27 Jun 2023 14:52:41 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DA7E19A8 for ; Tue, 27 Jun 2023 11:52:40 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-401d1d967beso51351cf.0 for ; Tue, 27 Jun 2023 11:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687891959; x=1690483959; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XanXoDlHYuqu7WYlucQ21J3KG2JUv31j1KTL+YaYRcw=; b=tPrpWdnP56AC15CdynAtlLaMhZcoMrwTEd/uWTCfR3x6ZSk2aQs18un036H4Ui91Mz yipTpkAWSSEw3sBbMhjNPTFYagOc2smOlg8be0RQW47nzZtgo+C5Ptfe55oDSxjaSkX0 idJ5n7fJQSXQxasfFIWbg2LKCscxSP6nA95ZRZt6P+sFiMDn6Y+k3aHiI3giIk0UJOI+ RsBiyEWPVmLE1yxdaMJ8gPZHKUeeMrjGJJGfIo73hE1hVi5UIcHUAG/2LgLNnAze8rTB /iF1/wOik0/z5RMYKefbcBecyhdwgNOoRGVNJZZZCrdwIR3VXSMUnaseQ55GbmLr05Td l7VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687891959; x=1690483959; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XanXoDlHYuqu7WYlucQ21J3KG2JUv31j1KTL+YaYRcw=; b=h6UlPD6TKt1GyOxRi8CzZNT4ZulgEsdyRHgnYhQ9ydMxEsRSF9TTgrdjlnw0IG5VDe fyAI86+EDGjLFnrpAAIiFgQqRIuJK31lT1+t7LCpgWimQ1VwoSqlyicNQFqLCYh0xTZ5 Tf6lWbli5cIG6iJCRas+0fQM2SqSiyoRDNPJswfbKtrNEVEK0yVnwMmpHM1RQljVKGb7 hiQiWz63IbRTC8qZ2ozGrn8T0IZawx2BOqq0BEoFE1SFWUFcXRFrjbfnChyg2jKhD4vX 9MYtTjbefCpf4njB7NgiOi0swW3V6KiJ5+SfCKzUbfoBC8HMCYtshVSYKHrjVUXUnmeh ijug== X-Gm-Message-State: AC+VfDzZ+Bqt43NxEwLRYsakOTn5HGlgS0xk0A29f4b3V8HsT03+i3RK WWlM3T74Lcy9U/sDPJ151heZkqL5FPhfQnMUPpK4 X-Received: by 2002:ac8:5905:0:b0:3f8:5b2:aef0 with SMTP id 5-20020ac85905000000b003f805b2aef0mr19156qty.24.1687891959197; Tue, 27 Jun 2023 11:52:39 -0700 (PDT) MIME-Version: 1.0 References: <20230627144339.144478-1-Julia.Lawall@inria.fr> <20230627144339.144478-7-Julia.Lawall@inria.fr> In-Reply-To: <20230627144339.144478-7-Julia.Lawall@inria.fr> From: John Stultz Date: Tue, 27 Jun 2023 11:52:27 -0700 Message-ID: Subject: Re: [PATCH v2 06/24] dma-buf: system_heap: use vmalloc_array and vcalloc To: Julia Lawall Cc: Sumit Semwal , kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , =?UTF-8?Q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 27, 2023 at 7:44=E2=80=AFAM Julia Lawall wrote: > > Use vmalloc_array and vcalloc to protect against > multiplication overflows. > > The changes were done using the following Coccinelle > semantic patch: > > // > @initialize:ocaml@ > @@ > > let rename alloc =3D > 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 =3D {u8,__u8,char,unsigned char}; > identifier alloc =3D {vmalloc,vzalloc}; > fresh identifier realloc =3D 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) > ) > // > > Signed-off-by: Julia Lawall > > --- > 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/dma-buf/heaps/system_heap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff -u -p a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/= system_heap.c > --- a/drivers/dma-buf/heaps/system_heap.c > +++ b/drivers/dma-buf/heaps/system_heap.c > @@ -221,7 +221,7 @@ static void *system_heap_do_vmap(struct > { > struct sg_table *table =3D &buffer->sg_table; > int npages =3D PAGE_ALIGN(buffer->len) / PAGE_SIZE; > - struct page **pages =3D vmalloc(sizeof(struct page *) * npages); > + struct page **pages =3D vmalloc_array(npages, sizeof(struct page = *)); > struct page **tmp =3D pages; > struct sg_page_iter piter; > void *vaddr; Seems reasonable. Thanks for sending this out! Acked-by: John Stultz thanks -john