From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-eopbgr700137.outbound.protection.outlook.com ([40.107.70.137]:63424 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728462AbeIOGrt (ORCPT ); Sat, 15 Sep 2018 02:47:49 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Lyude Paul , Ben Skeggs , Sasha Levin Subject: [PATCH AUTOSEL 4.18 41/92] drm/nouveau: Fix runtime PM leak in drm_open() Date: Sat, 15 Sep 2018 01:30:18 +0000 Message-ID: <20180915012944.179481-41-alexander.levin@microsoft.com> References: <20180915012944.179481-1-alexander.levin@microsoft.com> In-Reply-To: <20180915012944.179481-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Lyude Paul [ Upstream commit 922a8c82fafdec99688bbaea6c5889f562a42cdc ] Noticed this as I was skimming through, if we fail to allocate memory for cli we'll end up returning without dropping the runtime PM ref we got. Additionally, we'll even return the wrong return code! (ret most likely will =3D=3D 0 here, we want -ENOMEM). Signed-off-by: Lyude Paul Reviewed-by: Lukas Wunner Signed-off-by: Ben Skeggs Signed-off-by: Sasha Levin --- drivers/gpu/drm/nouveau/nouveau_drm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouvea= u/nouveau_drm.c index f5d3158f0378..c7ec86d6c3c9 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -908,8 +908,10 @@ nouveau_drm_open(struct drm_device *dev, struct drm_fi= le *fpriv) get_task_comm(tmpname, current); snprintf(name, sizeof(name), "%s[%d]", tmpname, pid_nr(fpriv->pid)); =20 - if (!(cli =3D kzalloc(sizeof(*cli), GFP_KERNEL))) - return ret; + if (!(cli =3D kzalloc(sizeof(*cli), GFP_KERNEL))) { + ret =3D -ENOMEM; + goto done; + } =20 ret =3D nouveau_cli_init(drm, name, cli); if (ret) --=20 2.17.1