Skip to content

Commit 9e14de1

Browse files
chanwoochoimyungjoo
authored andcommitted
PM / devfreq: Fix memory leak when fail to register device
When the devfreq_add_device fails to register deivce, the memory leak of devfreq instance happen. So, this patch fix the memory leak issue. Before freeing the devfreq instance checks whether devfreq instance is NULL or not because the device_unregister() frees the devfreq instance when jumping to the 'err_init'. It is to prevent the duplicate the kfee(devfreq). Cc: [email protected] Fixes: ac4b281 ("PM / devfreq: fix duplicated kfree on devfreq pointer") Signed-off-by: Chanwoo Choi <[email protected]> Signed-off-by: MyungJoo Ham <[email protected]>
1 parent b9c69e0 commit 9e14de1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/devfreq/devfreq.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
564564
err = device_register(&devfreq->dev);
565565
if (err) {
566566
mutex_unlock(&devfreq->lock);
567-
goto err_out;
567+
goto err_dev;
568568
}
569569

570570
devfreq->trans_table = devm_kzalloc(&devfreq->dev,
@@ -610,6 +610,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
610610
mutex_unlock(&devfreq_list_lock);
611611

612612
device_unregister(&devfreq->dev);
613+
err_dev:
614+
if (devfreq)
615+
kfree(devfreq);
613616
err_out:
614617
return ERR_PTR(err);
615618
}

0 commit comments

Comments
 (0)