Skip to content

Commit ddc1093

Browse files
committed
PCI: switchtec: Return -EFAULT for copy_to_user() errors
switchtec_dev_read() didn't handle copy_to_user() errors correctly: it assigned "rc = -EFAULT", but actually returned either "size", -ENXIO, or -EBADMSG instead. Update the failure cases to unlock mrpc_mutex and return -EFAULT directly. Link: https://lore.kernel.org/r/[email protected] Fixes: 080b47d ("MicroSemi Switchtec management interface driver") Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Logan Gunthorpe <[email protected]>
1 parent 4e353ff commit ddc1093

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/pci/switch/switchtec.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,21 +606,20 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
606606
rc = copy_to_user(data, &stuser->return_code,
607607
sizeof(stuser->return_code));
608608
if (rc) {
609-
rc = -EFAULT;
610-
goto out;
609+
mutex_unlock(&stdev->mrpc_mutex);
610+
return -EFAULT;
611611
}
612612

613613
data += sizeof(stuser->return_code);
614614
rc = copy_to_user(data, &stuser->data,
615615
size - sizeof(stuser->return_code));
616616
if (rc) {
617-
rc = -EFAULT;
618-
goto out;
617+
mutex_unlock(&stdev->mrpc_mutex);
618+
return -EFAULT;
619619
}
620620

621621
stuser_set_state(stuser, MRPC_IDLE);
622622

623-
out:
624623
mutex_unlock(&stdev->mrpc_mutex);
625624

626625
if (stuser->status == SWITCHTEC_MRPC_STATUS_DONE ||

0 commit comments

Comments
 (0)