Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp738986rdb; Thu, 18 Jan 2024 18:47:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEovwBhn8BB1rLNAl87ghF80hXfS0fkl+eefWJZn3fG6i8p4/rVOc4DdC+z1LoS91g1nzjs X-Received: by 2002:a05:6830:3494:b0:6dd:e054:c2e6 with SMTP id c20-20020a056830349400b006dde054c2e6mr1908190otu.36.1705632465306; Thu, 18 Jan 2024 18:47:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705632465; cv=pass; d=google.com; s=arc-20160816; b=hLpQa/9axtrCCr+/meIpdgUp7SNi5hHf6S6scSgZSiYh4HYEnCrhvLbCR6tQrU/u1R iOh7Tt0l9YmlKOmZd3J7y/f+Rr25sNxzn1wn+mH/xSh+tgY4BFPMO9L4WvLEwHVIAZwn b08zqMYaFdAH9UIgpnpchfnZG3ocApAf22HTgDOfZ1mbWl8LToPdJupCyJwFiU8KbOvx yAZvYnN0dN4aMwTOiZ42XeeO+Go4dJm0Mf/kWPepkk/6oy7YWl6ZsTl+/BOG40m59Vvo SMcAL9cDTnLIGMrOX6KBwMz8gfGEOIYTHE1gpjDSIbJRyC3a1WNSTYs6CSUyR/gkeZw0 9Hhw== 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=sd3GlzgGgJSlvg/FmViDsptsjJQ9iDHdHhzYDbLHp3M=; fh=ZFbNb17AUKIQzPCxxQzJtDHyqAdZC7r2IdItbOt1Ddg=; b=Soe3sPH4RhiHPYaQ+LIONAn417TNYMGMLv7W5bo+CSdm0piKsV4/EJIAo1h20XlXtw 4k+wQEcvU8i/n7kln+ieATZsjenoDdlx6JQ2mTAssIZyFZ+1O+6MZZXmTHTacqLjPguM uLvw3iRGFv77p1YqCbATzDJWsrkq1vEw83muvwq1YjUe/Owt1lUOls6A5ly9aP9ad5wh ynNPQBaGqRoujkfwBb2TvLk8w8ZPoNOFCQY+ReFAmfAvGlgaDESpPbu3rNwTfIzhtfn3 CwCvfOV+cXjyWXXgvGiVmblmtMAcYhSZWbgdxG100H66vO/s0dVr+8KkFMtFl32FQQjX 5kag== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PrLk9fQH; 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-30715-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30715-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bx2-20020a056a02050200b005cd7c92f504si2528744pgb.481.2024.01.18.18.47.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 18:47:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30715-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PrLk9fQH; 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-30715-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30715-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E799A28658A for ; Fri, 19 Jan 2024 02:47:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA0DD17C8; Fri, 19 Jan 2024 02:47:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PrLk9fQH" Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 0D52A1111 for ; Fri, 19 Jan 2024 02:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705632457; cv=none; b=AHFIn/ooCagT8U1LZKjidSAKNqvlRZ4/8o6lV6sTbx4glcCQhU/xmoDricAZMvLUriN80AmKAgJAcoCldHkXZPOUCX3v6VsQPtfBUrcAfRPCcb7xoJFbjxHrwHUb6uHHqPG0gQtzwSuk5jfZY3H4Y7NzWkooRtVb1ShKSFEC9vA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705632457; c=relaxed/simple; bh=LC2ojcyVvYY18DsgCFhzHooTLnRNiqsKr5V2HXzBzPI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=CARNOODyU2cpGlpyjy6rkIBn0qJrKXnCaYyO71+JtMVtm3JvldP/o3rjixZ9gQem/MrY6M5ztT8k2eyW0uTXjOOfUYrRsG14WI/rQPlWl464qNtQ2YE0AdbFhyIUHScjIxO4/IDN82prt6rpCcUL16bYn50lK5CnQRLttXKmIlU= 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=PrLk9fQH; arc=none smtp.client-ip=209.85.208.175 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-lj1-f175.google.com with SMTP id 38308e7fff4ca-2cdc1af60b2so3635931fa.1 for ; Thu, 18 Jan 2024 18:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705632454; x=1706237254; 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=sd3GlzgGgJSlvg/FmViDsptsjJQ9iDHdHhzYDbLHp3M=; b=PrLk9fQHCXcECjgwfGJUmOL17zKZrUhDN5Y4XE0Px14Y2zlsacIoFoQBb1ANItn8yA N3EbOgbesx4pABUFpaEMlFZ9k0PDazn/qCmsdZSbbxNAn1cVKckirAAc2bl2mql/V0y0 EPz9qI6P4bOWcMpe6GPPudPzrPe49otXhHzsgtQMpjaBZfRmkFC+7xtjsY5Tc1zUv8x0 nDHTtoeXZp6UU5h2b4W7EZnuaFbYIqOBwx6V3ubANYS/gtFEvDgsyrRFW0XPXbx/8s7C sQqo+4VfgbaREMwLMsa43vDfv+Vg8jJHFtFOAxYGc7drjCUsUXh5+u2YqW2Y8Ylj3tdO xgYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705632454; x=1706237254; 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=sd3GlzgGgJSlvg/FmViDsptsjJQ9iDHdHhzYDbLHp3M=; b=uqtEun+nHkGQWyrxeZQRcYhJRdklCQoX9F7xLwfQydiT1jT4KcF3zp2qS1Yh+bLIJV Fw0QZC/8my08skrhIQaLJQmvqiIw5BO5Ewv+W4BDpaOTCIqjC0t5mP+rOFnx0BkPVLc4 maaf0qQWrKAtjqlFf4fdkQe9nbMKqU9LMPEM9gP806Yi+rKjptfB+cIRlcVHD5sFO1Ix TjlU2otUi2oDB7/Ng3K2T0trTL7AiCLqMB9q6PgT261KgXRQ1QuAw2uOwhogr/jZOKET gNN1JfcVbr2TgnWVPdR5tGarIcY4gxtE2We4LEvlh1EHkYUKjiAVrDOqaFQr4p3IsZmg Qojg== X-Gm-Message-State: AOJu0YxIXdBDJaiG3O2Auv8MN8PKu+CghWNlSC/74C5PaVKOMazpLJR/ 5wT8FmO0TsOoMmsxA+JLeeeBGF0eMWeCeibm6A+CcETsfdWQZTWPE0Y8dfTfIPXlJylNiiIoNAt ZEFVKdoq0ihyEf48kTABL1EICyOVswxVn6DzFsg== X-Received: by 2002:a2e:bc11:0:b0:2cc:ce6d:5ade with SMTP id b17-20020a2ebc11000000b002ccce6d5ademr1319357ljf.84.1705632453818; Thu, 18 Jan 2024 18:47:33 -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: From: Qiang Yu Date: Fri, 19 Jan 2024 10:47:21 +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 applied to drm-misc-next On Wed, Jan 17, 2024 at 8:14=E2=80=AFPM Qiang Yu wrote: > > Reviewed-by: Qiang Yu > > On Wed, Jan 17, 2024 at 3:14=E2=80=AFPM Zhipeng Lu = wrote: > > > > 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/lim= a_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= _vm *vm) > > } else { > > bo->base.sgt =3D kmalloc(sizeof(*bo->base.sgt), GFP_KER= NEL); > > 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 *fi= le, > > -- > > 2.34.1 > >