From patchwork Thu Jul 6 13:40:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 116732 Return-Path: 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 + 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 ); 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 ; 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 To: Chun-Kuang Hu , Philipp Zabel , David Airlie , Daniel Vetter , Matthias Brugger , AngeloGioacchino Del Regno , CK Hu Cc: dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Mergnat 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 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: 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?= 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 Reviewed-by: Alexandre Mergnat Signed-off-by: Sui Jingfeng Reviewed-by: CK Hu Reviewed-by: AngeloGioacchino Del Regno --- 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);