[lvc-project] [PATCH v2 2/2] most: usb: hdm_probe: fix calling put_device() before device_initialize()

Victoria Votokina Victoria.Votokina at kaspersky.com
Mon Oct 20 12:28:39 MSK 2025


Early failures in hdm_probe() could jump to err_free_mdev before
&mdev->dev was initialized with device_initialize(), which triggered a
device core WARN and kref_put() on an uninitialized kobject.  Free the
private struct directly in this pre-initialization path.

While here, replace a few unnecessary goto-based unwinds with direct
returns and drop the now-unused err_free_dci label. On
device_register() failure, call put_device(&mdev->dci->dev) before
returning to keep the reference model correct.

This removes the WARNING and simplifies the error paths without changing
the success path behavior.

Fixes: 97a6f772f36b ("drivers: most: add USB adapter driver")
Signed-off-by: Victoria Votokina <Victoria.Votokina at kaspersky.com>
---
v2: Fixed error path for initialized interfaces requiring 
    most_deregister_interface

 drivers/most/most_usb.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
index 3d8163bb7b46d..d139bda166734 100644
--- a/drivers/most/most_usb.c
+++ b/drivers/most/most_usb.c
@@ -1068,8 +1068,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 		if (!mdev->dci) {
 			mutex_unlock(&mdev->io_mutex);
 			most_deregister_interface(&mdev->iface);
-			ret = -ENOMEM;
-			goto err_free_busy_urbs;
+			return -ENOMEM;
 		}
 
 		mdev->dci->dev.init_name = "dci";
@@ -1079,15 +1078,13 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 		if (device_register(&mdev->dci->dev)) {
 			mutex_unlock(&mdev->io_mutex);
 			most_deregister_interface(&mdev->iface);
-			ret = -ENOMEM;
-			goto err_free_dci;
+			put_device(&mdev->dci->dev);
+			return -ENOMEM;
 		}
 		mdev->dci->usb_device = mdev->usb_device;
 	}
 	mutex_unlock(&mdev->io_mutex);
 	return 0;
-err_free_dci:
-	put_device(&mdev->dci->dev);
 err_free_busy_urbs:
 	kfree(mdev->busy_urbs);
 err_free_ep_address:
@@ -1097,7 +1094,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 err_free_conf:
 	kfree(mdev->conf);
 err_free_mdev:
-	put_device(&mdev->dev);
+	kfree(mdev);
 	return ret;
 }
 
-- 
2.30.2




More information about the lvc-project mailing list