mirror of
https://github.com/torvalds/linux.git
synced 2024-12-19 09:32:32 +00:00
scsi: libsas: fix length error in sas_smp_handler()
The return value of smp_execute_task_sg() is the untransferred residual,
but bsg_job_done() requires the length of payload received. This makes
SMP passthrough commands from userland by sg ioctl to libsas get a wrong
response. The userland tools such as smp_utils failed because of these
wrong responses:
~#smp_discover /dev/bsg/expander-2\:13
response too short, len=0
~#smp_discover /dev/bsg/expander-2\:134
response too short, len=0
Fix this by passing the actual received length to bsg_job_done(). And if
smp_execute_task_sg() returns 0, this means received length is exactly
the buffer length.
[mkp: typo]
Fixes: 651a013649
("scsi: scsi_transport_sas: switch to bsg-lib for SMP passthrough")
Cc: <stable@vger.kernel.org> # v4.14+
Signed-off-by: Jason Yan <yanaijie@huawei.com>
Reported-by: chenqilin <chenqilin2@huawei.com>
Tested-by: chenqilin <chenqilin2@huawei.com>
CC: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
parent
48d83282db
commit
621f6401fd
@ -2145,7 +2145,7 @@ void sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
|
||||
struct sas_rphy *rphy)
|
||||
{
|
||||
struct domain_device *dev;
|
||||
unsigned int reslen = 0;
|
||||
unsigned int rcvlen = 0;
|
||||
int ret = -EINVAL;
|
||||
|
||||
/* no rphy means no smp target support (ie aic94xx host) */
|
||||
@ -2179,12 +2179,12 @@ void sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
|
||||
|
||||
ret = smp_execute_task_sg(dev, job->request_payload.sg_list,
|
||||
job->reply_payload.sg_list);
|
||||
if (ret > 0) {
|
||||
/* positive number is the untransferred residual */
|
||||
reslen = ret;
|
||||
if (ret >= 0) {
|
||||
/* bsg_job_done() requires the length received */
|
||||
rcvlen = job->reply_payload.payload_len - ret;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
out:
|
||||
bsg_job_done(job, ret, reslen);
|
||||
bsg_job_done(job, ret, rcvlen);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user