Commit 28965e17 authored by Oliver Neukum's avatar Oliver Neukum Committed by Greg Kroah-Hartman

cdc-wdm: unify error handling in write

This makes sure the error handling path is the same for
all error conditions, thus reducing code duplication.

Signed-off-by: Oliver Neukum <oneukum@suse.de>0
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4132cd02
...@@ -349,30 +349,25 @@ static ssize_t wdm_write ...@@ -349,30 +349,25 @@ static ssize_t wdm_write
r = copy_from_user(buf, buffer, count); r = copy_from_user(buf, buffer, count);
if (r > 0) { if (r > 0) {
kfree(buf);
rv = -EFAULT; rv = -EFAULT;
goto outnl; goto out_free_mem;
} }
/* concurrent writes and disconnect */ /* concurrent writes and disconnect */
r = mutex_lock_interruptible(&desc->wlock); r = mutex_lock_interruptible(&desc->wlock);
rv = -ERESTARTSYS; rv = -ERESTARTSYS;
if (r) { if (r)
kfree(buf); goto out_free_mem;
goto outnl;
}
if (test_bit(WDM_DISCONNECTING, &desc->flags)) { if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
kfree(buf);
rv = -ENODEV; rv = -ENODEV;
goto outnp; goto out_free_mem_lock;
} }
r = usb_autopm_get_interface(desc->intf); r = usb_autopm_get_interface(desc->intf);
if (r < 0) { if (r < 0) {
kfree(buf);
rv = usb_translate_errors(r); rv = usb_translate_errors(r);
goto outnp; goto out_free_mem_lock;
} }
if (!(file->f_flags & O_NONBLOCK)) if (!(file->f_flags & O_NONBLOCK))
...@@ -386,9 +381,8 @@ static ssize_t wdm_write ...@@ -386,9 +381,8 @@ static ssize_t wdm_write
r = -EIO; r = -EIO;
if (r < 0) { if (r < 0) {
kfree(buf);
rv = r; rv = r;
goto out; goto out_free_mem_pm;
} }
req = desc->orq; req = desc->orq;
...@@ -415,21 +409,28 @@ static ssize_t wdm_write ...@@ -415,21 +409,28 @@ static ssize_t wdm_write
rv = usb_submit_urb(desc->command, GFP_KERNEL); rv = usb_submit_urb(desc->command, GFP_KERNEL);
if (rv < 0) { if (rv < 0) {
kfree(buf);
desc->outbuf = NULL; desc->outbuf = NULL;
clear_bit(WDM_IN_USE, &desc->flags); clear_bit(WDM_IN_USE, &desc->flags);
dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv); dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv);
rv = usb_translate_errors(rv); rv = usb_translate_errors(rv);
goto out_free_mem_pm;
} else { } else {
dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d",
req->wIndex); req->wIndex);
} }
out:
usb_autopm_put_interface(desc->intf); usb_autopm_put_interface(desc->intf);
outnp:
mutex_unlock(&desc->wlock); mutex_unlock(&desc->wlock);
outnl: outnl:
return rv < 0 ? rv : count; return rv < 0 ? rv : count;
out_free_mem_pm:
usb_autopm_put_interface(desc->intf);
out_free_mem_lock:
mutex_unlock(&desc->wlock);
out_free_mem:
kfree(buf);
return rv;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment