From patchwork Mon Jun 26 18:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13293388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 928C1EB64D7 for ; Mon, 26 Jun 2023 18:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=RIPHnjS6hfOpUdI5+iuGeYcr1T1Vb4A32iGGqQnNndc=; b=sUrxH17wM/vXvs 8L2fuuSIHDDd9SWUGLzHfjfcG9lZrgytT+tZpAjKGvpgBqvp/bPef/pkGpnFc4YbIviGPE9cW/6n6 1A24pP2YqxF/n4jVqOkX6d0iChYzv9OG6g0c/+DacXrlOgvhi5REMQiP4x2KvDI07w3PhQBqEJcy+ KdLKNDtblynPDxN+D1u/rajkVSuegdRyhxVXKZxrUYI21Xhn0xtgpa81bNb2keWOml1OFwlX54tfx cTIyfJwDjIDIo2fRhN+KQ+kcoOAEKFG+I2zJb2mZcwZQZ1nnpOb+6FdsyX1YduPYltR6RMbwcwPOM p1nBE3QWAaE8BqghSN8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qDrPr-00At9Q-0d; Mon, 26 Jun 2023 18:58:23 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qDrPp-00At8Z-1l; Mon, 26 Jun 2023 18:58:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=Q09QxtDcKFjbIGYE4xpH3FtDk2UGEaaTkrB7gnDXeL0=; b=iPWASvqRRRvrn0f1MG/7kaAlHJ OuuZshIE08M9AFBKwTG71UktCFmG4xiOy2Ev/qV+I0fBZteqr6euG9UNmSxZHrVWq/+Y5NGs2O8gE kKYgbnFluHeC6Ety51i/3DYV7dkdBfr67/1PK0t4JU/QeWxXPIMHaxqDiNWga0WwP3cQu2r6Cvcfo CJhvQrgOfkDjJstxy/F5oAVoin2omi7ZvqxY57d0qoGpElzr+fFuA0bi743Vw7Zt/wfU6w/It/tMI l0BnyVUsWBU26gOMII9pft5a+RkIrYLlbibIRuSW0WebRJ2fB7LXj1e3nFOVJ+3GKcjbmkwVkZtl1 bB9j6Dog==; Received: from mail.loongson.cn ([114.242.206.163]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qDrPk-0044Xw-0V; Mon, 26 Jun 2023 18:58:19 +0000 Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxxcS635lke5MCAA--.4014S3; 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 To: Chun-Kuang Hu , Philipp Zabel , David Airlie , Daniel Vetter , Matthias Brugger , AngeloGioacchino Del Regno 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 X-CM-TRANSID: AQAAf8Ax98y535lk5kgKAA--.23871S2 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj9xXoWruryrJw1rZrWDuF43Wr13KFX_yoWfZFgEkw s29r17Wrn7Cr98AF42yw1SvFWIyFWruF48JFZxKa4ft3yUGF1UXry2vrn8WFnxXFn2gFyD K3Z8XF95Zwn7ZosvyTuYvTs0mTUanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUb7xYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 JVW8Jr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v2 6r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k2 6cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j5WrAUUUUU= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230626_195817_087028_34500004 X-CRM114-Status: UNSURE ( 8.40 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Also return -ENOMEM if such a failure happens, the implement should take responsibility for the error handling. Signed-off-by: Sui Jingfeng Reviewed-by: Matthias Brugger Reviewed-by: Alexandre Mergnat --- 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);