Patch "drivers: base: transport_class: fix resource leak when transport_add_device() fails" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    drivers: base: transport_class: fix resource leak when transport_add_device() fails

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     drivers-base-transport_class-fix-resource-leak-when-.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 079733fd7c74480ce78c3d3e0e589f85f55bde35
Author: Yang Yingliang <yangyingliang@xxxxxxxxxx>
Date:   Tue Nov 15 11:16:38 2022 +0800

    drivers: base: transport_class: fix resource leak when transport_add_device() fails
    
    [ Upstream commit e5da06b27ff5a148e42265c8e306670a9d913969 ]
    
    The normal call sequence of using transport class is:
    
    Add path:
    transport_setup_device()
      transport_setup_classdev()  // call sas_host_setup() here
    transport_add_device()        // if fails, need call transport_destroy_device()
    transport_configure_device()
    
    Remove path:
    transport_remove_device()
      transport_remove_classdev  // call sas_host_remove() here
    transport_destroy_device()
    
    If transport_add_device() fails, need call transport_destroy_device()
    to free memory, but in this case, ->remove() is not called, and the
    resources allocated in ->setup() are leaked. So fix these leaks by
    calling ->remove() in transport_add_class_device() if it returns error.
    
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221115031638.3816551-1-yangyingliang@xxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/base/transport_class.c b/drivers/base/transport_class.c
index ccc86206e5087..09ee2a1e35bbd 100644
--- a/drivers/base/transport_class.c
+++ b/drivers/base/transport_class.c
@@ -155,12 +155,27 @@ static int transport_add_class_device(struct attribute_container *cont,
 				      struct device *dev,
 				      struct device *classdev)
 {
+	struct transport_class *tclass = class_to_transport_class(cont->class);
 	int error = attribute_container_add_class_device(classdev);
 	struct transport_container *tcont = 
 		attribute_container_to_transport_container(cont);
 
-	if (!error && tcont->statistics)
+	if (error)
+		goto err_remove;
+
+	if (tcont->statistics) {
 		error = sysfs_create_group(&classdev->kobj, tcont->statistics);
+		if (error)
+			goto err_del;
+	}
+
+	return 0;
+
+err_del:
+	attribute_container_class_device_del(classdev);
+err_remove:
+	if (tclass->remove)
+		tclass->remove(tcont, dev, classdev);
 
 	return error;
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux