OSDN Git Service

net: cosa: fix error check return value of register_chrdev()
authorLv Ruyi <lv.ruyi@zte.com.cn>
Mon, 18 Apr 2022 10:58:34 +0000 (10:58 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 22 Apr 2022 09:20:43 +0000 (10:20 +0100)
If major equal 0, register_chrdev() returns error code when it fails.
This function dynamically allocate a major and return its number on
success, so we should use "< 0" to check it instead of "!".

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
Acked-By: Jan "Yenya" Kasprzak <kas@fi.muni.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/wan/cosa.c

index 23d2954..1e56720 100644 (file)
@@ -349,7 +349,7 @@ static int __init cosa_init(void)
                }
        } else {
                cosa_major = register_chrdev(0, "cosa", &cosa_fops);
-               if (!cosa_major) {
+               if (cosa_major < 0) {
                        pr_warn("unable to register chardev\n");
                        err = -EIO;
                        goto out;