[v1,08/18] thermal: intel: pch_thermal: Migrate to thermal_zone_device_register()

Message ID 20240130111250.185718-9-angelogioacchino.delregno@collabora.com
State New
Headers
Series [v1,01/18] thermal: core: Change governor name to const char pointer |

Commit Message

AngeloGioacchino Del Regno Jan. 30, 2024, 11:12 a.m. UTC
  The thermal API has a new thermal_zone_device_register() function which
is deprecating the older thermal_zone_device_register_with_trips() and
thermal_tripless_zone_device_register().

Migrate to the new thermal zone device registration function.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/thermal/intel/intel_pch_thermal.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
  

Comments

Rafael J. Wysocki Feb. 1, 2024, 7:51 p.m. UTC | #1
On Tue, Jan 30, 2024 at 12:13 PM AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com> wrote:
>
> The thermal API has a new thermal_zone_device_register() function which
> is deprecating the older thermal_zone_device_register_with_trips() and
> thermal_tripless_zone_device_register().
>
> Migrate to the new thermal zone device registration function.
>
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
>  drivers/thermal/intel/intel_pch_thermal.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c
> index b3905e34c507..73d7c2ac7dbc 100644
> --- a/drivers/thermal/intel/intel_pch_thermal.c
> +++ b/drivers/thermal/intel/intel_pch_thermal.c
> @@ -160,6 +160,7 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
>                                    const struct pci_device_id *id)
>  {
>         enum pch_board_ids board_id = id->driver_data;
> +       struct thermal_zone_device_params tzdp;
>         struct pch_thermal_device *ptd;
>         int nr_trips = 0;
>         u16 trip_temp;
> @@ -233,10 +234,13 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
>
>         nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
>
> -       ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id],
> -                                                          ptd->trips, nr_trips,
> -                                                          0, ptd, &tzd_ops,
> -                                                          NULL, 0, 0);
> +       tzdp.tzp.type = board_names[board_id];
> +       tzdp.tzp.devdata = ptd;
> +       tzdp.tzp.trips = ptd->trips;
> +       tzdp.tzp.num_trips = nr_trips;
> +       tzdp.tzp.ops = &tzd_ops;
> +
> +       ptd->tzd = thermal_zone_device_register(&tzdp);

IMV, this should be

ptd->tzd = thermal_zone_device_register(board_names[board_id],
ptd->trips, nr_trips, &tzd_ops, ptd, NULL);

and the tzdp variable is not necessary even.

Analogously in the rest of the series (ie. patches [4-18/18]).

>         if (IS_ERR(ptd->tzd)) {
>                 dev_err(&pdev->dev, "Failed to register thermal zone %s\n",
>                         board_names[board_id]);
> --
  
AngeloGioacchino Del Regno Feb. 2, 2024, 10:10 a.m. UTC | #2
Il 01/02/24 20:51, Rafael J. Wysocki ha scritto:
> On Tue, Jan 30, 2024 at 12:13 PM AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com> wrote:
>>
>> The thermal API has a new thermal_zone_device_register() function which
>> is deprecating the older thermal_zone_device_register_with_trips() and
>> thermal_tripless_zone_device_register().
>>
>> Migrate to the new thermal zone device registration function.
>>
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> ---
>>   drivers/thermal/intel/intel_pch_thermal.c | 12 ++++++++----
>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c
>> index b3905e34c507..73d7c2ac7dbc 100644
>> --- a/drivers/thermal/intel/intel_pch_thermal.c
>> +++ b/drivers/thermal/intel/intel_pch_thermal.c
>> @@ -160,6 +160,7 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
>>                                     const struct pci_device_id *id)
>>   {
>>          enum pch_board_ids board_id = id->driver_data;
>> +       struct thermal_zone_device_params tzdp;
>>          struct pch_thermal_device *ptd;
>>          int nr_trips = 0;
>>          u16 trip_temp;
>> @@ -233,10 +234,13 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
>>
>>          nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
>>
>> -       ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id],
>> -                                                          ptd->trips, nr_trips,
>> -                                                          0, ptd, &tzd_ops,
>> -                                                          NULL, 0, 0);
>> +       tzdp.tzp.type = board_names[board_id];
>> +       tzdp.tzp.devdata = ptd;
>> +       tzdp.tzp.trips = ptd->trips;
>> +       tzdp.tzp.num_trips = nr_trips;
>> +       tzdp.tzp.ops = &tzd_ops;
>> +
>> +       ptd->tzd = thermal_zone_device_register(&tzdp);
> 
> IMV, this should be
> 
> ptd->tzd = thermal_zone_device_register(board_names[board_id],
> ptd->trips, nr_trips, &tzd_ops, ptd, NULL);
> 
> and the tzdp variable is not necessary even.
> 

The whole point of thermal_zone_device_register() taking just one parameter was
that those older functions were taking a bit too many params, and with the
introduction of Thermal Zone name we'd be adding even more.

For intel_pch_thermal, things are more or less the same, assignments are done there
line by line... but for most of the others, IMO it's easier and schematized as a
single stack-initialized structure that could even be constified in the future.

> Analogously in the rest of the series (ie. patches [4-18/18]).
> 
>>          if (IS_ERR(ptd->tzd)) {
>>                  dev_err(&pdev->dev, "Failed to register thermal zone %s\n",
>>                          board_names[board_id]);
>> --
  
Rafael J. Wysocki Feb. 2, 2024, 5:44 p.m. UTC | #3
On Fri, Feb 2, 2024 at 11:10 AM AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com> wrote:
>
> Il 01/02/24 20:51, Rafael J. Wysocki ha scritto:
> > On Tue, Jan 30, 2024 at 12:13 PM AngeloGioacchino Del Regno
> > <angelogioacchino.delregno@collabora.com> wrote:
> >>
> >> The thermal API has a new thermal_zone_device_register() function which
> >> is deprecating the older thermal_zone_device_register_with_trips() and
> >> thermal_tripless_zone_device_register().
> >>
> >> Migrate to the new thermal zone device registration function.
> >>
> >> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> >> ---
> >>   drivers/thermal/intel/intel_pch_thermal.c | 12 ++++++++----
> >>   1 file changed, 8 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c
> >> index b3905e34c507..73d7c2ac7dbc 100644
> >> --- a/drivers/thermal/intel/intel_pch_thermal.c
> >> +++ b/drivers/thermal/intel/intel_pch_thermal.c
> >> @@ -160,6 +160,7 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
> >>                                     const struct pci_device_id *id)
> >>   {
> >>          enum pch_board_ids board_id = id->driver_data;
> >> +       struct thermal_zone_device_params tzdp;
> >>          struct pch_thermal_device *ptd;
> >>          int nr_trips = 0;
> >>          u16 trip_temp;
> >> @@ -233,10 +234,13 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
> >>
> >>          nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
> >>
> >> -       ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id],
> >> -                                                          ptd->trips, nr_trips,
> >> -                                                          0, ptd, &tzd_ops,
> >> -                                                          NULL, 0, 0);
> >> +       tzdp.tzp.type = board_names[board_id];
> >> +       tzdp.tzp.devdata = ptd;
> >> +       tzdp.tzp.trips = ptd->trips;
> >> +       tzdp.tzp.num_trips = nr_trips;
> >> +       tzdp.tzp.ops = &tzd_ops;
> >> +
> >> +       ptd->tzd = thermal_zone_device_register(&tzdp);
> >
> > IMV, this should be
> >
> > ptd->tzd = thermal_zone_device_register(board_names[board_id],
> > ptd->trips, nr_trips, &tzd_ops, ptd, NULL);
> >
> > and the tzdp variable is not necessary even.
> >
>
> The whole point of thermal_zone_device_register() taking just one parameter was
> that those older functions were taking a bit too many params, and with the
> introduction of Thermal Zone name we'd be adding even more.

That's fair.

However, as indicated elsewhere, there are at least a few arguments of
the registration function that fit into the argument list: trips[],
num_trips, ops, devdata.

I'd add the name to that list and put the rest (including type) into
the params struct.

> For intel_pch_thermal, things are more or less the same, assignments are done there
> line by line... but for most of the others, IMO it's easier and schematized as a
> single stack-initialized structure that could even be constified in the future.

Well, it's copied into the struct thermal_zone_device, so it's better
to put it one the stack, so the memory occupied by it gets freed when
not needed any more.
  

Patch

diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c
index b3905e34c507..73d7c2ac7dbc 100644
--- a/drivers/thermal/intel/intel_pch_thermal.c
+++ b/drivers/thermal/intel/intel_pch_thermal.c
@@ -160,6 +160,7 @@  static int intel_pch_thermal_probe(struct pci_dev *pdev,
 				   const struct pci_device_id *id)
 {
 	enum pch_board_ids board_id = id->driver_data;
+	struct thermal_zone_device_params tzdp;
 	struct pch_thermal_device *ptd;
 	int nr_trips = 0;
 	u16 trip_temp;
@@ -233,10 +234,13 @@  static int intel_pch_thermal_probe(struct pci_dev *pdev,
 
 	nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
 
-	ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id],
-							   ptd->trips, nr_trips,
-							   0, ptd, &tzd_ops,
-							   NULL, 0, 0);
+	tzdp.tzp.type = board_names[board_id];
+	tzdp.tzp.devdata = ptd;
+	tzdp.tzp.trips = ptd->trips;
+	tzdp.tzp.num_trips = nr_trips;
+	tzdp.tzp.ops = &tzd_ops;
+
+	ptd->tzd = thermal_zone_device_register(&tzdp);
 	if (IS_ERR(ptd->tzd)) {
 		dev_err(&pdev->dev, "Failed to register thermal zone %s\n",
 			board_names[board_id]);