2023-11-22 19:46:15

by Breno Leitao

[permalink] [raw]
Subject: Re: [PATCH v3] platform/x86: Add support for improved performance mode

On Mon, Nov 13, 2023 at 11:54:33AM -0500, Mark Pearson wrote:
> @@ -10355,6 +10361,17 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
> if (err)
> goto unlock;
>
> + /* Set TMS mode appropriately (enable for performance), if available */
> + if (dytc_ultraperf_cap) {
> + int cmd;
> +
> + cmd = DYTC_SET_COMMAND(DYTC_FUNCTION_TMS, DYTC_NOMODE,
> + profile == PLATFORM_PROFILE_PERFORMANCE);
> + err = dytc_command(cmd, &output);
> + if (err)
> + return err;

Aren't you returning holding the 'dytc_mutex' mutex?

From what I understand, in the first line of this function you get the lock,
and release later, at the exit, so, returning without releasing the lock might
be dangerous. Here is a summary of how I read this function with your change:


mutex_lock_interruptible(&dytc_mutex);
...
err = dytc_command(cmd, &output);
if (err)
return err;

unlock:
mutex_unlock(&dytc_mutex);
return err;


I think "goto unlock" might solve it.


2023-11-23 02:04:40

by Mark Pearson

[permalink] [raw]
Subject: Re: [PATCH v3] platform/x86: Add support for improved performance mode

Hi Breno,

Thanks for the review!

On Wed, Nov 22, 2023, at 2:44 PM, Breno Leitao wrote:
> On Mon, Nov 13, 2023 at 11:54:33AM -0500, Mark Pearson wrote:
>> @@ -10355,6 +10361,17 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
>> if (err)
>> goto unlock;
>>
>> + /* Set TMS mode appropriately (enable for performance), if available */
>> + if (dytc_ultraperf_cap) {
>> + int cmd;
>> +
>> + cmd = DYTC_SET_COMMAND(DYTC_FUNCTION_TMS, DYTC_NOMODE,
>> + profile == PLATFORM_PROFILE_PERFORMANCE);
>> + err = dytc_command(cmd, &output);
>> + if (err)
>> + return err;
>
> Aren't you returning holding the 'dytc_mutex' mutex?
>
> From what I understand, in the first line of this function you get the lock,
> and release later, at the exit, so, returning without releasing the lock might
> be dangerous. Here is a summary of how I read this function with your change:
>
>
> mutex_lock_interruptible(&dytc_mutex);
> ...
> err = dytc_command(cmd, &output);
> if (err)
> return err;
>
> unlock:
> mutex_unlock(&dytc_mutex);
> return err;
>
>
> I think "goto unlock" might solve it.

Yep - you're right. Good catch.
Will fix in the next revision.

Thank you
Mark