Skip to contentSkip to conversation

hwtracing: stm: fix possible double free in stm_register_device()

PATCH In review Hangyu Hua 1 participant 4 messages Apr 18, 2022 – Jun 23, 2022

Subsystems (3)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 hwtracing: stm: fix possible double free in stm_register_device()

put_device() will call stm_device_release() to free stm when stm_register_device() fails. So there is no need to call vfree() again.

Fix this by adding a return after put_device().

Fixes 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")
---
 drivers/hwtracing/stm/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hwtracing/stm/core.c +1 -0
index 2712e699ba08..403b4f41bb1b 100644
@@ -915,6 +915,7 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
 
 	/* matches device_initialize() above */
 	put_device(&stm->dev);
+	return err;
 err_free:
 	vfree(stm);
 
Signature · 1 line
2.25.1
author
#1 lore raw

Ping

Quoted 23 lines · Hangyu Hua

put_device() will call stm_device_release() to free stm when stm_register_device() fails. So there is no need to call vfree() again.

Fix this by adding a return after put_device().

Fixes 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")
---
  drivers/hwtracing/stm/core.c | 1 +
  1 file changed, 1 insertion(+)
drivers/hwtracing/stm/core.c +1 -0
index 2712e699ba08..403b4f41bb1b 100644
@@ -915,6 +915,7 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
 
  	/* matches device_initialize() above */
  	put_device(&stm->dev);
+	return err;
  err_free:
  	vfree(stm);
 
author
#2 lore raw

Gentel ping.

Quoted 25 lines · Hangyu Hua

Ping

Quoted 22 lines · Hangyu Hua

put_device() will call stm_device_release() to free stm when stm_register_device() fails. So there is no need to call vfree() again.

Fix this by adding a return after put_device().

Fixes 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")

---
  drivers/hwtracing/stm/core.c | 1 +

  1 file changed, 1 insertion(+)
drivers/hwtracing/stm/core.c +1 -0
index 2712e699ba08..403b4f41bb1b 100644
@@ -915,6 +915,7 @@ int stm_register_device(struct device *parent, 
 struct stm_data *stm_data,
       /* matches device_initialize() above */
       put_device(&stm->dev);
+    return err;

  err_free:
      vfree(stm);

author
#3 lore raw
Quoted 17 lines · Hangyu Hua

Gentel ping.

Quoted 14 lines · Hangyu Hua

Ping

Quoted 11 lines · Hangyu Hua

put_device() will call stm_device_release() to free stm when stm_register_device() fails. So there is no need to call vfree() again.

Fix this by adding a return after put_device().

Fixes 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")

---
  drivers/hwtracing/stm/core.c | 1 +

  1 file changed, 1 insertion(+)
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/hwtracing/stm/core.c +1 -0
index 2712e699ba08..403b4f41bb1b 100644
@@ -915,6 +915,7 @@ int stm_register_device(struct device *parent, 
 struct stm_data *stm_data,
       /* matches device_initialize() above */
       put_device(&stm->dev);
+    return err;

  err_free:
      vfree(stm);

Gentel ping.