Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: sg: Fix checking return value of blk_get_queue()

Commit fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference") make
a mess how blk_get_queue() is called, blk_get_queue() returns true on
success while the caller expects it returns 0 on success.

Fix this problem and also add a corresponding error message on failure.

Fixes: fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Closes: https://lore.kernel.org/all/87lefv622n.fsf@linux.ibm.com/
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20230705024001.177585-1-yukuai1@huaweicloud.com
Tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Tested-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Yu Kuai and committed by
Martin K. Petersen
80b60510 f4d1a8e0

+4 -3
+4 -3
drivers/scsi/sg.c
··· 1497 1497 int error; 1498 1498 unsigned long iflags; 1499 1499 1500 - error = blk_get_queue(scsidp->request_queue); 1501 - if (error) 1502 - return error; 1500 + if (!blk_get_queue(scsidp->request_queue)) { 1501 + pr_warn("%s: get scsi_device queue failed\n", __func__); 1502 + return -ENODEV; 1503 + } 1503 1504 1504 1505 error = -ENOMEM; 1505 1506 cdev = cdev_alloc();