diff mbox

[v2] PM / devfreq: Add proper locking around list_del()

Message ID 1475115208-6817-1-git-send-email-axel.lin@ingics.com (mailing list archive)
State Accepted, archived
Delegated to: Rafael Wysocki
Headers show

Commit Message

Axel Lin Sept. 29, 2016, 2:13 a.m. UTC
Use devfreq_list_lock around list_del() to prevent list corruption.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
v2: changes base on MyungJoo's comment.
Note, devfreq_list_lock lock region does not to include device_unregister(&devfreq->dev);
 drivers/devfreq/devfreq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

MyungJoo Ham Sept. 30, 2016, 1:46 p.m. UTC | #1
On Thu, Sep 29, 2016 at 11:13 AM, Axel Lin <axel.lin@ingics.com> wrote:
> Use devfreq_list_lock around list_del() to prevent list corruption.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

LGTM.

Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>

> ---
> v2: changes base on MyungJoo's comment.
> Note, devfreq_list_lock lock region does not to include device_unregister(&devfreq->dev);
>  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 478006b..66d3c718 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -594,17 +594,19 @@ struct devfreq *devfreq_add_device(struct device *dev,
>         if (devfreq->governor)
>                 err = devfreq->governor->event_handler(devfreq,
>                                         DEVFREQ_GOV_START, NULL);
> -       mutex_unlock(&devfreq_list_lock);
>         if (err) {
>                 dev_err(dev, "%s: Unable to start governor for the device\n",
>                         __func__);
>                 goto err_init;
>         }
> +       mutex_unlock(&devfreq_list_lock);
>
>         return devfreq;
>
>  err_init:
>         list_del(&devfreq->node);
> +       mutex_unlock(&devfreq_list_lock);
> +
>         device_unregister(&devfreq->dev);
>  err_out:
>         return ERR_PTR(err);
> --
> 2.7.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rafael J. Wysocki Oct. 12, 2016, 8:10 p.m. UTC | #2
On Friday, September 30, 2016 10:46:39 PM MyungJoo Ham wrote:
> On Thu, Sep 29, 2016 at 11:13 AM, Axel Lin <axel.lin@ingics.com> wrote:
> > Use devfreq_list_lock around list_del() to prevent list corruption.
> >
> > Signed-off-by: Axel Lin <axel.lin@ingics.com>
> 
> LGTM.
> 
> Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>

Applied.

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 478006b..66d3c718 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -594,17 +594,19 @@  struct devfreq *devfreq_add_device(struct device *dev,
 	if (devfreq->governor)
 		err = devfreq->governor->event_handler(devfreq,
 					DEVFREQ_GOV_START, NULL);
-	mutex_unlock(&devfreq_list_lock);
 	if (err) {
 		dev_err(dev, "%s: Unable to start governor for the device\n",
 			__func__);
 		goto err_init;
 	}
+	mutex_unlock(&devfreq_list_lock);
 
 	return devfreq;
 
 err_init:
 	list_del(&devfreq->node);
+	mutex_unlock(&devfreq_list_lock);
+
 	device_unregister(&devfreq->dev);
 err_out:
 	return ERR_PTR(err);