From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam01on0129.outbound.protection.outlook.com ([104.47.32.129]:50720 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728397AbeIOGve (ORCPT ); Sat, 15 Sep 2018 02:51:34 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Arvind Yadav , MyungJoo Ham , Sasha Levin Subject: [PATCH AUTOSEL 4.9 06/34] PM / devfreq: use put_device() instead of kfree() Date: Sat, 15 Sep 2018 01:34:29 +0000 Message-ID: <20180915013422.180023-6-alexander.levin@microsoft.com> References: <20180915013422.180023-1-alexander.levin@microsoft.com> In-Reply-To: <20180915013422.180023-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: Arvind Yadav [ Upstream commit 2d803dc8f7a5f622ac47c3b650834ada3a2659b9 ] Never directly free @dev after calling device_register() or device_unregister(), even if device_register() returned an error. Always use put_device() to give up the reference initialized. Signed-off-by: Arvind Yadav Reviewed-by: Chanwoo Choi Signed-off-by: MyungJoo Ham Signed-off-by: Sasha Levin --- drivers/devfreq/devfreq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index db70cee71caa..07600af0084d 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -574,7 +574,8 @@ struct devfreq *devfreq_add_device(struct device *dev, err =3D device_register(&devfreq->dev); if (err) { mutex_unlock(&devfreq->lock); - goto err_dev; + put_device(&devfreq->dev); + goto err_out; } =20 devfreq->trans_table =3D devm_kzalloc(&devfreq->dev, sizeof(unsigned int)= * @@ -618,6 +619,7 @@ err_init: mutex_unlock(&devfreq_list_lock); =20 device_unregister(&devfreq->dev); + devfreq =3D NULL; err_dev: if (devfreq) kfree(devfreq); --=20 2.17.1