Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2381430lqp; Sun, 24 Mar 2024 16:55:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSbxWe+/VPeXWcayWglfuCJwSTVmSpHpb8Nyrt4XYtUE66y5ZRw0ziWZMjwcjHHA2c5pPOQtFWP/y19ub4P/YLTTLL8L7yqFn9XAF3fw== X-Google-Smtp-Source: AGHT+IHmLaFaaU7Yh2Zb5mTsqCMKHxSHBqtl/X4tr5owW/7oZqN4flfWuxbK9zYMAdY16uQrq13T X-Received: by 2002:ac8:5d10:0:b0:431:39c8:1fdc with SMTP id f16-20020ac85d10000000b0043139c81fdcmr5762880qtx.65.1711324517568; Sun, 24 Mar 2024 16:55:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324517; cv=pass; d=google.com; s=arc-20160816; b=xfnwv0+w+RA3zQqkL6fQ10RABnz6u+O5TBpxDQBmxVqaz7jQsIXfa0BW8Uc/5qtPEF NBDY0SqU+u20oYzSpF6zu4m1qQK81PZGhxnk6bSDRTaNNIW0V9IT3zsW7B5cuSAEh3E2 rlfuxYAfXlHuv/yy6tJnRZmiBSmt2Pl2m2MS24AVjf3c/g2+4/TP03aCGqJ8jGZwOhj2 epIVbU8I1UgpBDSiVBNiJepDu39HU+kqtvuGrEsKlvM0Cyinr+V18MGzyVfmukWyqHd8 3x/bX9Bw4JtL4suBBO5Lm5njIy7K5MUyNb0yCQrxwD6hHOsOFjMY7nNiI9SItkhh9xGh yVRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mXk/EHon/bvgtw8HYyjxb/86emB6/bfRLWXYEI3Ny5M=; fh=jlHTww3USfPCOjIS4Y94SiVVd38kkecD7jGDMCIKLF8=; b=T6daVCRRyAaHlNgqcQg6mdpo5lTB2paPTZX5KaZ4DPL36u1Fa/Pub60Q10FwY1H3ou fs8md4NLy86CmMBV1cQUMSWeKb9i78QW9nh0pjkkVvnRBHCJ2Svb+M3IAx97nsZ89X02 XFqqkBobsKi6N/m9IdHcnMsBP+7R9i/s9Bsdia8M5l0bbTdf/b+edO5Z5K8j51+KEw8j Hc6OPvVgP16lfsmObh2XqU5GgEB0xXQBK8U4lMzkY2C6iON+jdbfCedJCSd0vCb7aH+a D84oPVsTaJwiOnXPfcHeRWRNeQJjo1yfzIhDK6zcpIVRAqWCW85lE0ynu0iOMH0gbTlw cnaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I37O5HjN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113256-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113256-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g12-20020ac8580c000000b004315cfcc239si289459qtg.339.2024.03.24.16.55.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:55:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113256-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I37O5HjN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113256-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113256-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4E51A1C22CFA for ; Sun, 24 Mar 2024 23:55:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C072C187E8E; Sun, 24 Mar 2024 22:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I37O5HjN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DED5E187E6D; Sun, 24 Mar 2024 22:40:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320056; cv=none; b=cs7NK6rbOEJ8RBq6hQjGIQMIMWd3jfl1HTZH0bdt2BRido9PZCiuyHdkEjyYuigLwurmE7cAqcMW/THZcObFJN8dyAYuUp0CI5Rjb5GnmalrM/6QKw7X/mUIzxXn/iC9gn72RalsN5gnc/dtfk1LYDo5JFx23tEoPAMRpW12ZDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320056; c=relaxed/simple; bh=0nT6+dnLat5eW46YYuat1egqogoXhgAReEx7/an+0Fs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GsELGmXW5My+29kC0igKiG4LoieDZfb5AmeE1+rT6KVJ4ZFo/35ze5gtT0ykydZO8imcR6C8ELuXp1cOSqegbgusl7Zq5fzaNjUe5VScRc/FZhcPY+O3BhnbXiBSgQaHonHLfH0Aoc34pP1/3vVsIp2CpNVOFmW2iTA92Lc4S/s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I37O5HjN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C437C433F1; Sun, 24 Mar 2024 22:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320055; bh=0nT6+dnLat5eW46YYuat1egqogoXhgAReEx7/an+0Fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I37O5HjNSeBQCM6xRflx/AMKd3ey5UzG5frdF1nhAVmOqzl6BxyrKMTEMnuJ4dfPG fSk2C6su7Z5FLEwIN/g/vbB6cPLTi97EAqb2JbvaVHX2H90fK3caqxGFXTqoImJ/+U iNieJKMCiGUql7TXxAOL15lNoVyWsKVT4cXQKilL9pdI4DOexqVwEam9w8+Vp88X+l I7WGR+8lVnSH25/r4r10ZZPYY6+psuJb5s+b7ZGYYqTHDd9iNKrhTX49m5IH7x8dV+ nH4YdhrpGlxhrdH+TJiTB92EFeKDvYt9rUbM1rE6viDlonhzEeVwr0vEwR3tGRzkEO YJ5G0ZFmYsCLQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Qiang Yu , Sasha Levin Subject: [PATCH 6.8 365/715] drm/lima: fix a memleak in lima_heap_alloc Date: Sun, 24 Mar 2024 18:29:04 -0400 Message-ID: <20240324223455.1342824-366-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Zhipeng Lu [ Upstream commit 04ae3eb470e52a3c41babe85ff8cee195e4dcbea ] When lima_vm_map_bo fails, the resources need to be deallocated, or there will be memleaks. Fixes: 6aebc51d7aef ("drm/lima: support heap buffer creation") Signed-off-by: Zhipeng Lu Signed-off-by: Qiang Yu Link: https://patchwork.freedesktop.org/patch/msgid/20240117071328.3811480-1-alexious@zju.edu.cn Signed-off-by: Sasha Levin --- drivers/gpu/drm/lima/lima_gem.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c index 4f9736e5f929b..7ea244d876ca6 100644 --- a/drivers/gpu/drm/lima/lima_gem.c +++ b/drivers/gpu/drm/lima/lima_gem.c @@ -75,29 +75,34 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm) } else { bo->base.sgt = kmalloc(sizeof(*bo->base.sgt), GFP_KERNEL); if (!bo->base.sgt) { - sg_free_table(&sgt); - return -ENOMEM; + ret = -ENOMEM; + goto err_out0; } } ret = dma_map_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0); - if (ret) { - sg_free_table(&sgt); - kfree(bo->base.sgt); - bo->base.sgt = NULL; - return ret; - } + if (ret) + goto err_out1; *bo->base.sgt = sgt; if (vm) { ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT); if (ret) - return ret; + goto err_out2; } bo->heap_size = new_size; return 0; + +err_out2: + dma_unmap_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0); +err_out1: + kfree(bo->base.sgt); + bo->base.sgt = NULL; +err_out0: + sg_free_table(&sgt); + return ret; } int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file, -- 2.43.0