Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp188657rdb; Mon, 15 Jan 2024 17:54:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjhQ1VG+um5P1OL0CstxlnTG2eM6WxjzZa9c6M0TBPFfPp1tu2PnrWVDic/5A6aSIKA1WF X-Received: by 2002:a05:6214:2481:b0:681:7da:4a6a with SMTP id gi1-20020a056214248100b0068107da4a6amr8226565qvb.7.1705370053878; Mon, 15 Jan 2024 17:54:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705370053; cv=none; d=google.com; s=arc-20160816; b=phupRKHfYpF7gZ8lYT8mC/hW/5VjLltpD4HjRpgn4G5DXUlog2jDgDcpWt8PyQL2WO XFLiXrTZVq92/MJVUMduiBqR2BHV2hho1AK1xC0/VgebPxSiWiwe59DMfbCwNbWvrIxv xiB1pf7sfUR52OFex1T37px4tcRoieBLplOHCqSJEVLOeziVu91x0xW5fkqanqHOkGn4 97V4q920ZMpGNk6yuMSDYYyuZrL7EoiiDiRinnNzAUoMhW5zXk52yWf0oHa3kboqz/xo rP+dhuPnva9MAsZSQJiggDN3rVEauI+aldwZ/rSeXMEuJs3u87/bppOZCh3UPtQCz48/ AGKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=NW8IeT94sqxk9dJoctrT0QMHmgttzl2Wny6AX+IZ+rw=; fh=ZFbNb17AUKIQzPCxxQzJtDHyqAdZC7r2IdItbOt1Ddg=; b=ByRWebrQcmE0bmLCz8Z+1D9tm3wG2aFhvZUdB6Ab2uZzgU+YCsje60DfPQ5/Klg3vY aVTmAvGYwSXzVzniLS2gxSqjiE7NC9ggvUmw5WHYQ5vNfKwqv1jw8o9HqEy79q7cEUjc 4v+23Lf8su8sTBQSXqkEMB+nK1zzsB+DQmyA8KxfKbbKUiu7gEAZC7sjf5/EpanzYsbf GlAn1xH88UgfjMWrA2dEZGimwRSgfnxRa6sX4VOhvyPeQyHc17PN1Z2yPN5iaLONhaxg 7IhBGm05Yu4e8dWNqsn8yD0Yw6MnyWO5wmyP9dGguh2CQ+eQ8K7ud3m9NWuoYS2LrlX0 sLZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="LJ1/Ogje"; spf=pass (google.com: domain of linux-kernel+bounces-26906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f6-20020ac85d06000000b00429bc1c4a65si9556582qtx.629.2024.01.15.17.54.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 17:54:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26906-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=@gmail.com header.s=20230601 header.b="LJ1/Ogje"; spf=pass (google.com: domain of linux-kernel+bounces-26906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 92BA41C22CE1 for ; Tue, 16 Jan 2024 01:54:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F11A779F9; Tue, 16 Jan 2024 01:24:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LJ1/Ogje" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52F5379C0 for ; Tue, 16 Jan 2024 01:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a28ab7ae504so883200066b.3 for ; Mon, 15 Jan 2024 17:24:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705368292; x=1705973092; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NW8IeT94sqxk9dJoctrT0QMHmgttzl2Wny6AX+IZ+rw=; b=LJ1/OgjeHUsnuudCGG9EbzhhbSP5dlROs9gcnVeAfBPiAJsUI+L1PwqPz5UwcfjyH9 pQzBs9C/eLOKLycVIyFtGS1WgwgkprdgicwHIIdpXjnV/wBQtFB+ZRDcFNHyUKBA/FRG 3sRps7LB3bZzLagUW9ITkyL50SErX9nUaRQ3KBpGDlHzWo/YZgoKUvo1/5D1KdOe/OmA BVjfK95qHHettH+KrNHeokHpyE1Tvu+BmPDFwhywlv+lxG4aGc4EDIy2gGPU6HCUrbqV ENt5eJpkgVdntQuREH4L7Nor4GpD4Br6M/pC9C/KfeD4WQPG6npKrfso58oiHa7+OBun jnfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705368292; x=1705973092; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NW8IeT94sqxk9dJoctrT0QMHmgttzl2Wny6AX+IZ+rw=; b=Sr/a3TH+Rn75S8Xwy4OglGZpUqka9WviDHcY8sooMoGlrftITFdWy+JVNGukAcA0dK OfK1LqRyj8BJZtnFNUit8eiCgWkReG/unzffQhVvozJIaQrkUdsPBzrR4JWQ0CaDZtUV vL10/79yBnO2Qm9uLqUPPFon+wLKxMbKN9UFGiTO6X9OVlT/JFWKp2BcsoDjoDtNddRI iL1D62gomJy6wk9P+Bqi+yrJbdntcsXxRN+K07jZyagemFhIMm0qZQpJanP2RRlpSUIW 6BpYq8PnEYZzWYD8sTvzQfx3nrm4FeQjiwZM/Zk/Q4ycQgWUQQMpkm681igUpaLqfNBK 3Mvg== X-Gm-Message-State: AOJu0Ywj16jK9BDi9enszML17TyMT5hqHlxcwwpBswrRUhmfW/ahOQXA 41zd4F7n4iA3JvoBk8qpKh0CK1VnnH5ODx203mU= X-Received: by 2002:a17:906:c058:b0:a27:b278:b3e with SMTP id bm24-20020a170906c05800b00a27b2780b3emr2593812ejb.83.1705368292224; Mon, 15 Jan 2024 17:24:52 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240112084750.3729837-1-alexious@zju.edu.cn> In-Reply-To: <20240112084750.3729837-1-alexious@zju.edu.cn> From: Qiang Yu Date: Tue, 16 Jan 2024 09:24:37 +0800 Message-ID: Subject: Re: [PATCH] drm/lima: fix a memleak in lima_heap_alloc To: Zhipeng Lu Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Vasily Khoruzhick , dri-devel@lists.freedesktop.org, lima@lists.freedesktop.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the fix. As the error handling gets longer and duplicated, could you rearrange them like the lima_gem_submit(): err_out2: dma_unmap_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0); err_out1: kfree(bo->base.sgt); bo->base.sgt =3D NULL; err_out0: sg_free_table(&sgt); return ret. Regards, Qiang On Fri, Jan 12, 2024 at 4:49=E2=80=AFPM Zhipeng Lu wr= ote: > > 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 > --- > drivers/gpu/drm/lima/lima_gem.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_= gem.c > index 4f9736e5f929..824ed22141c7 100644 > --- a/drivers/gpu/drm/lima/lima_gem.c > +++ b/drivers/gpu/drm/lima/lima_gem.c > @@ -92,8 +92,13 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_vm= *vm) > > if (vm) { > ret =3D lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT); > - if (ret) > + if (ret) { > + dma_unmap_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0= ); > + sg_free_table(&sgt); > + kfree(bo->base.sgt); > + bo->base.sgt =3D NULL; > return ret; > + } > } > > bo->heap_size =3D new_size; > -- > 2.34.1 >