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

Commit 3ff67445 authored by Alexey Khoroshilov's avatar Alexey Khoroshilov Committed by Greg Kroah-Hartman
Browse files

usbip: fix error handling in stub_probe()



If usb_hub_claim_port() fails, no resources are deallocated and
if stub_add_files() fails, port is not released.

The patch fixes these issues and rearranges error handling code.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: default avatarAlexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: default avatarValentina Manea <valentina.manea.m@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 01604026
Loading
Loading
Loading
Loading
+15 −11
Original line number Original line Diff line number Diff line
@@ -311,7 +311,6 @@ static int stub_probe(struct usb_device *udev)
{
{
	struct stub_device *sdev = NULL;
	struct stub_device *sdev = NULL;
	const char *udev_busid = dev_name(&udev->dev);
	const char *udev_busid = dev_name(&udev->dev);
	int err = 0;
	struct bus_id_priv *busid_priv;
	struct bus_id_priv *busid_priv;
	int rc;
	int rc;


@@ -372,23 +371,28 @@ static int stub_probe(struct usb_device *udev)
			(struct usb_dev_state *) udev);
			(struct usb_dev_state *) udev);
	if (rc) {
	if (rc) {
		dev_dbg(&udev->dev, "unable to claim port\n");
		dev_dbg(&udev->dev, "unable to claim port\n");
		return rc;
		goto err_port;
	}
	}


	err = stub_add_files(&udev->dev);
	rc = stub_add_files(&udev->dev);
	if (err) {
	if (rc) {
		dev_err(&udev->dev, "stub_add_files for %s\n", udev_busid);
		dev_err(&udev->dev, "stub_add_files for %s\n", udev_busid);
		goto err_files;
	}
	busid_priv->status = STUB_BUSID_ALLOC;

	return 0;
err_files:
	usb_hub_release_port(udev->parent, udev->portnum,
			     (struct usb_dev_state *) udev);
err_port:
	dev_set_drvdata(&udev->dev, NULL);
	dev_set_drvdata(&udev->dev, NULL);
	usb_put_dev(udev);
	usb_put_dev(udev);
	kthread_stop_put(sdev->ud.eh);
	kthread_stop_put(sdev->ud.eh);


	busid_priv->sdev = NULL;
	busid_priv->sdev = NULL;
	stub_device_free(sdev);
	stub_device_free(sdev);
		return err;
	return rc;
	}
	busid_priv->status = STUB_BUSID_ALLOC;

	return 0;
}
}


static void shutdown_busid(struct bus_id_priv *busid_priv)
static void shutdown_busid(struct bus_id_priv *busid_priv)