diff mbox

[PATCHv2] Thermal: Fix synchronization issues in thermal_sys.c

Message ID 1348727888-11196-1-git-send-email-durgadoss.r@intel.com (mailing list archive)
State Accepted
Delegated to: Zhang Rui
Headers show

Commit Message

durgadoss.r@intel.com Sept. 27, 2012, 6:38 a.m. UTC
This patch fixes the following mutex and NULL pointer
problems in thermal_sys.c:
 * mutex_unlock fix in update_temperature function
 * mutex_unlock fix in bind_cdev function
 * NULL check fix in bind_tz function

Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
Reported-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
---
v2:
 * Removed unnecessary NULL check in bind_cdev
 * Added 'Reported-by' tags for Sedat and Hugh
 drivers/thermal/thermal_sys.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Sedat Dilek Sept. 27, 2012, 12:38 p.m. UTC | #1
On Thu, Sep 27, 2012 at 10:01 AM, Sedat Dilek <sedat.dilek@gmail.com> wrote:
> On Thu, Sep 27, 2012 at 8:38 AM, Durgadoss R <durgadoss.r@intel.com> wrote:
>> This patch fixes the following mutex and NULL pointer
>> problems in thermal_sys.c:
>>  * mutex_unlock fix in update_temperature function
>>  * mutex_unlock fix in bind_cdev function
>>  * NULL check fix in bind_tz function
>>
>> Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
>> Reported-by: Hugh Dickins <hughd@google.com>
>> Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
>> ---
>> v2:
>>  * Removed unnecessary NULL check in bind_cdev
>>  * Added 'Reported-by' tags for Sedat and Hugh
>>  drivers/thermal/thermal_sys.c |    7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
>> index 4f77d89..e1179d3 100644
>> --- a/drivers/thermal/thermal_sys.c
>> +++ b/drivers/thermal/thermal_sys.c
>> @@ -253,7 +253,7 @@ static void bind_cdev(struct thermal_cooling_device *cdev)
>>
>>                 tzp = pos->tzp;
>>                 if (!tzp->tbp)
>> -                       return;
>> +                       continue;
>>
>>                 for (i = 0; i < tzp->num_tbps; i++) {
>>                         if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
>> @@ -289,7 +289,7 @@ static void bind_tz(struct thermal_zone_device *tz)
>>                 goto exit;
>>         }
>>
>> -       if (!tzp->tbp)
>> +       if (!tzp || !tzp->tbp)
>>                 goto exit;
>>
>>         list_for_each_entry(pos, &thermal_cdev_list, node) {
>> @@ -390,12 +390,13 @@ static void update_temperature(struct thermal_zone_device *tz)
>>         ret = tz->ops->get_temp(tz, &temp);
>>         if (ret) {
>>                 pr_warn("failed to read out thermal zone %d\n", tz->id);
>> -               return;
>> +               goto exit;
>>         }
>>
>>         tz->last_temperature = tz->temperature;
>>         tz->temperature = temp;
>>
>> +exit:
>>         mutex_unlock(&tz->lock);
>>  }
>>
>> --
>> 1.7.9.5
>>
>
> The v2 patch does *not* fix the issue here!
>
> [1] https://patchwork.kernel.org/patch/1511961/
>

I have re-tested with Linux-Next (next-20120927) plus thermal-next [1]
pulled in and see still the same call-trace!

Hugh or Dan can you confirm this works for you or not?
Thanks in advance.

[1] http://git.kernel.org/?p=linux/kernel/git/rzhang/linux.git;a=shortlog;h=refs/heads/next
[2] http://git.kernel.org/?p=linux/kernel/git/rzhang/linux.git;a=commitdiff;h=404b134156bd9d9bc506c0974a1254806e13db2c

>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-next" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sedat Dilek Sept. 27, 2012, 2:05 p.m. UTC | #2
On Thu, Sep 27, 2012 at 2:38 PM, Sedat Dilek <sedat.dilek@gmail.com> wrote:
> On Thu, Sep 27, 2012 at 10:01 AM, Sedat Dilek <sedat.dilek@gmail.com> wrote:
>> On Thu, Sep 27, 2012 at 8:38 AM, Durgadoss R <durgadoss.r@intel.com> wrote:
>>> This patch fixes the following mutex and NULL pointer
>>> problems in thermal_sys.c:
>>>  * mutex_unlock fix in update_temperature function
>>>  * mutex_unlock fix in bind_cdev function
>>>  * NULL check fix in bind_tz function
>>>
>>> Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
>>> Reported-by: Hugh Dickins <hughd@google.com>
>>> Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
>>> ---
>>> v2:
>>>  * Removed unnecessary NULL check in bind_cdev
>>>  * Added 'Reported-by' tags for Sedat and Hugh
>>>  drivers/thermal/thermal_sys.c |    7 ++++---
>>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
>>> index 4f77d89..e1179d3 100644
>>> --- a/drivers/thermal/thermal_sys.c
>>> +++ b/drivers/thermal/thermal_sys.c
>>> @@ -253,7 +253,7 @@ static void bind_cdev(struct thermal_cooling_device *cdev)
>>>
>>>                 tzp = pos->tzp;
>>>                 if (!tzp->tbp)
>>> -                       return;
>>> +                       continue;
>>>
>>>                 for (i = 0; i < tzp->num_tbps; i++) {
>>>                         if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
>>> @@ -289,7 +289,7 @@ static void bind_tz(struct thermal_zone_device *tz)
>>>                 goto exit;
>>>         }
>>>
>>> -       if (!tzp->tbp)
>>> +       if (!tzp || !tzp->tbp)
>>>                 goto exit;
>>>
>>>         list_for_each_entry(pos, &thermal_cdev_list, node) {
>>> @@ -390,12 +390,13 @@ static void update_temperature(struct thermal_zone_device *tz)
>>>         ret = tz->ops->get_temp(tz, &temp);
>>>         if (ret) {
>>>                 pr_warn("failed to read out thermal zone %d\n", tz->id);
>>> -               return;
>>> +               goto exit;
>>>         }
>>>
>>>         tz->last_temperature = tz->temperature;
>>>         tz->temperature = temp;
>>>
>>> +exit:
>>>         mutex_unlock(&tz->lock);
>>>  }
>>>
>>> --
>>> 1.7.9.5
>>>
>>
>> The v2 patch does *not* fix the issue here!
>>
>> [1] https://patchwork.kernel.org/patch/1511961/
>>
>
> I have re-tested with Linux-Next (next-20120927) plus thermal-next [1]
> pulled in and see still the same call-trace!
>
> Hugh or Dan can you confirm this works for you or not?
> Thanks in advance.
>
> [1] http://git.kernel.org/?p=linux/kernel/git/rzhang/linux.git;a=shortlog;h=refs/heads/next
> [2] http://git.kernel.org/?p=linux/kernel/git/rzhang/linux.git;a=commitdiff;h=404b134156bd9d9bc506c0974a1254806e13db2c
>

With the attached fixup/followup patch, I can boot into my system!
But, as said yesterday... working within X, Firefox is a pain in the a**.

- Sedat -

>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-next" 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/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 4f77d89..e1179d3 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -253,7 +253,7 @@  static void bind_cdev(struct thermal_cooling_device *cdev)
 
 		tzp = pos->tzp;
 		if (!tzp->tbp)
-			return;
+			continue;
 
 		for (i = 0; i < tzp->num_tbps; i++) {
 			if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
@@ -289,7 +289,7 @@  static void bind_tz(struct thermal_zone_device *tz)
 		goto exit;
 	}
 
-	if (!tzp->tbp)
+	if (!tzp || !tzp->tbp)
 		goto exit;
 
 	list_for_each_entry(pos, &thermal_cdev_list, node) {
@@ -390,12 +390,13 @@  static void update_temperature(struct thermal_zone_device *tz)
 	ret = tz->ops->get_temp(tz, &temp);
 	if (ret) {
 		pr_warn("failed to read out thermal zone %d\n", tz->id);
-		return;
+		goto exit;
 	}
 
 	tz->last_temperature = tz->temperature;
 	tz->temperature = temp;
 
+exit:
 	mutex_unlock(&tz->lock);
 }