Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2536781lqp; Mon, 25 Mar 2024 01:36:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9Rd/fy2k7vrkOnC3tzYtSn2eC073qRJnlWz7K4nYTSbvJ4eegCesiC9CmMCTiDEWCRi4bOfJ+A5kNL9fxaJTJAt3RRk1P26zVng38XQ== X-Google-Smtp-Source: AGHT+IFxY3IDBSD6g0Bv5Vym8CjLuPU2zXnRKD4f69g2Z9vA5YFIIgdxSHI+4Kcz69f52wyE3yYu X-Received: by 2002:a17:906:2688:b0:a46:8c40:7a3a with SMTP id t8-20020a170906268800b00a468c407a3amr4182820ejc.26.1711355765699; Mon, 25 Mar 2024 01:36:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711355765; cv=pass; d=google.com; s=arc-20160816; b=D7O4OhhD3o9V8r2cF0rQDnR2P2LtqEWj5faS6wjH1tPRPJ6CaE9BaT0+QnGJxyHszU EdObxs3RvXA+Ruifj0NXav7AIgl3cDoI4/0T4M6DtKNXesZp+MDAZwkX2ulI2Fs2qA6B zjGY6pEHBQ2h05Ax3CEumriDi2zlksQCVPGl+6n4/p9lO1yAjLTv13qVRS8ZlTR0Ggcu 9MpRTDratspkcF/5et+LsePO8wWzZT8zSdTKdsqqtnKXnbldu9zuTVL13YLehtg3eNRO F+DODc8wreX8jP33ORwZdFbaqezjAl87VH2JT04ksBHzA5tZUxcpsXNhvFQYyn1p4sIU /ltA== 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=gOxPTRTGQSquCmQuR6arJyP6Xd+QrfJSB2G5zehU2yI=; fh=jlHTww3USfPCOjIS4Y94SiVVd38kkecD7jGDMCIKLF8=; b=A5op1CTVxdXByz2kwgXmzDJWGp3FGoI1s56BlbuMG5iU1i9V80wykAVHtpaXB2b4Wv +WjBgYhxGkUceGUS2kQJTbvpsoPVfjkB/xO291dshoWEL7JpIAZJ/Vo24HalidHMs66F 2CbcUEMcEzktNLLlExNQKnLEeG3NA8oNL5zXbuKq4w614tDqW4gCotpTuWuhE6jdlUwW ksylX64MhGQgcONKN53DE6TNonkLsi9IOY+jWU3ZsqL8GUBPZQrrgkcdRXxEH3NmR/j7 M5gez/eKoivFjYUM8uEd8kcKVsFjCtHLVgUvHe0t88GKrL97B24EdYMayKhBceeeDBcO 99hQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PHKc8EZX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116169-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116169-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hh10-20020a170906a94a00b00a474f677083si1348110ejb.80.2024.03.25.01.36.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 01:36:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116169-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PHKc8EZX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116169-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116169-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 am.mirrors.kernel.org (Postfix) with ESMTPS id EC4681F315F6 for ; Mon, 25 Mar 2024 08:35:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EA3B3B5A2E; Mon, 25 Mar 2024 03:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PHKc8EZX" 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 89AE317BB05; Sun, 24 Mar 2024 23:42:27 +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=1711323748; cv=none; b=tmFXnzEbL6/byinKKBJFOc0pPAnPwULSmrwwzMxpJ811hiliWCu7lRwg9I5gx2VqHsz+9tOdSYrz0JcZWvxwIC3K58R+4QOiTKVXdRVjkHQSldYQ1h5NgDuS6OS6tmgtziXnMLihR8IpdO/q8HslgE+Pd4hMPFOTDxJrE//XFJc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711323748; c=relaxed/simple; bh=yR9eDH5FyneCFiaeoSi342C8aJUPm3XBozGPnp/Dtx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S9WjffmMXeKLbnX6Oz+eaqXCh7KfDENv9SLLPxyEekjn4Y6bceAj8V4o7PBxQu1q7Aa6BC8NO3CAuO4dsVnuc073zfqHmxLYka6q8xi8JYqaoT+7gy9gUCqQragSkBKqQJttmWnsd+U4IfqxoK3+dN7egYeDWNhkQmTd/r76sXc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PHKc8EZX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD3E7C433C7; Sun, 24 Mar 2024 23:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711323747; bh=yR9eDH5FyneCFiaeoSi342C8aJUPm3XBozGPnp/Dtx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PHKc8EZXSlyw2rSRHu1sE2I9wYtAD0fovPuOvGfANgAcLraHq7TxtYrQzjLLtQhz5 SXjBXeH2AMwNXtuCuCW8i/5JH2KyYnBq5Q3pSSSSNxryCgDD/+V8htwJjHJItSC60l isQbnZuzo8che1bVTuW2CwWxGWzDsEuGVS65g7xMORQiMr2rudumL4AMtBnvC1mFYl AvIKJX1I5rD6ay5j1iMhmU4nOhwJVJymScbwcA4GFfvoKjnBBIm6dxPmIchJ6mwrBr sNqBEqTpuRAMN8BQX9jPKuTEjaQsk+h6lslNaMD14QHioxwLmGiGa3o/6xrjY91IMW hJtopKQdLw/Bg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Qiang Yu , Sasha Levin Subject: [PATCH 5.10 122/238] drm/lima: fix a memleak in lima_heap_alloc Date: Sun, 24 Mar 2024 19:38:30 -0400 Message-ID: <20240324234027.1354210-123-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324234027.1354210-1-sashal@kernel.org> References: <20240324234027.1354210-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 11223fe348dfe..894175f2ed492 100644 --- a/drivers/gpu/drm/lima/lima_gem.c +++ b/drivers/gpu/drm/lima/lima_gem.c @@ -74,29 +74,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