2019-11-20 17:22:46

by Wen Yang

[permalink] [raw]
Subject: [PATCH] stm class: fix a double free in stm_register_device()

In the error path of stm_register_device(), the kfree is
unnecessary, as the put_device() before it ends up calling
stm_device_release() to free stm_device.

Fixes: 7bd1d4093c2fa ("stm class: Introduce an abstraction for System Trace Module devices")
Signed-off-by: Wen Yang <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
drivers/hwtracing/stm/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 2712e69..55c69d8 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -868,8 +868,10 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
return -ENOMEM;

stm->major = register_chrdev(0, stm_data->name, &stm_fops);
- if (stm->major < 0)
- goto err_free;
+ if (stm->major < 0) {
+ vfree(stm);
+ return err;
+ }

device_initialize(&stm->dev);
stm->dev.devt = MKDEV(stm->major, 0);
@@ -915,8 +917,6 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,

/* matches device_initialize() above */
put_device(&stm->dev);
-err_free:
- vfree(stm);

return err;
}
--
1.8.3.1