Message ID | 20230706134000.130098-1-suijingfeng@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2579205vqx; Thu, 6 Jul 2023 06:59:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlGz+8z/0yVqfXiI6AVmPhACK9sSyZzx+ycNnvf5s8sQlMVTrT1VnrVFFKut4bK6yB2XRxy0 X-Received: by 2002:a17:903:2795:b0:1b8:9958:e14b with SMTP id jw21-20020a170903279500b001b89958e14bmr1549239plb.10.1688651951604; Thu, 06 Jul 2023 06:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688651951; cv=none; d=google.com; s=arc-20160816; b=bJj4sCIhBkwdEsx2g3Hc/Jvv4UD719XuoKwm5YFd4C10WCp51tTQsRHVH0Ydo0a1Jl ckusYYM3OK+/tKDKs2zD9ZYJuYKwnpOOdJgDynylGVkfmQZBPRbTtcuQb3bG+1+eNI1Y xwVoKvYXIHczqgqPrn6cxkfwqojdqqLR7e/cXTyDrpI4fcE+vATbKlQ/aqIYRifBU40y 5/M/foTBiASNPQg3T6/CN1yCzicDZNbwwRDrdFjuwiF8unXz6Z6ZMtkcvE4NL3Z3QGA8 4NVepAZxamdJWQIsei1Y08ZYcniX4klg4u3Q0MRHQeWcExX5sUDt/gY8oCn2oSJ8BtWE rv/Q== 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=wPpBDlYaIuD+VMsca1EiUkZwQdb3LgKSP8mKv4+2NUM=; fh=gSBn7OVk7dOJk/4sITu0Y1/ehR135nbXxANz0I09pmE=; b=Th4zqpJ9G2ltrJ3CUyDlZepNFe3p7nNpp574VxcsH3FmveFvSEEJOxjEL0rHI/QD0M rSVvnv1Z1zUI+9zrl6P6u2aBruMEM286OS3bjYHqNWWFGUykj5qOCm8J2ojJXYhJkkGH TKmR7GQ8oW8HqDI1DuJoAOUcDVn9mMGTt3Ajo+XcXom3TEntFrKF5CBZgcPbaMQTV7WY MX5f+AKvklkwg7mqKyA/7dU288aBbmda7+CJVHgz/ZFdhJKkOSdBb6Gr6yo96PGg1WqK BFrpy0nz/VUh6gogXBgXrdDyqpGSJTmJZwAqjcEbMXBTvink8G8bW+nltmifu1Deq4X7 gtZA== 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 j4-20020a170902da8400b001b8c7085d7dsi807995plx.292.2023.07.06.06.58.55; Thu, 06 Jul 2023 06:59:11 -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 S231769AbjGFNkJ (ORCPT <rfc822;hadasmailinglist@gmail.com> + 99 others); Thu, 6 Jul 2023 09:40:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbjGFNkI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 6 Jul 2023 09:40:08 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A6466131 for <linux-kernel@vger.kernel.org>; Thu, 6 Jul 2023 06:40:05 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Axjus0xKZkGfgAAA--.1104S3; Thu, 06 Jul 2023 21:40:04 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx5swyxKZkoPYeAA--.5921S2; Thu, 06 Jul 2023 21:40:02 +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>, CK Hu <ck.hu@mediatek.com> Cc: dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Mergnat <amergnat@baylibre.com> Subject: [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail Date: Thu, 6 Jul 2023 21:40:00 +0800 Message-Id: <20230706134000.130098-1-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Dx5swyxKZkoPYeAA--.5921S2 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj9xXoWruryruF4ktw18JFWUKr1fKrX_yoWkWwcEka n2vr17Wrs7Gr98Aa12kw1avFWSyFWruF48Ja95K34ft3yUGr1UXry29rn8WFnxJ3Z29FyD twn8XF95ZFnrZosvyTuYvTs0mTUanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUbSxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r12 6r1DMcIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU4cdbUUUUU 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?1770679908754226980?= |
Series |
[v2] drm/mediatek: Fix potential memory leak if vmap() fail
|
|
Commit Message
Sui Jingfeng
July 6, 2023, 1:40 p.m. UTC
Also return -ENOMEM if such a failure happens, the implement should take responsibility for the error handling. Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap function") Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> 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
Hi, Jingfeng: On Thu, 2023-07-06 at 21:40 +0800, Sui Jingfeng wrote: > > External email : Please do not click links or open attachments until > you have verified the sender or the content. > Also return -ENOMEM if such a failure happens, the implement should > take > responsibility for the error handling. Reviewed-by: CK Hu <ck.hu@mediatek.com> > > Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap > function") > Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> > Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> > 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; > + } > out: > kfree(sgt); > iosys_map_set_vaddr(map, mtk_gem->kvaddr); > -- > 2.34.1
Hi, Thanks a lot! On 2023/7/27 09:47, CK Hu (胡俊光) wrote: > Hi, Jingfeng: > > On Thu, 2023-07-06 at 21:40 +0800, Sui Jingfeng wrote: > > > > External email : Please do not click links or open attachments until > > you have verified the sender or the content. > > Also return -ENOMEM if such a failure happens, the implement should > > take > > responsibility for the error handling. > > Reviewed-by: CK Hu <ck.hu@mediatek.com> > > > > > Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap > > function") > > Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> > > Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> > > 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; > > +} > > out: > > kfree(sgt); > > iosys_map_set_vaddr(map, mtk_gem->kvaddr); > > -- > > 2.34.1 > > ************* MEDIATEK Confidentiality Notice ******************** > The information contained in this e-mail message (including any > attachments) may be confidential, proprietary, privileged, or otherwise > exempt from disclosure under applicable laws. It is intended to be > conveyed only to the designated recipient(s). Any use, dissemination, > distribution, printing, retaining or copying of this e-mail (including its > attachments) by unintended recipient(s) is strictly prohibited and may > be unlawful. If you are not an intended recipient of this e-mail, or believe > that you have received this e-mail in error, please notify the sender > immediately (by replying to this e-mail), delete any and all copies of > this e-mail (including any attachments) from your system, and do not > disclose the content of this e-mail to any other person. Thank you!
Il 06/07/23 15:40, Sui Jingfeng ha scritto: > Also return -ENOMEM if such a failure happens, the implement should take > responsibility for the error handling. > > Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap function") > Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> > Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Hi, On 2023/7/27 17:22, AngeloGioacchino Del Regno wrote: > Il 06/07/23 15:40, Sui Jingfeng ha scritto: >> Also return -ENOMEM if such a failure happens, the implement should take >> responsibility for the error handling. >> >> Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap >> function") >> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> >> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> >> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > > Reviewed-by: AngeloGioacchino Del Regno > <angelogioacchino.delregno@collabora.com> Yeah! I got so many R-B! So surprise, So happy! Hopefully someone will merge/apply this patch someday, thanks.
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);