Skip to contentSkip to conversation

rtc: fix RTC removal

PATCH In review Alexandre Belloni 2 participants 2 messages Dec 5, 2020 – Dec 7, 2020 Real time clock (RTC)

lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/1 rtc: fix RTC removal

Since the rtc_register_device, removing an RTC device will end with a
refcount_t: underflow; use-after-free warning since put_device is called twice in the device tear down path.

Fixes fdcfd854333b ("rtc: rework rtc_register_device() resource management")
---
 drivers/rtc/class.c | 1 -
 1 file changed, 1 deletion(-)
drivers/rtc/class.c +0 -1
index e6b44b7c4ad3..5c6748dfa55d 100644
@@ -335,7 +335,6 @@ static void devm_rtc_unregister_device(void *data)
 	cdev_device_del(&rtc->char_dev, &rtc->dev);
 	rtc->ops = NULL;
 	mutex_unlock(&rtc->ops_lock);
-	put_device(&rtc->dev);
 }
 
 static void devm_rtc_release_device(void *res)
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Alexandre Belloni

Since the rtc_register_device, removing an RTC device will end with a
refcount_t: underflow; use-after-free warning since put_device is called twice in the device tear down path.

Fixes fdcfd854333b ("rtc: rework rtc_register_device() resource management")
---
 drivers/rtc/class.c | 1 -
 1 file changed, 1 deletion(-)
drivers/rtc/class.c +0 -2
index e6b44b7c4ad3..5c6748dfa55d 100644
@@ -335,7 +335,6 @@ static void devm_rtc_unregister_device(void *data)
        cdev_device_del(&rtc->char_dev, &rtc->dev);
        rtc->ops = NULL;
        mutex_unlock(&rtc->ops_lock);
-       put_device(&rtc->dev);
 }
 
 static void devm_rtc_release_device(void *res)
--
Quoted 2 lines

2.28.0

Eek! Thanks for fixing that.