Skip to contentSkip to conversation

vt: correctly check return value of class_create

PATCH In review Insu Yun 2 participants 2 messages Jan 23, 2016 TTY layer and serial drivers

lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 vt: correctly check return value of class_create

Since class_create can be failed in memory pressure, its return value should be checked and correctly handled.

---
 drivers/tty/vt/vc_screen.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/vt/vc_screen.c +2 -0
index 14a2b5f..5df4bc1 100644
@@ -644,6 +644,8 @@ int __init vcs_init(void)
 	if (register_chrdev(VCS_MAJOR, "vcs", &vcs_fops))
 		panic("unable to get major %d for vcs device", VCS_MAJOR);
 	vc_class = class_create(THIS_MODULE, "vc");
+	if (IS_ERR(vc_class))
+		return PTR_ERR(vc_class);
 
 	device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs");
 	device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa");
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 1 line · Insu Yun

Since class_create can be failed in memory pressure,

In this case, really? At init time?

Quoted 1 line

its return value should be checked and correctly handled.

You didn't correctly handle it, you leaked memory and other resources :(