Skip to content

Commit 26c9ab8

Browse files
committed
thermal: core: Represent suspend-related thermal zone flags as bits
Instead of using two separate fields in struct thermal_zone_device for representing flags related to thermal zone suspend, represent them explicitly as bits in one u8 "state" field. Subsequently, that field will be used for addressing race conditions related to thermal zone initialization and exit. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Lukasz Luba <[email protected]>
1 parent 7ddca58 commit 26c9ab8

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

drivers/thermal/thermal_core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
547547
int low = -INT_MAX, high = INT_MAX;
548548
int temp, ret;
549549

550-
if (tz->suspended || tz->mode != THERMAL_DEVICE_ENABLED)
550+
if (tz->state != TZ_STATE_READY || tz->mode != THERMAL_DEVICE_ENABLED)
551551
return;
552552

553553
ret = __thermal_zone_get_temp(tz, &temp);
@@ -1671,15 +1671,14 @@ static void thermal_zone_device_resume(struct work_struct *work)
16711671

16721672
mutex_lock(&tz->lock);
16731673

1674-
tz->suspended = false;
1674+
tz->state &= ~(TZ_STATE_FLAG_SUSPENDED | TZ_STATE_FLAG_RESUMING);
16751675

16761676
thermal_debug_tz_resume(tz);
16771677
thermal_zone_device_init(tz);
16781678
thermal_governor_update_tz(tz, THERMAL_TZ_RESUME);
16791679
__thermal_zone_device_update(tz, THERMAL_TZ_RESUME);
16801680

16811681
complete(&tz->resume);
1682-
tz->resuming = false;
16831682

16841683
mutex_unlock(&tz->lock);
16851684
}
@@ -1688,7 +1687,7 @@ static void thermal_zone_pm_prepare(struct thermal_zone_device *tz)
16881687
{
16891688
mutex_lock(&tz->lock);
16901689

1691-
if (tz->resuming) {
1690+
if (tz->state & TZ_STATE_FLAG_RESUMING) {
16921691
/*
16931692
* thermal_zone_device_resume() queued up for this zone has not
16941693
* acquired the lock yet, so release it to let the function run
@@ -1701,7 +1700,7 @@ static void thermal_zone_pm_prepare(struct thermal_zone_device *tz)
17011700
mutex_lock(&tz->lock);
17021701
}
17031702

1704-
tz->suspended = true;
1703+
tz->state |= TZ_STATE_FLAG_SUSPENDED;
17051704

17061705
mutex_unlock(&tz->lock);
17071706
}
@@ -1713,7 +1712,7 @@ static void thermal_zone_pm_complete(struct thermal_zone_device *tz)
17131712
cancel_delayed_work(&tz->poll_queue);
17141713

17151714
reinit_completion(&tz->resume);
1716-
tz->resuming = true;
1715+
tz->state |= TZ_STATE_FLAG_RESUMING;
17171716

17181717
/*
17191718
* Replace the work function with the resume one, which will restore the

drivers/thermal/thermal_core.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ struct thermal_governor {
6262
struct list_head governor_list;
6363
};
6464

65+
#define TZ_STATE_FLAG_SUSPENDED BIT(0)
66+
#define TZ_STATE_FLAG_RESUMING BIT(1)
67+
68+
#define TZ_STATE_READY 0
69+
6570
/**
6671
* struct thermal_zone_device - structure for a thermal zone
6772
* @id: unique id number for each thermal zone
@@ -101,8 +106,7 @@ struct thermal_governor {
101106
* @node: node in thermal_tz_list (in thermal_core.c)
102107
* @poll_queue: delayed work for polling
103108
* @notify_event: Last notification event
104-
* @suspended: thermal zone suspend indicator
105-
* @resuming: indicates whether or not thermal zone resume is in progress
109+
* @state: current state of the thermal zone
106110
* @trips: array of struct thermal_trip objects
107111
*/
108112
struct thermal_zone_device {
@@ -135,8 +139,7 @@ struct thermal_zone_device {
135139
struct list_head node;
136140
struct delayed_work poll_queue;
137141
enum thermal_notify_event notify_event;
138-
bool suspended;
139-
bool resuming;
142+
u8 state;
140143
#ifdef CONFIG_THERMAL_DEBUGFS
141144
struct thermal_debugfs *debugfs;
142145
#endif

0 commit comments

Comments
 (0)