diff mbox series

[v4,4/4] opp: Make _set_opp_custom() work without regulators

Message ID 20210120222649.28149-5-digetx@gmail.com (mailing list archive)
State New, archived
Delegated to: viresh kumar
Headers show
Series OPP API fixes and improvements | expand

Commit Message

Dmitry Osipenko Jan. 20, 2021, 10:26 p.m. UTC
Check whether OPP table has regulators in _set_opp_custom() and set up
dev_pm_set_opp_data accordingly. Now _set_opp_custom() works properly,
i.e. it doesn't crash if OPP table doesn't have assigned regulators.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/opp/core.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

Comments

Viresh Kumar Jan. 22, 2021, 7:26 a.m. UTC | #1
On 21-01-21, 01:26, Dmitry Osipenko wrote:
> Check whether OPP table has regulators in _set_opp_custom() and set up
> dev_pm_set_opp_data accordingly. Now _set_opp_custom() works properly,
> i.e. it doesn't crash if OPP table doesn't have assigned regulators.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/opp/core.c | 26 +++++++++++++++++---------
>  1 file changed, 17 insertions(+), 9 deletions(-)

I have applied this instead:

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 32d653774adc..805fc2602808 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -828,24 +828,31 @@ static int _set_opp_custom(const struct opp_table *opp_table,
                           struct dev_pm_opp_supply *old_supply,
                           struct dev_pm_opp_supply *new_supply)
 {
-       struct dev_pm_set_opp_data *data;
+       struct dev_pm_set_opp_data *data = opp_table->set_opp_data;
        int size;
 
-       data = opp_table->set_opp_data;
+       /*
+        * We support this only if dev_pm_opp_set_regulators() was called
+        * earlier.
+        */
+       if (opp_table->sod_supplies) {
+               size = sizeof(*old_supply) * opp_table->regulator_count;
+               if (!old_supply)
+                       memset(data->old_opp.supplies, 0, size);
+               else
+                       memcpy(data->old_opp.supplies, old_supply, size);
+
+               memcpy(data->new_opp.supplies, new_supply, size);
+               data->regulator_count = opp_table->regulator_count;
+       } else {
+               data->regulator_count = 0;
+       }
+
        data->regulators = opp_table->regulators;
-       data->regulator_count = opp_table->regulator_count;
        data->clk = opp_table->clk;
        data->dev = dev;
-
        data->old_opp.rate = old_freq;
-       size = sizeof(*old_supply) * opp_table->regulator_count;
-       if (!old_supply)
-               memset(data->old_opp.supplies, 0, size);
-       else
-               memcpy(data->old_opp.supplies, old_supply, size);
-
        data->new_opp.rate = freq;
-       memcpy(data->new_opp.supplies, new_supply, size);
 
        return opp_table->set_opp(data);
 }
Dmitry Osipenko Jan. 22, 2021, 2:43 p.m. UTC | #2
21.01.2021 01:26, Dmitry Osipenko пишет:
> Check whether OPP table has regulators in _set_opp_custom() and set up
> dev_pm_set_opp_data accordingly. Now _set_opp_custom() works properly,
> i.e. it doesn't crash if OPP table doesn't have assigned regulators.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/opp/core.c | 26 +++++++++++++++++---------
>  1 file changed, 17 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 08d205a55c07..c38ac1cf62ac 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -829,23 +829,31 @@ static int _set_opp_custom(const struct opp_table *opp_table,
>  			   struct dev_pm_opp_supply *new_supply)
>  {
>  	struct dev_pm_set_opp_data *data;
> -	int size;
> +	int size, regulator_count;
> +
> +	if (opp_table->sod_supplies)
> +		regulator_count = opp_table->regulator_count;
> +	else
> +		regulator_count = 0;
>  
>  	data = opp_table->set_opp_data;
>  	data->regulators = opp_table->regulators;
> -	data->regulator_count = opp_table->regulator_count;
> +	data->regulator_count = regulator_count;
>  	data->clk = opp_table->clk;
>  	data->dev = dev;
>  
>  	data->old_opp.rate = old_freq;
> -	size = sizeof(*old_supply) * opp_table->regulator_count;
> -	if (!old_supply)
> -		memset(data->old_opp.supplies, 0, size);
> -	else
> -		memcpy(data->old_opp.supplies, old_supply, size);
> -
>  	data->new_opp.rate = freq;
> -	memcpy(data->new_opp.supplies, new_supply, size);
> +
> +	if (regulator_count) {
> +		size = sizeof(*old_supply) * opp_table->regulator_count;
> +		if (!old_supply)
> +			memset(data->old_opp.supplies, 0, size);
> +		else
> +			memcpy(data->old_opp.supplies, old_supply, size);
> +
> +		memcpy(data->new_opp.supplies, new_supply, size);
> +	}
>  
>  	return opp_table->set_opp(data);
>  }
> 

Looks good, thank you!
Dmitry Osipenko Jan. 22, 2021, 2:44 p.m. UTC | #3
22.01.2021 10:26, Viresh Kumar пишет:
> On 21-01-21, 01:26, Dmitry Osipenko wrote:
>> Check whether OPP table has regulators in _set_opp_custom() and set up
>> dev_pm_set_opp_data accordingly. Now _set_opp_custom() works properly,
>> i.e. it doesn't crash if OPP table doesn't have assigned regulators.
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>  drivers/opp/core.c | 26 +++++++++++++++++---------
>>  1 file changed, 17 insertions(+), 9 deletions(-)
> 
> I have applied this instead:
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 32d653774adc..805fc2602808 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -828,24 +828,31 @@ static int _set_opp_custom(const struct opp_table *opp_table,
>                            struct dev_pm_opp_supply *old_supply,
>                            struct dev_pm_opp_supply *new_supply)
>  {
> -       struct dev_pm_set_opp_data *data;
> +       struct dev_pm_set_opp_data *data = opp_table->set_opp_data;
>         int size;
>  
> -       data = opp_table->set_opp_data;
> +       /*
> +        * We support this only if dev_pm_opp_set_regulators() was called
> +        * earlier.
> +        */
> +       if (opp_table->sod_supplies) {
> +               size = sizeof(*old_supply) * opp_table->regulator_count;
> +               if (!old_supply)
> +                       memset(data->old_opp.supplies, 0, size);
> +               else
> +                       memcpy(data->old_opp.supplies, old_supply, size);
> +
> +               memcpy(data->new_opp.supplies, new_supply, size);
> +               data->regulator_count = opp_table->regulator_count;
> +       } else {
> +               data->regulator_count = 0;
> +       }
> +
>         data->regulators = opp_table->regulators;
> -       data->regulator_count = opp_table->regulator_count;
>         data->clk = opp_table->clk;
>         data->dev = dev;
> -
>         data->old_opp.rate = old_freq;
> -       size = sizeof(*old_supply) * opp_table->regulator_count;
> -       if (!old_supply)
> -               memset(data->old_opp.supplies, 0, size);
> -       else
> -               memcpy(data->old_opp.supplies, old_supply, size);
> -
>         data->new_opp.rate = freq;
> -       memcpy(data->new_opp.supplies, new_supply, size);
>  
>         return opp_table->set_opp(data);
>  }
> 
> 

I replied to the wrong email, but this also looks good :) Thanks!
diff mbox series

Patch

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 08d205a55c07..c38ac1cf62ac 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -829,23 +829,31 @@  static int _set_opp_custom(const struct opp_table *opp_table,
 			   struct dev_pm_opp_supply *new_supply)
 {
 	struct dev_pm_set_opp_data *data;
-	int size;
+	int size, regulator_count;
+
+	if (opp_table->sod_supplies)
+		regulator_count = opp_table->regulator_count;
+	else
+		regulator_count = 0;
 
 	data = opp_table->set_opp_data;
 	data->regulators = opp_table->regulators;
-	data->regulator_count = opp_table->regulator_count;
+	data->regulator_count = regulator_count;
 	data->clk = opp_table->clk;
 	data->dev = dev;
 
 	data->old_opp.rate = old_freq;
-	size = sizeof(*old_supply) * opp_table->regulator_count;
-	if (!old_supply)
-		memset(data->old_opp.supplies, 0, size);
-	else
-		memcpy(data->old_opp.supplies, old_supply, size);
-
 	data->new_opp.rate = freq;
-	memcpy(data->new_opp.supplies, new_supply, size);
+
+	if (regulator_count) {
+		size = sizeof(*old_supply) * opp_table->regulator_count;
+		if (!old_supply)
+			memset(data->old_opp.supplies, 0, size);
+		else
+			memcpy(data->old_opp.supplies, old_supply, size);
+
+		memcpy(data->new_opp.supplies, new_supply, size);
+	}
 
 	return opp_table->set_opp(data);
 }