Skip to content

Commit 83c6f23

Browse files
Wu Bomartinkpetersen
authored andcommitted
scsi: sg: add sg_remove_request in sg_write
If the __copy_from_user function failed we need to call sg_remove_request in sg_write. Link: https://lore.kernel.org/r/[email protected] Acked-by: Douglas Gilbert <[email protected]> Signed-off-by: Wu Bo <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 849f858 commit 83c6f23

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/scsi/sg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,10 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
685685
hp->flags = input_size; /* structure abuse ... */
686686
hp->pack_id = old_hdr.pack_id;
687687
hp->usr_ptr = NULL;
688-
if (copy_from_user(cmnd, buf, cmd_size))
688+
if (copy_from_user(cmnd, buf, cmd_size)) {
689+
sg_remove_request(sfp, srp);
689690
return -EFAULT;
691+
}
690692
/*
691693
* SG_DXFER_TO_FROM_DEV is functionally equivalent to SG_DXFER_FROM_DEV,
692694
* but is is possible that the app intended SG_DXFER_TO_DEV, because there

0 commit comments

Comments
 (0)