aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/usbip/stub_dev.c8
-rw-r--r--drivers/staging/usbip/usbip_common.c25
-rw-r--r--drivers/staging/usbip/usbip_common.h1
-rw-r--r--drivers/staging/usbip/vhci_hcd.c4
-rw-r--r--drivers/staging/usbip/vhci_sysfs.c6
5 files changed, 9 insertions, 35 deletions
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index 76a1ff0e6275..2e2ccefb9c2b 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -86,7 +86,6 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
86 struct stub_device *sdev = dev_get_drvdata(dev); 86 struct stub_device *sdev = dev_get_drvdata(dev);
87 int sockfd = 0; 87 int sockfd = 0;
88 struct socket *socket; 88 struct socket *socket;
89 ssize_t err = -EINVAL;
90 89
91 if (!sdev) { 90 if (!sdev) {
92 dev_err(dev, "sdev is null\n"); 91 dev_err(dev, "sdev is null\n");
@@ -96,6 +95,7 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
96 sscanf(buf, "%d", &sockfd); 95 sscanf(buf, "%d", &sockfd);
97 96
98 if (sockfd != -1) { 97 if (sockfd != -1) {
98 int err;
99 dev_info(dev, "stub up\n"); 99 dev_info(dev, "stub up\n");
100 100
101 spin_lock_irq(&sdev->ud.lock); 101 spin_lock_irq(&sdev->ud.lock);
@@ -105,7 +105,7 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
105 goto err; 105 goto err;
106 } 106 }
107 107
108 socket = sockfd_to_socket(sockfd); 108 socket = sockfd_lookup(sockfd, &err);
109 if (!socket) 109 if (!socket)
110 goto err; 110 goto err;
111 111
@@ -138,7 +138,7 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
138 138
139err: 139err:
140 spin_unlock_irq(&sdev->ud.lock); 140 spin_unlock_irq(&sdev->ud.lock);
141 return err; 141 return -EINVAL;
142} 142}
143static DEVICE_ATTR(usbip_sockfd, S_IWUSR, NULL, store_sockfd); 143static DEVICE_ATTR(usbip_sockfd, S_IWUSR, NULL, store_sockfd);
144 144
@@ -208,7 +208,7 @@ static void stub_shutdown_connection(struct usbip_device *ud)
208 * not touch NULL socket. 208 * not touch NULL socket.
209 */ 209 */
210 if (ud->tcp_socket) { 210 if (ud->tcp_socket) {
211 fput(ud->tcp_socket->file); 211 sockfd_put(ud->tcp_socket);
212 ud->tcp_socket = NULL; 212 ud->tcp_socket = NULL;
213 } 213 }
214 214
diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c
index 96552e3a1bfb..e010939ebb12 100644
--- a/drivers/staging/usbip/usbip_common.c
+++ b/drivers/staging/usbip/usbip_common.c
@@ -400,31 +400,6 @@ err:
400} 400}
401EXPORT_SYMBOL_GPL(usbip_recv); 401EXPORT_SYMBOL_GPL(usbip_recv);
402 402
403struct socket *sockfd_to_socket(unsigned int sockfd)
404{
405 struct socket *socket;
406 struct file *file;
407 struct inode *inode;
408
409 file = fget(sockfd);
410 if (!file) {
411 pr_err("invalid sockfd\n");
412 return NULL;
413 }
414
415 inode = file_inode(file);
416
417 if (!inode || !S_ISSOCK(inode->i_mode)) {
418 fput(file);
419 return NULL;
420 }
421
422 socket = SOCKET_I(inode);
423
424 return socket;
425}
426EXPORT_SYMBOL_GPL(sockfd_to_socket);
427
428/* there may be more cases to tweak the flags. */ 403/* there may be more cases to tweak the flags. */
429static unsigned int tweak_transfer_flags(unsigned int flags) 404static unsigned int tweak_transfer_flags(unsigned int flags)
430{ 405{
diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
index 7e6c5436d972..9f86588a4534 100644
--- a/drivers/staging/usbip/usbip_common.h
+++ b/drivers/staging/usbip/usbip_common.h
@@ -314,7 +314,6 @@ void usbip_dump_urb(struct urb *purb);
314void usbip_dump_header(struct usbip_header *pdu); 314void usbip_dump_header(struct usbip_header *pdu);
315 315
316int usbip_recv(struct socket *sock, void *buf, int size); 316int usbip_recv(struct socket *sock, void *buf, int size);
317struct socket *sockfd_to_socket(unsigned int sockfd);
318 317
319void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, 318void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
320 int pack); 319 int pack);
diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index 72391ef87646..99dd2b1656c9 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -789,7 +789,7 @@ static void vhci_shutdown_connection(struct usbip_device *ud)
789 789
790 /* active connection is closed */ 790 /* active connection is closed */
791 if (vdev->ud.tcp_socket) { 791 if (vdev->ud.tcp_socket) {
792 fput(vdev->ud.tcp_socket->file); 792 sockfd_put(vdev->ud.tcp_socket);
793 vdev->ud.tcp_socket = NULL; 793 vdev->ud.tcp_socket = NULL;
794 } 794 }
795 pr_info("release socket\n"); 795 pr_info("release socket\n");
@@ -836,7 +836,7 @@ static void vhci_device_reset(struct usbip_device *ud)
836 vdev->udev = NULL; 836 vdev->udev = NULL;
837 837
838 if (ud->tcp_socket) { 838 if (ud->tcp_socket) {
839 fput(ud->tcp_socket->file); 839 sockfd_put(ud->tcp_socket);
840 ud->tcp_socket = NULL; 840 ud->tcp_socket = NULL;
841 } 841 }
842 ud->status = VDEV_ST_NULL; 842 ud->status = VDEV_ST_NULL;
diff --git a/drivers/staging/usbip/vhci_sysfs.c b/drivers/staging/usbip/vhci_sysfs.c
index 0141bc34d5cc..baba127081b3 100644
--- a/drivers/staging/usbip/vhci_sysfs.c
+++ b/drivers/staging/usbip/vhci_sysfs.c
@@ -175,6 +175,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
175 struct socket *socket; 175 struct socket *socket;
176 int sockfd = 0; 176 int sockfd = 0;
177 __u32 rhport = 0, devid = 0, speed = 0; 177 __u32 rhport = 0, devid = 0, speed = 0;
178 int err;
178 179
179 /* 180 /*
180 * @rhport: port number of vhci_hcd 181 * @rhport: port number of vhci_hcd
@@ -192,8 +193,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
192 return -EINVAL; 193 return -EINVAL;
193 194
194 /* Extract socket from fd. */ 195 /* Extract socket from fd. */
195 /* The correct way to clean this up is to fput(socket->file). */ 196 socket = sockfd_lookup(sockfd, &err);
196 socket = sockfd_to_socket(sockfd);
197 if (!socket) 197 if (!socket)
198 return -EINVAL; 198 return -EINVAL;
199 199
@@ -209,7 +209,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
209 spin_unlock(&vdev->ud.lock); 209 spin_unlock(&vdev->ud.lock);
210 spin_unlock(&the_controller->lock); 210 spin_unlock(&the_controller->lock);
211 211
212 fput(socket->file); 212 sockfd_put(socket);
213 213
214 dev_err(dev, "port %d already used\n", rhport); 214 dev_err(dev, "port %d already used\n", rhport);
215 return -EINVAL; 215 return -EINVAL;