hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
....@@ -44,10 +44,12 @@
4444 int trip, int *temp)
4545 {
4646 struct int34x_thermal_zone *d = zone->devdata;
47
- int i;
47
+ int i, ret = 0;
4848
4949 if (d->override_ops && d->override_ops->get_trip_temp)
5050 return d->override_ops->get_trip_temp(zone, trip, temp);
51
+
52
+ mutex_lock(&d->trip_mutex);
5153
5254 if (trip < d->aux_trip_nr)
5355 *temp = d->aux_trips[trip];
....@@ -66,10 +68,12 @@
6668 }
6769 }
6870 if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
69
- return -EINVAL;
71
+ ret = -EINVAL;
7072 }
7173
72
- return 0;
74
+ mutex_unlock(&d->trip_mutex);
75
+
76
+ return ret;
7377 }
7478
7579 static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,
....@@ -77,10 +81,12 @@
7781 enum thermal_trip_type *type)
7882 {
7983 struct int34x_thermal_zone *d = zone->devdata;
80
- int i;
84
+ int i, ret = 0;
8185
8286 if (d->override_ops && d->override_ops->get_trip_type)
8387 return d->override_ops->get_trip_type(zone, trip, type);
88
+
89
+ mutex_lock(&d->trip_mutex);
8490
8591 if (trip < d->aux_trip_nr)
8692 *type = THERMAL_TRIP_PASSIVE;
....@@ -99,10 +105,12 @@
99105 }
100106 }
101107 if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
102
- return -EINVAL;
108
+ ret = -EINVAL;
103109 }
104110
105
- return 0;
111
+ mutex_unlock(&d->trip_mutex);
112
+
113
+ return ret;
106114 }
107115
108116 static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
....@@ -174,6 +182,8 @@
174182 int trip_cnt = int34x_zone->aux_trip_nr;
175183 int i;
176184
185
+ mutex_lock(&int34x_zone->trip_mutex);
186
+
177187 int34x_zone->crt_trip_id = -1;
178188 if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_CRT",
179189 &int34x_zone->crt_temp))
....@@ -201,6 +211,8 @@
201211 int34x_zone->act_trips[i].valid = true;
202212 }
203213
214
+ mutex_unlock(&int34x_zone->trip_mutex);
215
+
204216 return trip_cnt;
205217 }
206218 EXPORT_SYMBOL_GPL(int340x_thermal_read_trips);
....@@ -223,6 +235,8 @@
223235 GFP_KERNEL);
224236 if (!int34x_thermal_zone)
225237 return ERR_PTR(-ENOMEM);
238
+
239
+ mutex_init(&int34x_thermal_zone->trip_mutex);
226240
227241 int34x_thermal_zone->adev = adev;
228242 int34x_thermal_zone->override_ops = override_ops;
....@@ -275,6 +289,7 @@
275289 acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
276290 kfree(int34x_thermal_zone->aux_trips);
277291 err_trip_alloc:
292
+ mutex_destroy(&int34x_thermal_zone->trip_mutex);
278293 kfree(int34x_thermal_zone);
279294 return ERR_PTR(ret);
280295 }
....@@ -286,6 +301,7 @@
286301 thermal_zone_device_unregister(int34x_thermal_zone->zone);
287302 acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
288303 kfree(int34x_thermal_zone->aux_trips);
304
+ mutex_destroy(&int34x_thermal_zone->trip_mutex);
289305 kfree(int34x_thermal_zone);
290306 }
291307 EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);