From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0134.outbound.protection.outlook.com ([104.47.33.134]:14354 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727994AbeIOGrD (ORCPT ); Sat, 15 Sep 2018 02:47:03 -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.18 15/92] PM / devfreq: use put_device() instead of kfree() Date: Sat, 15 Sep 2018 01:29:58 +0000 Message-ID: <20180915012944.179481-15-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: 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 0b5b3abe054e..e26adf67e218 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -625,7 +625,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 @@ -672,6 +673,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