Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp353954rdb; Wed, 17 Jan 2024 04:14:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwrWFD/7uy++Vd+muStbR7Ad/9WAzoy3d5XEjN7aYfOR9Xi3CvlPLy4hY4Iy7GkLxr7Ez6 X-Received: by 2002:ac8:5942:0:b0:42a:1047:1a73 with SMTP id 2-20020ac85942000000b0042a10471a73mr724370qtz.45.1705493679410; Wed, 17 Jan 2024 04:14:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705493679; cv=pass; d=google.com; s=arc-20160816; b=zDnHVOUN7HXScJevDpQId/JQ8c+YLijTZqMocGtECPJtq9/hpCBNs59ZbRP9yGo9+8 TQ1t2xYCWtskCPl+l7llPjP5WKvQelXjxD/BZI75M+PYBpYmaABL0IlRpBNh3T3olSsX 7PgZd/LUYnu74MgrIRCPJ9gOtJ+mvFa8Et01kYPyqcaNPbHVb/+f2CHEZWpNg06aBPEd cBY/jfUuVHgztZq8R5RMsELidG+zp39dzcTCK+hWbDz5tF+8+7yV/GJLdNQ39J22bt1V 9yqstBLs8WZ2m2aRIyIzY/c1gq16YeRtjOnTvd/kNWxlsX3tQ3nXf2cGJ5XVYInSdZ7D VcOw== ARC-Message-Signature: i=2; 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=S3cnt7gyC+lpqdMXbg30DVvgkbh9UK/R9kQWe9GwuLk=; fh=ZFbNb17AUKIQzPCxxQzJtDHyqAdZC7r2IdItbOt1Ddg=; b=Bhxiuh6HbifHGey4XmNXy+VKViNL8q63YPwN8/yBCi4W5CN3VTjJ/Ph1CKpcmQPWSv 7MvVteDOH+IOXair08x9WnZG+yJW9rkFZhvf7uhw3SXc46XzJ91k+Y8BwyOOGh0SlFh3 78yGLREumqhkpGX+V3gwmn9clGcWMcNTu/NOCCVBxbJzbGJh0bCaOX/Tlmc2zXKtx84E OUK6En4qOlAEDGWowW/kT4r72Wc91yJ1d34HOey5FDze9OkESN1byiG98Z5Ewvzmw6jl bgOZxOT3DvNkf5gpetKybCIX/mQHHwrxn7wJ7xGQlL5QxMnuGDz8zzBGN+qWqihf1PR8 +Zvw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cnYWH0QE; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-28947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28947-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. [147.75.199.223]) by mx.google.com with ESMTPS id p9-20020a05622a048900b00429899c2e0bsi11403338qtx.642.2024.01.17.04.14.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 04:14:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cnYWH0QE; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-28947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28947-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 2DB071C2161C for ; Wed, 17 Jan 2024 12:14:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE6B21DFE4; Wed, 17 Jan 2024 12:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cnYWH0QE" Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 4AB1B1DFC7 for ; Wed, 17 Jan 2024 12:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705493666; cv=none; b=NjY7En/vLve/3tF64ucfCTROYdgxNHqBf0Uq9ZmuQBGEwYRJDl4QT/g1l/mJHfVu00J/PJk8ktyvpAPqIRNQM6197bYs/PgWS2fAHdSPAiPGau0Ljsp/FW1fZgPhJwXb+dZnDqsqXqShaO+gcL/pLGiIStEB7lSRb4+M1Kb1R5k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705493666; c=relaxed/simple; bh=9hVK2zsyhbMNgnba9kHodPE2CXCC6M2YOk6Fqce5lfg=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version: References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc: Content-Type:Content-Transfer-Encoding; b=OgnYVsO0xXMY8eSHi+o6EMEFZSQQHnZDLYQturnB47E9M/x4CyS9r2D7+Dxpol/t6s9X0thfYupZWLHSVgf/4unfNihs3sFWx1FircOSuKIfx8o3d91QkL+Pucv5OY0gOK9fxtWwEKrMo7pZocPrf1+cfvG7vmc7AX4ZV9pFAT4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cnYWH0QE; arc=none smtp.client-ip=209.85.167.48 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-lf1-f48.google.com with SMTP id 2adb3069b0e04-50ec948ad31so10985677e87.2 for ; Wed, 17 Jan 2024 04:14:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705493661; x=1706098461; 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=S3cnt7gyC+lpqdMXbg30DVvgkbh9UK/R9kQWe9GwuLk=; b=cnYWH0QEUgdlZrEZwIS+pmOhyRnj05cta0+x1W/69HKy0B0VWFKyk7Gjd8XuzUDtnq gn8pbkVblLrgPN95ajW1fFG+wA7S7ijF5xSVR/Ob0+efzaD5A7YlYmDm0wOFwY31QHgk opyZ7DPeK09q2C2OaAmrLuywinY/fetfW8a0pAqjOt9FTNrM1gA+O2HZz5lt2+j1Cber h9GMPekEpkySmAlxL/ddJYtdD75qky5Uxoou7h/W2D19paAmenmGvZ9l8Dr4MEWojG/m Mup3w/P50wqifsWnuginuOUEzWEW47o2GSrTUE/nxrbpOQcnnsjzn4RBdwjhGc8mZrPA HU4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705493661; x=1706098461; 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=S3cnt7gyC+lpqdMXbg30DVvgkbh9UK/R9kQWe9GwuLk=; b=P3Tjs5tCGFK7fYU+8EFuGWlY3hz89zNu3Ak9hli66TQo2rKHw0FkfzMM+xQMwyfYJO frRVlPMks9q92D2IgGyWpX5TQ/BFx2wRmVGzRF9piDQRv+P8V4XI1ycRXCutPWNfYiFr JgKddbnRVkBmoQGVpr7qDhrbgloYByUX4tR+O0swDCWoLn6fQhE1V9RAoLuzkZo2zKaT XXRFjQg0RXMUBksmPO59Xg0D6MocH6c+bD/Jq8Gd04xmgibk/z1FbxrrKP9VEnzPchg1 +YLY9uYNFMpr2TijmI1lFBjuSTI55iAw44CZ1xeDAzcDZ3kSSAslmY5QfSfqTohpCZay hVFA== X-Gm-Message-State: AOJu0YwZ6ZyeQQAPYMT0I1g9RXiphk1r0yLOUTU3mhlVEJWnVyVlFriq Jezor1DZjk3djfkUoKs+uFSG0zN0adVqeyd808I= X-Received: by 2002:a05:6512:2201:b0:50e:53bc:3f9b with SMTP id h1-20020a056512220100b0050e53bc3f9bmr5144540lfu.113.1705493661288; Wed, 17 Jan 2024 04:14:21 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240117071328.3811480-1-alexious@zju.edu.cn> In-Reply-To: <20240117071328.3811480-1-alexious@zju.edu.cn> From: Qiang Yu Date: Wed, 17 Jan 2024 20:14:08 +0800 Message-ID: Subject: Re: [PATCH] [v2] 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 Reviewed-by: Qiang Yu On Wed, Jan 17, 2024 at 3:14=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 > --- > Changelog: > > v2: rearrange the error-handling to ladder tags. > --- > drivers/gpu/drm/lima/lima_gem.c | 23 +++++++++++++++-------- > 1 file changed, 15 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_= gem.c > index 4f9736e5f929..d3d82ee7fb4c 100644 > --- a/drivers/gpu/drm/lima/lima_gem.c > +++ b/drivers/gpu/drm/lima/lima_gem.c > @@ -75,29 +75,36 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_v= m *vm) > } else { > bo->base.sgt =3D kmalloc(sizeof(*bo->base.sgt), GFP_KERNE= L); > if (!bo->base.sgt) { > - sg_free_table(&sgt); > - return -ENOMEM; > + ret =3D -ENOMEM; > + goto err_out0; > } > } > > ret =3D dma_map_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0); > if (ret) { > - sg_free_table(&sgt); > - kfree(bo->base.sgt); > - bo->base.sgt =3D NULL; > - return ret; > + goto err_out1; > } > > *bo->base.sgt =3D sgt; > > if (vm) { > ret =3D lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT); > - if (ret) > - return ret; > + if (ret) { > + goto err_out2; > + } > } > > bo->heap_size =3D new_size; > return 0; > + > +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; > } > > int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file= , > -- > 2.34.1 >