[PATCH 1/6] PM / devfreq: Free devfreq upon set_freq_table error

From: Bjorn Andersson
Date: Tue Apr 24 2018 - 18:37:15 EST


When set_freq_table() fails we must still free the previously allocated
devfreq context, so jump to the correct label for this. Also when this
happens devfreq will always be non-NULL, so drop the unnecessary
conditional.

Also destroy the devfreq mutex as we're cleaning up the devfreq object.

Signed-off-by: Bjorn Andersson <bjorn.andersson@xxxxxxxxxx>
---
drivers/devfreq/devfreq.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 2067cd229ce3..30a672397ff0 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -597,7 +597,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
mutex_unlock(&devfreq->lock);
err = set_freq_table(devfreq);
if (err < 0)
- goto err_out;
+ goto err_dev;
mutex_lock(&devfreq->lock);
}

@@ -669,8 +669,8 @@ struct devfreq *devfreq_add_device(struct device *dev,

device_unregister(&devfreq->dev);
err_dev:
- if (devfreq)
- kfree(devfreq);
+ mutex_destroy(&devfreq->lock);
+ kfree(devfreq);
err_out:
return ERR_PTR(err);
}
--
2.16.2