Message ID | 20230626185801.684451-1-suijingfeng@loongson.cn |
---|---|
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 k13csp7705738vqr; Mon, 26 Jun 2023 12:26:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5r/d7TWCKjlRzpuSW0vbLZUA+lS84gNq9VqCrVhDZWHHq0XlAqHagjgczztS6qYV4gtNHo X-Received: by 2002:a17:907:62a6:b0:94e:bf3e:638 with SMTP id nd38-20020a17090762a600b0094ebf3e0638mr26316716ejc.11.1687807600938; Mon, 26 Jun 2023 12:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687807600; cv=none; d=google.com; s=arc-20160816; b=ORuF/4zFNP3F7fv8YCPoRyagbc0fT8aLXhjxsk2mcRGaJ5IJbZazjDik063artuz5Y jaeWSfHCOAy0SEG2PfRnwAI2rwSHo8rXWQINmDwCL8GVqQCSQrcDbVxS2vCYYcBcem2M SpyLQd12lPE/3Sg3G1QJ1tigcMDy6RMEjNnKPne2VNYpIA/yMq6coPgHSoItm4+5qQ2S dbPzzuqR8/Fr0yAAE+kHtWjm+NNdhT78DZiGmayzUcyycYYwe6dl+d1mCTnWloIapaPv lYXMkTnqvugWv4PxZDs2bANNlFBxcDM//VHKaBbbZeWpjEQRTe+tKb6CaXsk26OEesgE f7Ig== 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 :message-id:date:subject:cc:to:from; bh=Q09QxtDcKFjbIGYE4xpH3FtDk2UGEaaTkrB7gnDXeL0=; fh=2HMf8O/QeSPgIi4QzXI2JCBTN2hB/ORyp/ChpvpkkiI=; b=NYP/w9tzhYrQj7Y3hDltU8jissALUgsVgVi5h5L8AnP5mj2jmjpI0TFJz6cKtLYqSy gTX7OG+E0KbmNrADX9bIow99P9sioO4VNPHyNclYlAAO9xdiJ9lMWRZKHiFx1iJdgLA+ hQCKmbG5IJBWOMYlvAHcrOcmTEkFOWN99QTYUXG+FDlJwg3xdPzbdKxHVu2uGbxwaDW4 EtcOTp/2myrk0uDQ6C5N4fekPW7VD1aItMaGTABTaXM9HdsZkqAor/ZX5PIn3KUiecpn N6mtXUj01V+MvCiYw2uP5/aZVNtmZBDO38I9z6gQrFAwv4h5nostgjB3wCFsP6gMQZUF 44rg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o24-20020a170906359800b00991b7749bd8si1579642ejb.786.2023.06.26.12.26.16; Mon, 26 Jun 2023 12:26:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230296AbjFZS6N (ORCPT <rfc822;filip.gregor98@gmail.com> + 99 others); Mon, 26 Jun 2023 14:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232713AbjFZS6G (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 26 Jun 2023 14:58:06 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A424613D for <linux-kernel@vger.kernel.org>; Mon, 26 Jun 2023 11:58:03 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxQ8S635lkfZMCAA--.3956S3; Tue, 27 Jun 2023 02:58:02 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax98y535lk5kgKAA--.23871S2; Tue, 27 Jun 2023 02:58:01 +0800 (CST) From: Sui Jingfeng <suijingfeng@loongson.cn> To: Chun-Kuang Hu <chunkuang.hu@kernel.org>, Philipp Zabel <p.zabel@pengutronix.de>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cc: dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] drm/mediatek: Fix potential memory leak if vmap() fail Date: Tue, 27 Jun 2023 02:58:01 +0800 Message-Id: <20230626185801.684451-1-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Ax98y535lk5kgKAA--.23871S2 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj9xXoWruryrJw1rZrWDuF43Wr13KFX_yoWfZFgEkw s29r17Wrn7Cr98AF42yw1SvFWIyFWruF48JFZxKa4ft3yUGF1UXry2vrn8WFnxXFn2gFyD K3Z8XF95Zwn7ZosvyTuYvTs0mTUanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUbfkYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 JVW8Jr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2 x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1D McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4 1lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU4R6wDUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1769794542763225162?= X-GMAIL-MSGID: =?utf-8?q?1769794542763225162?= |
Series |
drm/mediatek: Fix potential memory leak if vmap() fail
|
|
Commit Message
Sui Jingfeng
June 26, 2023, 6:58 p.m. UTC
Also return -ENOMEM if such a failure happens, the implement should take
responsibility for the error handling.
Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
---
drivers/gpu/drm/mediatek/mtk_drm_gem.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
Comments
On 26/06/2023 20:58, Sui Jingfeng wrote: > Also return -ENOMEM if such a failure happens, the implement should take > responsibility for the error handling. > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > --- > drivers/gpu/drm/mediatek/mtk_drm_gem.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > index a25b28d3ee90..9f364df52478 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > @@ -247,7 +247,11 @@ int mtk_drm_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map) > > mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP, > pgprot_writecombine(PAGE_KERNEL)); > - > + if (!mtk_gem->kvaddr) { > + kfree(sgt); > + kfree(mtk_gem->pages); > + return -ENOMEM; > + } Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> > out: > kfree(sgt); > iosys_map_set_vaddr(map, mtk_gem->kvaddr);
On 26/06/2023 20:58, Sui Jingfeng wrote: > Also return -ENOMEM if such a failure happens, the implement should take > responsibility for the error handling. Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Hi, Thanks a lot! On 2023/7/6 19:39, Matthias Brugger wrote: > > > On 26/06/2023 20:58, Sui Jingfeng wrote: >> Also return -ENOMEM if such a failure happens, the implement should take >> responsibility for the error handling. >> >> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> >> --- >> drivers/gpu/drm/mediatek/mtk_drm_gem.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> b/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> index a25b28d3ee90..9f364df52478 100644 >> --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> @@ -247,7 +247,11 @@ int mtk_drm_gem_prime_vmap(struct drm_gem_object >> *obj, struct iosys_map *map) >> mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP, >> pgprot_writecombine(PAGE_KERNEL)); >> - >> + if (!mtk_gem->kvaddr) { >> + kfree(sgt); >> + kfree(mtk_gem->pages); >> + return -ENOMEM; >> + } > > Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> > >> out: >> kfree(sgt); >> iosys_map_set_vaddr(map, mtk_gem->kvaddr);
Hi, thanks a lot! On 2023/7/6 20:13, Alexandre Mergnat wrote: > > > On 26/06/2023 20:58, Sui Jingfeng wrote: >> Also return -ENOMEM if such a failure happens, the implement should take >> responsibility for the error handling. > > Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> >
Il 26/06/23 20:58, Sui Jingfeng ha scritto: > Also return -ENOMEM if such a failure happens, the implement should take > responsibility for the error handling. > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> This commit needs a Fixes tag. Please add the relevant one and resend. Thanks, Angelo > --- > drivers/gpu/drm/mediatek/mtk_drm_gem.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > index a25b28d3ee90..9f364df52478 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > @@ -247,7 +247,11 @@ int mtk_drm_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map) > > mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP, > pgprot_writecombine(PAGE_KERNEL)); > - > + if (!mtk_gem->kvaddr) { > + kfree(sgt); > + kfree(mtk_gem->pages); > + return -ENOMEM; > + } > out: > kfree(sgt); > iosys_map_set_vaddr(map, mtk_gem->kvaddr);
Hi, On 2023/7/6 20:47, AngeloGioacchino Del Regno wrote: > Il 26/06/23 20:58, Sui Jingfeng ha scritto: >> Also return -ENOMEM if such a failure happens, the implement should take >> responsibility for the error handling. >> >> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > > This commit needs a Fixes tag. Please add the relevant one and resend. > Done at [1], Thanks for point this out, I got it. [1] https://patchwork.freedesktop.org/patch/545843/?series=119885&rev=2 > Thanks, > Angelo > >> --- >> drivers/gpu/drm/mediatek/mtk_drm_gem.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> b/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> index a25b28d3ee90..9f364df52478 100644 >> --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c >> @@ -247,7 +247,11 @@ int mtk_drm_gem_prime_vmap(struct drm_gem_object >> *obj, struct iosys_map *map) >> mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP, >> pgprot_writecombine(PAGE_KERNEL)); >> - >> + if (!mtk_gem->kvaddr) { >> + kfree(sgt); >> + kfree(mtk_gem->pages); >> + return -ENOMEM; >> + } >> out: >> kfree(sgt); >> iosys_map_set_vaddr(map, mtk_gem->kvaddr); > >
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c index a25b28d3ee90..9f364df52478 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c @@ -247,7 +247,11 @@ int mtk_drm_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map) mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP, pgprot_writecombine(PAGE_KERNEL)); - + if (!mtk_gem->kvaddr) { + kfree(sgt); + kfree(mtk_gem->pages); + return -ENOMEM; + } out: kfree(sgt); iosys_map_set_vaddr(map, mtk_gem->kvaddr);