All of lore.kernel.org
 help / color / mirror / Atom feed
* [rtc-linux] [PATCH 1/4] RTC: fix double free in rtc_register_device() error path
@ 2015-07-20 23:02 ` Dmitry Torokhov
  0 siblings, 0 replies; 32+ messages in thread
From: Dmitry Torokhov @ 2015-07-20 23:02 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: rtc-linux, linux-kernel, Vasiliy Kulikov

Commit 59cca865f21e9e7beab73fcf79ba4eb776a4c228 correctly noted that naked
kfree() should not be used after failed device_register() call, however,
while it added the needed put_device() it forgot to remove the original
kfree() causing double-free.

Cc: Vasiliy Kulikov <segooon@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/rtc/class.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index ea2a315..eb82ec2 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -234,8 +234,9 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
 
 	err = device_register(&rtc->dev);
 	if (err) {
+		/* This will free both memory and the ID */
 		put_device(&rtc->dev);
-		goto exit_kfree;
+		goto exit;
 	}
 
 	rtc_dev_add_device(rtc);
@@ -247,9 +248,6 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
 
 	return rtc;
 
-exit_kfree:
-	kfree(rtc);
-
 exit_ida:
 	ida_simple_remove(&rtc_ida, id);
 
-- 
2.4.3.573.g4eafbef

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2015-07-23  0:40 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-20 23:02 [rtc-linux] [PATCH 1/4] RTC: fix double free in rtc_register_device() error path Dmitry Torokhov
2015-07-20 23:02 ` Dmitry Torokhov
2015-07-20 23:02 ` [rtc-linux] [PATCH 2/4] RTC: remove unnecessary device_get() in rtc_device_unregister Dmitry Torokhov
2015-07-20 23:02   ` Dmitry Torokhov
2015-07-21  0:39   ` [rtc-linux] " Krzysztof Kozlowski
2015-07-21  0:39     ` Krzysztof Kozlowski
2015-07-22 20:33   ` [rtc-linux] " Alexandre Belloni
2015-07-22 20:33     ` Alexandre Belloni
2015-07-20 23:02 ` [rtc-linux] [PATCH 3/4] RTC: properly manage lifetime of dev and cdev in rtc device Dmitry Torokhov
2015-07-20 23:02   ` Dmitry Torokhov
2015-07-21  0:54   ` [rtc-linux] " Krzysztof Kozlowski
2015-07-21  0:54     ` Krzysztof Kozlowski
2015-07-22 20:40   ` [rtc-linux] " Alexandre Belloni
2015-07-22 20:40     ` Alexandre Belloni
2015-07-20 23:02 ` [rtc-linux] [PATCH 4/4] RTC: switch to using is_visible() to control sysfs attributes Dmitry Torokhov
2015-07-20 23:02   ` Dmitry Torokhov
2015-07-21  1:21   ` [rtc-linux] " Krzysztof Kozlowski
2015-07-21  1:21     ` Krzysztof Kozlowski
2015-07-22 20:57     ` Alexandre Belloni
2015-07-22 20:57       ` Alexandre Belloni
2015-07-22 21:44       ` Dmitry Torokhov
2015-07-22 21:44         ` Dmitry Torokhov
2015-07-23  0:40       ` Krzysztof Kozlowski
2015-07-23  0:40         ` Krzysztof Kozlowski
2015-07-22 20:53   ` [rtc-linux] " Alexandre Belloni
2015-07-22 20:53     ` Alexandre Belloni
2015-07-21  0:32 ` [rtc-linux] [PATCH 1/4] RTC: fix double free in rtc_register_device() error path Krzysztof Kozlowski
2015-07-21  0:32   ` Krzysztof Kozlowski
2015-07-21  0:42   ` Dmitry Torokhov
2015-07-21  0:42     ` Dmitry Torokhov
2015-07-22 20:32 ` [rtc-linux] " Alexandre Belloni
2015-07-22 20:32   ` Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.