diff options
Diffstat (limited to 'drivers/staging/usbip')
-rw-r--r-- | drivers/staging/usbip/stub_dev.c | 15 | ||||
-rw-r--r-- | drivers/staging/usbip/stub_rx.c | 5 | ||||
-rw-r--r-- | drivers/staging/usbip/stub_tx.c | 3 | ||||
-rw-r--r-- | drivers/staging/usbip/usbip_common.c | 40 | ||||
-rw-r--r-- | drivers/staging/usbip/usbip_common.h | 4 | ||||
-rw-r--r-- | drivers/staging/usbip/userspace/src/usbip_detach.c | 9 | ||||
-rw-r--r-- | drivers/staging/usbip/vhci.h | 1 | ||||
-rw-r--r-- | drivers/staging/usbip/vhci_hcd.c | 51 | ||||
-rw-r--r-- | drivers/staging/usbip/vhci_rx.c | 2 | ||||
-rw-r--r-- | drivers/staging/usbip/vhci_sysfs.c | 6 | ||||
-rw-r--r-- | drivers/staging/usbip/vhci_tx.c | 2 |
11 files changed, 57 insertions, 81 deletions
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c index c8d79a7f0e0e..ee36415eb26d 100644 --- a/drivers/staging/usbip/stub_dev.c +++ b/drivers/staging/usbip/stub_dev.c @@ -18,6 +18,7 @@ */ #include <linux/device.h> +#include <linux/file.h> #include <linux/kthread.h> #include <linux/module.h> @@ -203,7 +204,7 @@ static void stub_shutdown_connection(struct usbip_device *ud) * not touch NULL socket. */ if (ud->tcp_socket) { - sock_release(ud->tcp_socket); + fput(ud->tcp_socket->file); ud->tcp_socket = NULL; } @@ -432,6 +433,8 @@ static int stub_probe(struct usb_interface *interface, dev_err(&interface->dev, "stub_add_files for %s\n", udev_busid); usb_set_intfdata(interface, NULL); usb_put_intf(interface); + usb_put_dev(udev); + kthread_stop_put(sdev->ud.eh); busid_priv->interf_count = 0; busid_priv->sdev = NULL; @@ -477,19 +480,17 @@ static void stub_disconnect(struct usb_interface *interface) /* get stub_device */ if (!sdev) { dev_err(&interface->dev, "could not get device"); - /* BUG(); */ return; } usb_set_intfdata(interface, NULL); /* - * NOTE: - * rx/tx threads are invoked for each usb_device. + * NOTE: rx/tx threads are invoked for each usb_device. */ stub_remove_files(&interface->dev); - /*If usb reset called from event handler*/ + /* If usb reset is called from event handler */ if (busid_priv->sdev->ud.eh == current) { busid_priv->interf_count--; return; @@ -504,13 +505,13 @@ static void stub_disconnect(struct usb_interface *interface) busid_priv->interf_count = 0; - /* 1. shutdown the current connection */ + /* shutdown the current connection */ shutdown_busid(busid_priv); usb_put_dev(sdev->udev); usb_put_intf(interface); - /* 3. free sdev */ + /* free sdev */ busid_priv->sdev = NULL; stub_device_free(sdev); diff --git a/drivers/staging/usbip/stub_rx.c b/drivers/staging/usbip/stub_rx.c index 694cfd7596f3..0572a15242b5 100644 --- a/drivers/staging/usbip/stub_rx.c +++ b/drivers/staging/usbip/stub_rx.c @@ -164,7 +164,6 @@ static int tweak_set_configuration_cmd(struct urb *urb) config, dev_name(&urb->dev->dev)); return 0; - /* return usb_driver_set_configuration(urb->dev, config); */ } static int tweak_reset_device_cmd(struct urb *urb) @@ -480,7 +479,7 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, return; } - /* set priv->urb->transfer_buffer */ + /* allocate urb transfer buffer, if needed */ if (pdu->u.cmd_submit.transfer_buffer_length > 0) { priv->urb->transfer_buffer = kzalloc(pdu->u.cmd_submit.transfer_buffer_length, @@ -492,7 +491,7 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, } } - /* set priv->urb->setup_packet */ + /* copy urb setup packet */ priv->urb->setup_packet = kmemdup(&pdu->u.cmd_submit.setup, 8, GFP_KERNEL); if (!priv->urb->setup_packet) { diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c index 023fda305be2..513961fef055 100644 --- a/drivers/staging/usbip/stub_tx.c +++ b/drivers/staging/usbip/stub_tx.c @@ -166,7 +166,7 @@ static int stub_send_ret_submit(struct stub_device *sdev) int ret; struct urb *urb = priv->urb; struct usbip_header pdu_header; - void *iso_buffer = NULL; + struct usbip_iso_packet_descriptor *iso_buffer = NULL; struct kvec *iov = NULL; int iovnum = 0; @@ -192,7 +192,6 @@ static int stub_send_ret_submit(struct stub_device *sdev) setup_ret_submit_pdu(&pdu_header, urb); usbip_dbg_stub_tx("setup txdata seqnum: %d urb: %p\n", pdu_header.base.seqnum, urb); - /*usbip_dump_header(pdu_header);*/ usbip_header_correct_endian(&pdu_header, 1); iov[iovnum].iov_base = &pdu_header; diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c index 57f11f9cd8a5..75189feac380 100644 --- a/drivers/staging/usbip/usbip_common.c +++ b/drivers/staging/usbip/usbip_common.c @@ -413,8 +413,10 @@ struct socket *sockfd_to_socket(unsigned int sockfd) inode = file->f_dentry->d_inode; - if (!inode || !S_ISSOCK(inode->i_mode)) + if (!inode || !S_ISSOCK(inode->i_mode)) { + fput(file); return NULL; + } socket = SOCKET_I(inode); @@ -439,7 +441,6 @@ static void usbip_pack_cmd_submit(struct usbip_header *pdu, struct urb *urb, * will be discussed when usbip is ported to other operating systems. */ if (pack) { - /* vhci_tx.c */ spdu->transfer_flags = tweak_transfer_flags(urb->transfer_flags); spdu->transfer_buffer_length = urb->transfer_buffer_length; @@ -447,9 +448,7 @@ static void usbip_pack_cmd_submit(struct usbip_header *pdu, struct urb *urb, spdu->number_of_packets = urb->number_of_packets; spdu->interval = urb->interval; } else { - /* stub_rx.c */ urb->transfer_flags = spdu->transfer_flags; - urb->transfer_buffer_length = spdu->transfer_buffer_length; urb->start_frame = spdu->start_frame; urb->number_of_packets = spdu->number_of_packets; @@ -463,16 +462,12 @@ static void usbip_pack_ret_submit(struct usbip_header *pdu, struct urb *urb, struct usbip_header_ret_submit *rpdu = &pdu->u.ret_submit; if (pack) { - /* stub_tx.c */ - rpdu->status = urb->status; rpdu->actual_length = urb->actual_length; rpdu->start_frame = urb->start_frame; rpdu->number_of_packets = urb->number_of_packets; rpdu->error_count = urb->error_count; } else { - /* vhci_rx.c */ - urb->status = rpdu->status; urb->actual_length = rpdu->actual_length; urb->start_frame = rpdu->start_frame; @@ -639,28 +634,26 @@ static void usbip_pack_iso(struct usbip_iso_packet_descriptor *iso, } /* must free buffer */ -void *usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen) +struct usbip_iso_packet_descriptor* +usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen) { - void *buff; struct usbip_iso_packet_descriptor *iso; int np = urb->number_of_packets; ssize_t size = np * sizeof(*iso); int i; - buff = kzalloc(size, GFP_KERNEL); - if (!buff) + iso = kzalloc(size, GFP_KERNEL); + if (!iso) return NULL; for (i = 0; i < np; i++) { - iso = buff + (i * sizeof(*iso)); - - usbip_pack_iso(iso, &urb->iso_frame_desc[i], 1); - usbip_iso_packet_correct_endian(iso, 1); + usbip_pack_iso(&iso[i], &urb->iso_frame_desc[i], 1); + usbip_iso_packet_correct_endian(&iso[i], 1); } *bufflen = size; - return buff; + return iso; } EXPORT_SYMBOL_GPL(usbip_alloc_iso_desc_pdu); @@ -680,8 +673,6 @@ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb) /* my Bluetooth dongle gets ISO URBs which are np = 0 */ if (np == 0) { - /* pr_info("iso np == 0\n"); */ - /* usbip_dump_urb(urb); */ return 0; } @@ -703,11 +694,10 @@ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb) return -EPIPE; } + iso = (struct usbip_iso_packet_descriptor *) buff; for (i = 0; i < np; i++) { - iso = buff + (i * sizeof(*iso)); - - usbip_iso_packet_correct_endian(iso, 0); - usbip_pack_iso(iso, &urb->iso_frame_desc[i], 0); + usbip_iso_packet_correct_endian(&iso[i], 0); + usbip_pack_iso(&iso[i], &urb->iso_frame_desc[i], 0); total_length += urb->iso_frame_desc[i].actual_length; } @@ -754,7 +744,7 @@ void usbip_pad_iso(struct usbip_device *ud, struct urb *urb) /* * if actual_length is transfer_buffer_length then no padding is * present. - */ + */ if (urb->actual_length == urb->transfer_buffer_length) return; @@ -778,14 +768,12 @@ int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb) int size; if (ud->side == USBIP_STUB) { - /* stub_rx.c */ /* the direction of urb must be OUT. */ if (usb_pipein(urb->pipe)) return 0; size = urb->transfer_buffer_length; } else { - /* vhci_rx.c */ /* the direction of urb must be IN. */ if (usb_pipeout(urb->pipe)) return 0; diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h index 5d89c0fd6f7b..7e6c5436d972 100644 --- a/drivers/staging/usbip/usbip_common.h +++ b/drivers/staging/usbip/usbip_common.h @@ -320,7 +320,9 @@ void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, int pack); void usbip_header_correct_endian(struct usbip_header *pdu, int send); -void *usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen); +struct usbip_iso_packet_descriptor* +usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen); + /* some members of urb must be substituted before. */ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb); void usbip_pad_iso(struct usbip_device *ud, struct urb *urb); diff --git a/drivers/staging/usbip/userspace/src/usbip_detach.c b/drivers/staging/usbip/userspace/src/usbip_detach.c index 89bf3c195c28..dac5f065755a 100644 --- a/drivers/staging/usbip/userspace/src/usbip_detach.c +++ b/drivers/staging/usbip/userspace/src/usbip_detach.c @@ -19,6 +19,7 @@ #include <sysfs/libsysfs.h> #include <ctype.h> +#include <limits.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -46,6 +47,7 @@ static int detach_port(char *port) { int ret; uint8_t portnum; + char path[PATH_MAX+1]; for (unsigned int i=0; i < strlen(port); i++) if (!isdigit(port[i])) { @@ -57,6 +59,13 @@ static int detach_port(char *port) portnum = atoi(port); + /* remove the port state file */ + + snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", portnum); + + remove(path); + rmdir(VHCI_STATE_PATH); + ret = usbip_vhci_driver_open(); if (ret < 0) { err("open vhci_driver"); diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h index c66b8b3f97b4..5dddc4d4b6a5 100644 --- a/drivers/staging/usbip/vhci.h +++ b/drivers/staging/usbip/vhci.h @@ -99,7 +99,6 @@ extern const struct attribute_group dev_attr_group; /* vhci_hcd.c */ void rh_port_connect(int rhport, enum usb_device_speed speed); -void rh_port_disconnect(int rhport); /* vhci_rx.c */ struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum); diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c index 620d1beb4587..c3aa2195f1a8 100644 --- a/drivers/staging/usbip/vhci_hcd.c +++ b/drivers/staging/usbip/vhci_hcd.c @@ -18,6 +18,7 @@ */ #include <linux/init.h> +#include <linux/file.h> #include <linux/kernel.h> #include <linux/kthread.h> #include <linux/module.h> @@ -140,32 +141,23 @@ void rh_port_connect(int rhport, enum usb_device_speed speed) break; } - /* spin_lock(&the_controller->vdev[rhport].ud.lock); - * the_controller->vdev[rhport].ud.status = VDEV_CONNECT; - * spin_unlock(&the_controller->vdev[rhport].ud.lock); */ - spin_unlock_irqrestore(&the_controller->lock, flags); usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); } -void rh_port_disconnect(int rhport) +static void rh_port_disconnect(int rhport) { unsigned long flags; usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport); spin_lock_irqsave(&the_controller->lock, flags); - /* stop_activity(dum, driver); */ + the_controller->port_status[rhport] &= ~USB_PORT_STAT_CONNECTION; the_controller->port_status[rhport] |= (1 << USB_PORT_FEAT_C_CONNECTION); - /* not yet complete the disconnection - * spin_lock(&vdev->ud.lock); - * vdev->ud.status = VHC_ST_DISCONNECT; - * spin_unlock(&vdev->ud.lock); */ - spin_unlock_irqrestore(&the_controller->lock, flags); usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); } @@ -228,7 +220,6 @@ done: return changed ? retval : 0; } -/* See hub_configure in hub.c */ static inline void hub_descriptor(struct usb_hub_descriptor *desc) { memset(desc, 0, sizeof(*desc)); @@ -292,8 +283,6 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, usbip_dbg_vhci_rh(" ClearPortFeature: " "USB_PORT_FEAT_POWER\n"); dum->port_status[rhport] = 0; - /* dum->address = 0; */ - /* dum->hdev = 0; */ dum->resuming = 0; break; case USB_PORT_FEAT_C_RESET: @@ -333,11 +322,11 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, retval = -EPIPE; } - /* we do no care of resume. */ + /* we do not care about resume. */ /* whoever resets or resumes must GetPortStatus to * complete it!! - * */ + */ if (dum->resuming && time_after(jiffies, dum->re_timeout)) { dum->port_status[rhport] |= (1 << USB_PORT_FEAT_C_SUSPEND); @@ -345,11 +334,6 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ~(1 << USB_PORT_FEAT_SUSPEND); dum->resuming = 0; dum->re_timeout = 0; - /* if (dum->driver && dum->driver->resume) { - * spin_unlock (&dum->lock); - * dum->driver->resume (&dum->gadget); - * spin_lock (&dum->lock); - * } */ } if ((dum->port_status[rhport] & (1 << USB_PORT_FEAT_RESET)) != @@ -411,9 +395,6 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, default: pr_err("default: no such request\n"); - /* dev_dbg (hardware, - * "hub control req%04x v%04x i%04x l%d\n", - * typeReq, wValue, wIndex, wLength); */ /* "protocol stall" on error */ retval = -EPIPE; @@ -456,7 +437,6 @@ static void vhci_tx_urb(struct urb *urb) if (!vdev) { pr_err("could not get virtual device"); - /* BUG(); */ return; } @@ -813,7 +793,7 @@ static void vhci_shutdown_connection(struct usbip_device *ud) kernel_sock_shutdown(ud->tcp_socket, SHUT_RDWR); } - /* kill threads related to this sdev, if v.c. exists */ + /* kill threads related to this sdev */ if (vdev->ud.tcp_rx) { kthread_stop_put(vdev->ud.tcp_rx); vdev->ud.tcp_rx = NULL; @@ -825,8 +805,8 @@ static void vhci_shutdown_connection(struct usbip_device *ud) pr_info("stop threads\n"); /* active connection is closed */ - if (vdev->ud.tcp_socket != NULL) { - sock_release(vdev->ud.tcp_socket); + if (vdev->ud.tcp_socket) { + fput(vdev->ud.tcp_socket->file); vdev->ud.tcp_socket = NULL; } pr_info("release socket\n"); @@ -872,7 +852,10 @@ static void vhci_device_reset(struct usbip_device *ud) usb_put_dev(vdev->udev); vdev->udev = NULL; - ud->tcp_socket = NULL; + if (ud->tcp_socket) { + fput(ud->tcp_socket->file); + ud->tcp_socket = NULL; + } ud->status = VDEV_ST_NULL; spin_unlock(&ud->lock); @@ -928,7 +911,6 @@ static int vhci_start(struct usb_hcd *hcd) spin_lock_init(&vhci->lock); hcd->power_budget = 0; /* no limit */ - hcd->state = HC_STATE_RUNNING; hcd->uses_new_polling = 1; /* vhci_hcd is now ready to be controlled through sysfs */ @@ -976,8 +958,6 @@ static int vhci_bus_suspend(struct usb_hcd *hcd) dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); spin_lock_irq(&vhci->lock); - /* vhci->rh_state = DUMMY_RH_SUSPENDED; - * set_link_state(vhci); */ hcd->state = HC_STATE_SUSPENDED; spin_unlock_irq(&vhci->lock); @@ -995,10 +975,6 @@ static int vhci_bus_resume(struct usb_hcd *hcd) if (!HCD_HW_ACCESSIBLE(hcd)) { rc = -ESHUTDOWN; } else { - /* vhci->rh_state = DUMMY_RH_RUNNING; - * set_link_state(vhci); - * if (!list_empty(&vhci->urbp_list)) - * mod_timer(&vhci->timer, jiffies); */ hcd->state = HC_STATE_RUNNING; } spin_unlock_irq(&vhci->lock); @@ -1151,7 +1127,7 @@ static int vhci_hcd_resume(struct platform_device *pdev) static struct platform_driver vhci_driver = { .probe = vhci_hcd_probe, - .remove = __devexit_p(vhci_hcd_remove), + .remove = vhci_hcd_remove, .suspend = vhci_hcd_suspend, .resume = vhci_hcd_resume, .driver = { @@ -1175,7 +1151,6 @@ static struct platform_device the_pdev = { .name = (char *) driver_name, .id = -1, .dev = { - /* .driver = &vhci_driver, */ .release = the_pdev_release, }, }; diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c index f0eaf04fa25b..ba5f1c079b69 100644 --- a/drivers/staging/usbip/vhci_rx.c +++ b/drivers/staging/usbip/vhci_rx.c @@ -167,7 +167,7 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev, } else { usbip_dbg_vhci_rx("now giveback urb %p\n", urb); - /* If unlink is succeed, status is -ECONNRESET */ + /* If unlink is successful, status is -ECONNRESET */ urb->status = pdu->u.ret_unlink.status; pr_info("urb->status %d\n", urb->status); diff --git a/drivers/staging/usbip/vhci_sysfs.c b/drivers/staging/usbip/vhci_sysfs.c index 7ce9c2f7e442..c66e9c05c76b 100644 --- a/drivers/staging/usbip/vhci_sysfs.c +++ b/drivers/staging/usbip/vhci_sysfs.c @@ -18,6 +18,7 @@ */ #include <linux/kthread.h> +#include <linux/file.h> #include <linux/net.h> #include "usbip_common.h" @@ -189,7 +190,8 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr, if (valid_args(rhport, speed) < 0) return -EINVAL; - /* check sockfd */ + /* Extract socket from fd. */ + /* The correct way to clean this up is to fput(socket->file). */ socket = sockfd_to_socket(sockfd); if (!socket) return -EINVAL; @@ -206,6 +208,8 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr, spin_unlock(&vdev->ud.lock); spin_unlock(&the_controller->lock); + fput(socket->file); + dev_err(dev, "port %d already used\n", rhport); return -EINVAL; } diff --git a/drivers/staging/usbip/vhci_tx.c b/drivers/staging/usbip/vhci_tx.c index 9b437e7ef1a7..b1f0dcd68f55 100644 --- a/drivers/staging/usbip/vhci_tx.c +++ b/drivers/staging/usbip/vhci_tx.c @@ -76,7 +76,7 @@ static int vhci_send_cmd_submit(struct vhci_device *vdev) int ret; struct urb *urb = priv->urb; struct usbip_header pdu_header; - void *iso_buffer = NULL; + struct usbip_iso_packet_descriptor *iso_buffer = NULL; txsize = 0; memset(&pdu_header, 0, sizeof(pdu_header)); |