Skip to content

Commit 20d3f24

Browse files
committed
Merge tag 'thermal-6.5-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control fixes from Rafael Wysocki: "Constify thermal_zone_device_register() parameters, which was omitted by mistake, and fix a double free on thermal zone unregistration in the generic DT thermal driver (Ahmad Fatoum)" * tag 'thermal-6.5-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: thermal: of: fix double-free on unregistration thermal: core: constify params in thermal_zone_device_register
2 parents 3632f42 + ac4436a commit 20d3f24

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

drivers/thermal/thermal_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp);
12031203
struct thermal_zone_device *
12041204
thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask,
12051205
void *devdata, struct thermal_zone_device_ops *ops,
1206-
struct thermal_zone_params *tzp, int passive_delay,
1206+
const struct thermal_zone_params *tzp, int passive_delay,
12071207
int polling_delay)
12081208
{
12091209
struct thermal_zone_device *tz;
@@ -1371,7 +1371,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_device_register_with_trips);
13711371

13721372
struct thermal_zone_device *thermal_zone_device_register(const char *type, int ntrips, int mask,
13731373
void *devdata, struct thermal_zone_device_ops *ops,
1374-
struct thermal_zone_params *tzp, int passive_delay,
1374+
const struct thermal_zone_params *tzp, int passive_delay,
13751375
int polling_delay)
13761376
{
13771377
return thermal_zone_device_register_with_trips(type, NULL, ntrips, mask,

drivers/thermal/thermal_of.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,13 @@ static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdel
238238
return 0;
239239
}
240240

241-
static struct thermal_zone_params *thermal_of_parameters_init(struct device_node *np)
241+
static void thermal_of_parameters_init(struct device_node *np,
242+
struct thermal_zone_params *tzp)
242243
{
243-
struct thermal_zone_params *tzp;
244244
int coef[2];
245245
int ncoef = ARRAY_SIZE(coef);
246246
int prop, ret;
247247

248-
tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
249-
if (!tzp)
250-
return ERR_PTR(-ENOMEM);
251-
252248
tzp->no_hwmon = true;
253249

254250
if (!of_property_read_u32(np, "sustainable-power", &prop))
@@ -267,8 +263,6 @@ static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
267263

268264
tzp->slope = coef[0];
269265
tzp->offset = coef[1];
270-
271-
return tzp;
272266
}
273267

274268
static struct device_node *thermal_of_zone_get_by_name(struct thermal_zone_device *tz)
@@ -442,13 +436,11 @@ static int thermal_of_unbind(struct thermal_zone_device *tz,
442436
static void thermal_of_zone_unregister(struct thermal_zone_device *tz)
443437
{
444438
struct thermal_trip *trips = tz->trips;
445-
struct thermal_zone_params *tzp = tz->tzp;
446439
struct thermal_zone_device_ops *ops = tz->ops;
447440

448441
thermal_zone_device_disable(tz);
449442
thermal_zone_device_unregister(tz);
450443
kfree(trips);
451-
kfree(tzp);
452444
kfree(ops);
453445
}
454446

@@ -477,7 +469,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
477469
{
478470
struct thermal_zone_device *tz;
479471
struct thermal_trip *trips;
480-
struct thermal_zone_params *tzp;
472+
struct thermal_zone_params tzp = {};
481473
struct thermal_zone_device_ops *of_ops;
482474
struct device_node *np;
483475
int delay, pdelay;
@@ -509,25 +501,20 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
509501
goto out_kfree_trips;
510502
}
511503

512-
tzp = thermal_of_parameters_init(np);
513-
if (IS_ERR(tzp)) {
514-
ret = PTR_ERR(tzp);
515-
pr_err("Failed to initialize parameter from %pOFn: %d\n", np, ret);
516-
goto out_kfree_trips;
517-
}
504+
thermal_of_parameters_init(np, &tzp);
518505

519506
of_ops->bind = thermal_of_bind;
520507
of_ops->unbind = thermal_of_unbind;
521508

522509
mask = GENMASK_ULL((ntrips) - 1, 0);
523510

524511
tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips,
525-
mask, data, of_ops, tzp,
512+
mask, data, of_ops, &tzp,
526513
pdelay, delay);
527514
if (IS_ERR(tz)) {
528515
ret = PTR_ERR(tz);
529516
pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret);
530-
goto out_kfree_tzp;
517+
goto out_kfree_trips;
531518
}
532519

533520
ret = thermal_zone_device_enable(tz);
@@ -540,8 +527,6 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
540527

541528
return tz;
542529

543-
out_kfree_tzp:
544-
kfree(tzp);
545530
out_kfree_trips:
546531
kfree(trips);
547532
out_kfree_of_ops:

include/linux/thermal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,14 @@ int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp);
301301
#ifdef CONFIG_THERMAL
302302
struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
303303
void *, struct thermal_zone_device_ops *,
304-
struct thermal_zone_params *, int, int);
304+
const struct thermal_zone_params *, int, int);
305305

306306
void thermal_zone_device_unregister(struct thermal_zone_device *);
307307

308308
struct thermal_zone_device *
309309
thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int, int,
310310
void *, struct thermal_zone_device_ops *,
311-
struct thermal_zone_params *, int, int);
311+
const struct thermal_zone_params *, int, int);
312312

313313
void *thermal_zone_device_priv(struct thermal_zone_device *tzd);
314314
const char *thermal_zone_device_type(struct thermal_zone_device *tzd);
@@ -348,7 +348,7 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz);
348348
static inline struct thermal_zone_device *thermal_zone_device_register(
349349
const char *type, int trips, int mask, void *devdata,
350350
struct thermal_zone_device_ops *ops,
351-
struct thermal_zone_params *tzp,
351+
const struct thermal_zone_params *tzp,
352352
int passive_delay, int polling_delay)
353353
{ return ERR_PTR(-ENODEV); }
354354
static inline void thermal_zone_device_unregister(

0 commit comments

Comments
 (0)