Skip to contentSkip to conversation

clocksource: decrement reference count when device_register() fail

PATCH New Yangtao Li 1 participant 1 message Jan 21, 2019 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 clocksource: decrement reference count when device_register() fail

device_register() may fail, use put_device() giving up the refconut to avoid refcount leak.

---
 kernel/time/clocksource.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/time/clocksource.c +4 -1
index 3bcc19ceb073..0a830fedc7ef 100644
@@ -1183,8 +1183,11 @@ static int __init init_clocksource_sysfs(void)
 {
 	int error = subsys_system_register(&clocksource_subsys, NULL);
 
-	if (!error)
+	if (!error) {
 		error = device_register(&device_clocksource);
+		if (error)
+			put_device(&device_clocksource);
+	}
 
 	return error;
 }
Signature · 1 line
2.17.0