Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30566241rwd; Thu, 6 Jul 2023 07:41:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHo8KuTw9B2u9zzT/4ZxLrK+8hs97xHaOHHEzEVSylLBUFawJV9cp9wCoWC3sMNdNlaj2ik X-Received: by 2002:a05:6a20:1aa1:b0:123:2973:672c with SMTP id ci33-20020a056a201aa100b001232973672cmr1392681pzb.57.1688654502919; Thu, 06 Jul 2023 07:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688654502; cv=none; d=google.com; s=arc-20160816; b=GrVCTAcPnRlG8fvGwA0RUr7Qwh1EQ0T/XKSCgm8gTkON77JEyT+gb5wn0qvHYiSBrU 76wGdJKwOU6bX3/6qI9aI/4/uVqlZBL5zNHCCS8lUCZM5U1hOXGfrmZBZDQXWq7eTZun QuECrWHL0mOuKxlunzqB3q8RhtWiRtjx18jl8GxhCRlo6OWb2mnJcoX3ZIC09bKOZlnj k6U93uzxYlGjAu05LkQZ498omfTE+PrYDTeI0tLDl55mGY1uYsntOxA6RWiNc2yyrMFK 3ppH78xBac3rVQ3j5BOMg9UDaYDMFuXsHRWl/iWlFhc76dk+6Dfr7z4tY6dT1l2z1elp ibkQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o8-20020a634e48000000b00541cfaad532si1531907pgl.613.2023.07.06.07.41.30; Thu, 06 Jul 2023 07:41:42 -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 S231754AbjGFNkJ (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 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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