Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Valentina Manea <valentina.manea.m@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alexey Khoroshilov and committed by
Greg Kroah-Hartman
3ff67445 01604026

+15 -11
+15 -11
drivers/usb/usbip/stub_dev.c
··· 311 311 { 312 312 struct stub_device *sdev = NULL; 313 313 const char *udev_busid = dev_name(&udev->dev); 314 - int err = 0; 315 314 struct bus_id_priv *busid_priv; 316 315 int rc; 317 316 ··· 371 372 (struct usb_dev_state *) udev); 372 373 if (rc) { 373 374 dev_dbg(&udev->dev, "unable to claim port\n"); 374 - return rc; 375 + goto err_port; 375 376 } 376 377 377 - err = stub_add_files(&udev->dev); 378 - if (err) { 378 + rc = stub_add_files(&udev->dev); 379 + if (rc) { 379 380 dev_err(&udev->dev, "stub_add_files for %s\n", udev_busid); 380 - dev_set_drvdata(&udev->dev, NULL); 381 - usb_put_dev(udev); 382 - kthread_stop_put(sdev->ud.eh); 383 - 384 - busid_priv->sdev = NULL; 385 - stub_device_free(sdev); 386 - return err; 381 + goto err_files; 387 382 } 388 383 busid_priv->status = STUB_BUSID_ALLOC; 389 384 390 385 return 0; 386 + err_files: 387 + usb_hub_release_port(udev->parent, udev->portnum, 388 + (struct usb_dev_state *) udev); 389 + err_port: 390 + dev_set_drvdata(&udev->dev, NULL); 391 + usb_put_dev(udev); 392 + kthread_stop_put(sdev->ud.eh); 393 + 394 + busid_priv->sdev = NULL; 395 + stub_device_free(sdev); 396 + return rc; 391 397 } 392 398 393 399 static void shutdown_busid(struct bus_id_priv *busid_priv)