snsc: check return value of class_create
authorZhouyi Zhou <yizhouzhou@ict.ac.cn>
Wed, 10 Aug 2016 08:06:43 +0000 (16:06 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Aug 2016 12:47:54 +0000 (14:47 +0200)
 return value of class_create should be considered in
module init function.

Signed-off-by: Zhouyi Zhou <zhouzhouyi@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/snsc.c

index 94006f9c2e4312d6b4f7dbafa7726daa93e2c1e7..10e56323f3902faf66cd5fc5b8fd83272505b378 100644 (file)
@@ -385,13 +385,18 @@ scdrv_init(void)
 
        event_nasid = ia64_sn_get_console_nasid();
 
+       snsc_class = class_create(THIS_MODULE, SYSCTL_BASENAME);
+       if (IS_ERR(snsc_class)) {
+               printk("%s: failed to allocate class\n", __func__);
+               return PTR_ERR(snsc_class);
+       }
+
        if (alloc_chrdev_region(&first_dev, 0, num_cnodes,
                                SYSCTL_BASENAME) < 0) {
                printk("%s: failed to register SN system controller device\n",
                       __func__);
                return -ENODEV;
        }
-       snsc_class = class_create(THIS_MODULE, SYSCTL_BASENAME);
 
        for (cnode = 0; cnode < num_cnodes; cnode++) {
                        geoid = cnodeid_get_geoid(cnode);