[PATCH 1/1] staging: fwserial: fix resource leak

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

 



From: Vladimirs Ambrosovs <rodriguez.twister@xxxxxxxxx>

This patch fixes the leak, which was present in fwserial driver in the
init function. in case the tty driver allocation failed the function
returned error, leaving debugfs entry in the filesystem.

To fix the issue additional error label was added, so that the code will
jump to it in case of allocation failure, and free debugfs entries.

Also, the additional check for debugfs_create_dir() return value was 
added to warn the user, that the directory was not created. Further
driver code checks, whether the value is NULL or not, so it is safe
to continue init.

Signed-off-by: Vladimirs Ambrosovs <rodriguez.twister@xxxxxxxxx>
---
 drivers/staging/fwserial/fwserial.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index fdb2418..27a1d77 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -2812,16 +2812,25 @@ static int __init fwserial_init(void)
 	/* XXX: placeholder for a "firewire" debugfs node */
 	fwserial_debugfs = debugfs_create_dir(KBUILD_MODNAME, NULL);
 
+	/* Don't need to return error if debugfs create dir failed, since
+	 * it is safe to continue without debugfs entry. It is being
+	 * checked further in the code, before usage, but we still want
+	 * to inform the user
+	 */
+	if (unlikely(IS_ERR_OR_NULL(fwserial_debugfs)))
+		pr_warn("failed to create debugfs entry\n");
+
 	/* num_ttys/num_ports must not be set above the static alloc avail */
 	if (num_ttys + num_loops > MAX_CARD_PORTS)
 		num_ttys = MAX_CARD_PORTS - num_loops;
+
 	num_ports = num_ttys + num_loops;
 
 	fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW
 					| TTY_DRIVER_DYNAMIC_DEV);
 	if (IS_ERR(fwtty_driver)) {
 		err = PTR_ERR(fwtty_driver);
-		return err;
+		goto remove_debugfs;
 	}
 
 	fwtty_driver->driver_name	= KBUILD_MODNAME;
@@ -2923,7 +2932,9 @@ unregister_driver:
 	tty_unregister_driver(fwtty_driver);
 put_tty:
 	put_tty_driver(fwtty_driver);
+remove_debugfs:
 	debugfs_remove_recursive(fwserial_debugfs);
+
 	return err;
 }
 
-- 
2.0.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux