]> git.itanic.dy.fi Git - linux-stable/commitdiff
PM / devfreq: use put_device() instead of kfree()
authorArvind Yadav <arvind.yadav.cs@gmail.com>
Fri, 30 Mar 2018 11:44:03 +0000 (17:14 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Sep 2018 06:39:36 +0000 (08:39 +0200)
[ 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 <arvind.yadav.cs@gmail.com>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/devfreq/devfreq.c

index 0b5b3abe054e6427f779beca3098a8d37d15cee3..e26adf67e218d6d4e7a6a31cc86da55ea5ad4ebc 100644 (file)
@@ -625,7 +625,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
        err = device_register(&devfreq->dev);
        if (err) {
                mutex_unlock(&devfreq->lock);
-               goto err_dev;
+               put_device(&devfreq->dev);
+               goto err_out;
        }
 
        devfreq->trans_table =
@@ -672,6 +673,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
        mutex_unlock(&devfreq_list_lock);
 
        device_unregister(&devfreq->dev);
+       devfreq = NULL;
 err_dev:
        if (devfreq)
                kfree(devfreq);