Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 964ea96e authored by Al Viro's avatar Al Viro
Browse files

usbip: don't open-code sockfd_lookup/sockfd_put



Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent c7999c36
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -86,7 +86,6 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
	struct stub_device *sdev = dev_get_drvdata(dev);
	struct stub_device *sdev = dev_get_drvdata(dev);
	int sockfd = 0;
	int sockfd = 0;
	struct socket *socket;
	struct socket *socket;
	ssize_t err = -EINVAL;


	if (!sdev) {
	if (!sdev) {
		dev_err(dev, "sdev is null\n");
		dev_err(dev, "sdev is null\n");
@@ -96,6 +95,7 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
	sscanf(buf, "%d", &sockfd);
	sscanf(buf, "%d", &sockfd);


	if (sockfd != -1) {
	if (sockfd != -1) {
		int err;
		dev_info(dev, "stub up\n");
		dev_info(dev, "stub up\n");


		spin_lock_irq(&sdev->ud.lock);
		spin_lock_irq(&sdev->ud.lock);
@@ -105,7 +105,7 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
			goto err;
			goto err;
		}
		}


		socket = sockfd_to_socket(sockfd);
		socket = sockfd_lookup(sockfd, &err);
		if (!socket)
		if (!socket)
			goto err;
			goto err;


@@ -138,7 +138,7 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,


err:
err:
	spin_unlock_irq(&sdev->ud.lock);
	spin_unlock_irq(&sdev->ud.lock);
	return err;
	return -EINVAL;
}
}
static DEVICE_ATTR(usbip_sockfd, S_IWUSR, NULL, store_sockfd);
static DEVICE_ATTR(usbip_sockfd, S_IWUSR, NULL, store_sockfd);


@@ -208,7 +208,7 @@ static void stub_shutdown_connection(struct usbip_device *ud)
	 * not touch NULL socket.
	 * not touch NULL socket.
	 */
	 */
	if (ud->tcp_socket) {
	if (ud->tcp_socket) {
		fput(ud->tcp_socket->file);
		sockfd_put(ud->tcp_socket);
		ud->tcp_socket = NULL;
		ud->tcp_socket = NULL;
	}
	}


+0 −25
Original line number Original line Diff line number Diff line
@@ -400,31 +400,6 @@ int usbip_recv(struct socket *sock, void *buf, int size)
}
}
EXPORT_SYMBOL_GPL(usbip_recv);
EXPORT_SYMBOL_GPL(usbip_recv);


struct socket *sockfd_to_socket(unsigned int sockfd)
{
	struct socket *socket;
	struct file *file;
	struct inode *inode;

	file = fget(sockfd);
	if (!file) {
		pr_err("invalid sockfd\n");
		return NULL;
	}

	inode = file_inode(file);

	if (!inode || !S_ISSOCK(inode->i_mode)) {
		fput(file);
		return NULL;
	}

	socket = SOCKET_I(inode);

	return socket;
}
EXPORT_SYMBOL_GPL(sockfd_to_socket);

/* there may be more cases to tweak the flags. */
/* there may be more cases to tweak the flags. */
static unsigned int tweak_transfer_flags(unsigned int flags)
static unsigned int tweak_transfer_flags(unsigned int flags)
{
{
+0 −1
Original line number Original line Diff line number Diff line
@@ -314,7 +314,6 @@ void usbip_dump_urb(struct urb *purb);
void usbip_dump_header(struct usbip_header *pdu);
void usbip_dump_header(struct usbip_header *pdu);


int usbip_recv(struct socket *sock, void *buf, int size);
int usbip_recv(struct socket *sock, void *buf, int size);
struct socket *sockfd_to_socket(unsigned int sockfd);


void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
		    int pack);
		    int pack);
+2 −2
Original line number Original line Diff line number Diff line
@@ -789,7 +789,7 @@ static void vhci_shutdown_connection(struct usbip_device *ud)


	/* active connection is closed */
	/* active connection is closed */
	if (vdev->ud.tcp_socket) {
	if (vdev->ud.tcp_socket) {
		fput(vdev->ud.tcp_socket->file);
		sockfd_put(vdev->ud.tcp_socket);
		vdev->ud.tcp_socket = NULL;
		vdev->ud.tcp_socket = NULL;
	}
	}
	pr_info("release socket\n");
	pr_info("release socket\n");
@@ -836,7 +836,7 @@ static void vhci_device_reset(struct usbip_device *ud)
	vdev->udev = NULL;
	vdev->udev = NULL;


	if (ud->tcp_socket) {
	if (ud->tcp_socket) {
		fput(ud->tcp_socket->file);
		sockfd_put(ud->tcp_socket);
		ud->tcp_socket = NULL;
		ud->tcp_socket = NULL;
	}
	}
	ud->status = VDEV_ST_NULL;
	ud->status = VDEV_ST_NULL;
+3 −3
Original line number Original line Diff line number Diff line
@@ -175,6 +175,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
	struct socket *socket;
	struct socket *socket;
	int sockfd = 0;
	int sockfd = 0;
	__u32 rhport = 0, devid = 0, speed = 0;
	__u32 rhport = 0, devid = 0, speed = 0;
	int err;


	/*
	/*
	 * @rhport: port number of vhci_hcd
	 * @rhport: port number of vhci_hcd
@@ -192,8 +193,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
		return -EINVAL;
		return -EINVAL;


	/* Extract socket from fd. */
	/* Extract socket from fd. */
	/* The correct way to clean this up is to fput(socket->file). */
	socket = sockfd_lookup(sockfd, &err);
	socket = sockfd_to_socket(sockfd);
	if (!socket)
	if (!socket)
		return -EINVAL;
		return -EINVAL;


@@ -209,7 +209,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
		spin_unlock(&vdev->ud.lock);
		spin_unlock(&vdev->ud.lock);
		spin_unlock(&the_controller->lock);
		spin_unlock(&the_controller->lock);


		fput(socket->file);
		sockfd_put(socket);


		dev_err(dev, "port %d already used\n", rhport);
		dev_err(dev, "port %d already used\n", rhport);
		return -EINVAL;
		return -EINVAL;