Skip to content

Commit

Permalink
scsi: megaraid: Fix error check return value of register_chrdev()
Browse files Browse the repository at this point in the history
[ Upstream commit c5acd61 ]

If major equals 0, register_chrdev() returns an error code when it fails.
This function dynamically allocates a major and returns its number on
success, so we should use "< 0" to check it instead of "!".

Link: https://lore.kernel.org/r/20220418105755.2558828-1-lv.ruyi@zte.com.cn
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Lv Ruyi authored and gregkh committed Jun 9, 2022
1 parent 95050b9 commit 508add1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/scsi/megaraid.c
Original file line number Diff line number Diff line change
Expand Up @@ -4634,7 +4634,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");
}
Expand Down

0 comments on commit 508add1

Please sign in to comment.