Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: testing: Initialize some variables annoteded with _free()

Variables annotated with __free() need to be initialized if the function
can return before they get updated for the first time or the attempt to
free the memory pointed to by them upon function return may crash the
kernel.

Fix this issue in some places in the thermal testing code.

Fixes: f6a034f2df42 ("thermal: Introduce a debugfs-based testing facility")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/12576267.O9o76ZdvQC@rjwysocki.net

+4 -4
+4 -4
drivers/thermal/testing/zone.c
··· 185 185 int tt_add_tz(void) 186 186 { 187 187 struct tt_thermal_zone *tt_zone __free(kfree); 188 - struct tt_work *tt_work __free(kfree); 188 + struct tt_work *tt_work __free(kfree) = NULL; 189 189 int ret; 190 190 191 191 tt_zone = kzalloc(sizeof(*tt_zone), GFP_KERNEL); ··· 237 237 238 238 int tt_del_tz(const char *arg) 239 239 { 240 - struct tt_work *tt_work __free(kfree); 240 + struct tt_work *tt_work __free(kfree) = NULL; 241 241 struct tt_thermal_zone *tt_zone, *aux; 242 242 int ret; 243 243 int id; ··· 331 331 int tt_zone_add_trip(const char *arg) 332 332 { 333 333 struct tt_thermal_zone *tt_zone __free(put_tt_zone) = NULL; 334 + struct tt_trip *tt_trip __free(kfree) = NULL; 334 335 struct tt_work *tt_work __free(kfree); 335 - struct tt_trip *tt_trip __free(kfree); 336 336 int id; 337 337 338 338 tt_work = kzalloc(sizeof(*tt_work), GFP_KERNEL); ··· 387 387 388 388 static int tt_zone_register_tz(struct tt_thermal_zone *tt_zone) 389 389 { 390 - struct thermal_trip *trips __free(kfree); 390 + struct thermal_trip *trips __free(kfree) = NULL; 391 391 struct thermal_zone_device *tz; 392 392 struct tt_trip *tt_trip; 393 393 int i;