diff mbox series

thermal: genetlink: Fix TZ_GET_TRIP NULL pointer dereference

Message ID 20220228110351.20518-2-nicolas.cavallari@green-communications.fr
State Accepted
Commit 5838a14832d447990827d85e90afe17e6fb9c175
Headers show
Series thermal: genetlink: Fix TZ_GET_TRIP NULL pointer dereference | expand

Commit Message

Nicolas Cavallari Feb. 28, 2022, 11:03 a.m. UTC
Do not call get_trip_hyst() if the thermal zone does not define one.

Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
---
 drivers/thermal/thermal_netlink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Rafael J. Wysocki March 1, 2022, 3:14 p.m. UTC | #1
On Mon, Feb 28, 2022 at 12:04 PM Nicolas Cavallari
<nicolas.cavallari@green-communications.fr> wrote:
>
> Do not call get_trip_hyst() if the thermal zone does not define one.
>
> Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
> ---
>  drivers/thermal/thermal_netlink.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c
> index a16dd4d5d710..73e68cce292e 100644
> --- a/drivers/thermal/thermal_netlink.c
> +++ b/drivers/thermal/thermal_netlink.c
> @@ -419,11 +419,12 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
>         for (i = 0; i < tz->trips; i++) {
>
>                 enum thermal_trip_type type;
> -               int temp, hyst;
> +               int temp, hyst = 0;
>
>                 tz->ops->get_trip_type(tz, i, &type);
>                 tz->ops->get_trip_temp(tz, i, &temp);
> -               tz->ops->get_trip_hyst(tz, i, &hyst);
> +               if (tz->ops->get_trip_hyst)
> +                       tz->ops->get_trip_hyst(tz, i, &hyst);
>
>                 if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_ID, i) ||
>                     nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_TYPE, type) ||
> --

Applied, but I think this needs to go into 5.17-rc, doesn't it?

Daniel?
Daniel Lezcano March 1, 2022, 8:48 p.m. UTC | #2
On 01/03/2022 16:14, Rafael J. Wysocki wrote:
> On Mon, Feb 28, 2022 at 12:04 PM Nicolas Cavallari
> <nicolas.cavallari@green-communications.fr> wrote:
>>
>> Do not call get_trip_hyst() if the thermal zone does not define one.
>>
>> Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
>> ---
>>   drivers/thermal/thermal_netlink.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c
>> index a16dd4d5d710..73e68cce292e 100644
>> --- a/drivers/thermal/thermal_netlink.c
>> +++ b/drivers/thermal/thermal_netlink.c
>> @@ -419,11 +419,12 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
>>          for (i = 0; i < tz->trips; i++) {
>>
>>                  enum thermal_trip_type type;
>> -               int temp, hyst;
>> +               int temp, hyst = 0;
>>
>>                  tz->ops->get_trip_type(tz, i, &type);
>>                  tz->ops->get_trip_temp(tz, i, &temp);
>> -               tz->ops->get_trip_hyst(tz, i, &hyst);
>> +               if (tz->ops->get_trip_hyst)
>> +                       tz->ops->get_trip_hyst(tz, i, &hyst);
>>
>>                  if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_ID, i) ||
>>                      nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_TYPE, type) ||
>> --
> 
> Applied, but I think this needs to go into 5.17-rc, doesn't it?

Yes, correct
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c
index a16dd4d5d710..73e68cce292e 100644
--- a/drivers/thermal/thermal_netlink.c
+++ b/drivers/thermal/thermal_netlink.c
@@ -419,11 +419,12 @@  static int thermal_genl_cmd_tz_get_trip(struct param *p)
 	for (i = 0; i < tz->trips; i++) {
 
 		enum thermal_trip_type type;
-		int temp, hyst;
+		int temp, hyst = 0;
 
 		tz->ops->get_trip_type(tz, i, &type);
 		tz->ops->get_trip_temp(tz, i, &temp);
-		tz->ops->get_trip_hyst(tz, i, &hyst);
+		if (tz->ops->get_trip_hyst)
+			tz->ops->get_trip_hyst(tz, i, &hyst);
 
 		if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_ID, i) ||
 		    nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_TYPE, type) ||