Thermal control fixes for 6.5-rc4

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).
 -----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCAAwFiEE4fcc61cGeeHD/fCwgsRv/nhiVHEFAmTEHtsSHHJqd0Byand5
 c29ja2kubmV0AAoJEILEb/54YlRxEhwQALAz9MtdfsjcYuSUk/Ud25d95S3rrUdg
 SsUJpejweAnrll0p6jSRYOpl9pZXk0euIhkqDcP1ytcT3/E559xbfB5cEkIZYPN4
 P5XPHqf8YCCRrmxHT1K/R+gxkDoJsodMBUS/pbE4ESQFzpjYkFRAgQruMa8GoCv3
 SX8DrU9KSMxAxvRi2oJ6vSegSqQFYB/+hp2P5GnePJwkNYaaI2LMT7/DdhCBM8RR
 EzG84ZkMkSZvChJm7CVjmkfJja7lO8Xatz31lFtGothH5gOxb65XiCS5MbeY+MxI
 CmdK8OFEukaH81mFz5pLJztjgRFV0JHBKzql35XnMB3SV6X1ac4D2mH5DUQpIbQK
 yG3wOSJtPrS3LxuCv0G3Dw2E8kJFbnug5UZfgl5RbGrdE7jO/hTuhppejnJazzoB
 rAmmyAuNDPJlJfrP54Qv6Z3dgLYsVI8OmfCkZD55rS6MDJl/mcIJoGiTHKZvm8IK
 bQ01xGlDTClwiv/EciBLDcnguhCaByFowWrHg2/vvCG4j4XoRgr2yUDTp6Ay5bTy
 xlOeFm2gtfFy+AFt0IMVfgDjPHSuHHxqtUldrz+Y2y6Ns12+s0As9ReVDm2WeSBp
 5iGKJtShb6qOZ9OTCbJCDQjtR36AP1+PVXG5Vc+gsCc2ASG3akoCGo1NIp2mJuPb
 Xm7RMdt8TMRb
 =90Ib
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2023-07-28 17:14:05 -07:00
commit 20d3f2417b
3 changed files with 11 additions and 26 deletions

View file

@ -1203,7 +1203,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp);
struct thermal_zone_device *
thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask,
void *devdata, struct thermal_zone_device_ops *ops,
struct thermal_zone_params *tzp, int passive_delay,
const struct thermal_zone_params *tzp, int passive_delay,
int polling_delay)
{
struct thermal_zone_device *tz;
@ -1371,7 +1371,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_device_register_with_trips);
struct thermal_zone_device *thermal_zone_device_register(const char *type, int ntrips, int mask,
void *devdata, struct thermal_zone_device_ops *ops,
struct thermal_zone_params *tzp, int passive_delay,
const struct thermal_zone_params *tzp, int passive_delay,
int polling_delay)
{
return thermal_zone_device_register_with_trips(type, NULL, ntrips, mask,

View file

@ -238,17 +238,13 @@ static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdel
return 0;
}
static struct thermal_zone_params *thermal_of_parameters_init(struct device_node *np)
static void thermal_of_parameters_init(struct device_node *np,
struct thermal_zone_params *tzp)
{
struct thermal_zone_params *tzp;
int coef[2];
int ncoef = ARRAY_SIZE(coef);
int prop, ret;
tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
if (!tzp)
return ERR_PTR(-ENOMEM);
tzp->no_hwmon = true;
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
tzp->slope = coef[0];
tzp->offset = coef[1];
return tzp;
}
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,
static void thermal_of_zone_unregister(struct thermal_zone_device *tz)
{
struct thermal_trip *trips = tz->trips;
struct thermal_zone_params *tzp = tz->tzp;
struct thermal_zone_device_ops *ops = tz->ops;
thermal_zone_device_disable(tz);
thermal_zone_device_unregister(tz);
kfree(trips);
kfree(tzp);
kfree(ops);
}
@ -477,7 +469,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
{
struct thermal_zone_device *tz;
struct thermal_trip *trips;
struct thermal_zone_params *tzp;
struct thermal_zone_params tzp = {};
struct thermal_zone_device_ops *of_ops;
struct device_node *np;
int delay, pdelay;
@ -509,12 +501,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
goto out_kfree_trips;
}
tzp = thermal_of_parameters_init(np);
if (IS_ERR(tzp)) {
ret = PTR_ERR(tzp);
pr_err("Failed to initialize parameter from %pOFn: %d\n", np, ret);
goto out_kfree_trips;
}
thermal_of_parameters_init(np, &tzp);
of_ops->bind = thermal_of_bind;
of_ops->unbind = thermal_of_unbind;
@ -522,12 +509,12 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
mask = GENMASK_ULL((ntrips) - 1, 0);
tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips,
mask, data, of_ops, tzp,
mask, data, of_ops, &tzp,
pdelay, delay);
if (IS_ERR(tz)) {
ret = PTR_ERR(tz);
pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret);
goto out_kfree_tzp;
goto out_kfree_trips;
}
ret = thermal_zone_device_enable(tz);
@ -540,8 +527,6 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
return tz;
out_kfree_tzp:
kfree(tzp);
out_kfree_trips:
kfree(trips);
out_kfree_of_ops:

View file

@ -301,14 +301,14 @@ int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp);
#ifdef CONFIG_THERMAL
struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
void *, struct thermal_zone_device_ops *,
struct thermal_zone_params *, int, int);
const struct thermal_zone_params *, int, int);
void thermal_zone_device_unregister(struct thermal_zone_device *);
struct thermal_zone_device *
thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int, int,
void *, struct thermal_zone_device_ops *,
struct thermal_zone_params *, int, int);
const struct thermal_zone_params *, int, int);
void *thermal_zone_device_priv(struct thermal_zone_device *tzd);
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);
static inline struct thermal_zone_device *thermal_zone_device_register(
const char *type, int trips, int mask, void *devdata,
struct thermal_zone_device_ops *ops,
struct thermal_zone_params *tzp,
const struct thermal_zone_params *tzp,
int passive_delay, int polling_delay)
{ return ERR_PTR(-ENODEV); }
static inline void thermal_zone_device_unregister(