diff mbox series

megaraid: fix error check return value of register_chrdev()

Message ID 20220418105755.2558828-1-lv.ruyi@zte.com.cn
State New
Headers show
Series megaraid: fix error check return value of register_chrdev() | expand

Commit Message

Lv Ruyi April 18, 2022, 10:57 a.m. UTC
From: Lv Ruyi <lv.ruyi@zte.com.cn>

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>
---
 drivers/scsi/megaraid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Martin K. Petersen April 26, 2022, 1:03 p.m. UTC | #1
> 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 "!".

Applied to 5.19/scsi-staging, thanks!
diff mbox series

Patch

diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index a5d8cee2d510..bf491af9f0d6 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4607,7 +4607,7 @@  static int __init megaraid_init(void)
 	 * major number allocation.
 	 */
 	major = register_chrdev(0, "megadev_legacy", &megadev_fops);
-	if (!major) {
+	if (major < 0) {
 		printk(KERN_WARNING
 				"megaraid: failed to register char device\n");
 	}