[SCSI] hpsa: reorganize error handling in hpsa_passthru_ioctl

Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
This commit is contained in:
Stephen M. Cameron 2013-02-20 11:24:52 -06:00 committed by James Bottomley
parent e2bea6df32
commit c1f63c8fe8

View File

@ -2959,6 +2959,7 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
struct CommandList *c; struct CommandList *c;
char *buff = NULL; char *buff = NULL;
union u64bit temp64; union u64bit temp64;
int rc = 0;
if (!argp) if (!argp)
return -EINVAL; return -EINVAL;
@ -2978,8 +2979,8 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
/* Copy the data into the buffer we created */ /* Copy the data into the buffer we created */
if (copy_from_user(buff, iocommand.buf, if (copy_from_user(buff, iocommand.buf,
iocommand.buf_size)) { iocommand.buf_size)) {
kfree(buff); rc = -EFAULT;
return -EFAULT; goto out_kfree;
} }
} else { } else {
memset(buff, 0, iocommand.buf_size); memset(buff, 0, iocommand.buf_size);
@ -2987,8 +2988,8 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
} }
c = cmd_special_alloc(h); c = cmd_special_alloc(h);
if (c == NULL) { if (c == NULL) {
kfree(buff); rc = -ENOMEM;
return -ENOMEM; goto out_kfree;
} }
/* Fill in the command type */ /* Fill in the command type */
c->cmd_type = CMD_IOCTL_PEND; c->cmd_type = CMD_IOCTL_PEND;
@ -3027,22 +3028,22 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
memcpy(&iocommand.error_info, c->err_info, memcpy(&iocommand.error_info, c->err_info,
sizeof(iocommand.error_info)); sizeof(iocommand.error_info));
if (copy_to_user(argp, &iocommand, sizeof(iocommand))) { if (copy_to_user(argp, &iocommand, sizeof(iocommand))) {
kfree(buff); rc = -EFAULT;
cmd_special_free(h, c); goto out;
return -EFAULT;
} }
if (iocommand.Request.Type.Direction == XFER_READ && if (iocommand.Request.Type.Direction == XFER_READ &&
iocommand.buf_size > 0) { iocommand.buf_size > 0) {
/* Copy the data out of the buffer we created */ /* Copy the data out of the buffer we created */
if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) { if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) {
kfree(buff); rc = -EFAULT;
cmd_special_free(h, c); goto out;
return -EFAULT;
} }
} }
kfree(buff); out:
cmd_special_free(h, c); cmd_special_free(h, c);
return 0; out_kfree:
kfree(buff);
return rc;
} }
static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)