Skip to content

Commit 0104dcd

Browse files
committed
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: f6a034f ("thermal: Introduce a debugfs-based testing facility") Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 1c426fd commit 0104dcd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/thermal/testing/zone.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void tt_add_tz_work_fn(struct work_struct *work)
185185
int tt_add_tz(void)
186186
{
187187
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;
189189
int ret;
190190

191191
tt_zone = kzalloc(sizeof(*tt_zone), GFP_KERNEL);
@@ -237,7 +237,7 @@ static void tt_zone_unregister_tz(struct tt_thermal_zone *tt_zone)
237237

238238
int tt_del_tz(const char *arg)
239239
{
240-
struct tt_work *tt_work __free(kfree);
240+
struct tt_work *tt_work __free(kfree) = NULL;
241241
struct tt_thermal_zone *tt_zone, *aux;
242242
int ret;
243243
int id;
@@ -331,8 +331,8 @@ static void tt_zone_add_trip_work_fn(struct work_struct *work)
331331
int tt_zone_add_trip(const char *arg)
332332
{
333333
struct tt_thermal_zone *tt_zone __free(put_tt_zone) = NULL;
334+
struct tt_trip *tt_trip __free(kfree) = NULL;
334335
struct tt_work *tt_work __free(kfree);
335-
struct tt_trip *tt_trip __free(kfree);
336336
int id;
337337

338338
tt_work = kzalloc(sizeof(*tt_work), GFP_KERNEL);
@@ -387,7 +387,7 @@ static struct thermal_zone_device_ops tt_zone_ops = {
387387

388388
static int tt_zone_register_tz(struct tt_thermal_zone *tt_zone)
389389
{
390-
struct thermal_trip *trips __free(kfree);
390+
struct thermal_trip *trips __free(kfree) = NULL;
391391
struct thermal_zone_device *tz;
392392
struct tt_trip *tt_trip;
393393
int i;

0 commit comments

Comments
 (0)