scsi: snic: Fix memory leak with using debugfs_lookup()
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Feb 2023 14:10:09 +0000 (15:10 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 8 Feb 2023 23:49:59 +0000 (18:49 -0500)
When calling debugfs_lookup() the result must have dput() called on it,
otherwise the memory will leak over time.  To make things simpler, just
call debugfs_lookup_and_remove() instead which handles all of the logic at
once.

Link: https://lore.kernel.org/r/20230202141009.2290380-1-gregkh@linuxfoundation.org
Cc: Karan Tilak Kumar <kartilak@cisco.com>
Cc: Sesidhar Baddela <sebaddel@cisco.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/snic/snic_debugfs.c

index 57bdc3ba49d9c7ca3ab139a5e966d9c14d47e27c..9dd975b36b5bd5bc8683c97b452846d25fa384f6 100644 (file)
@@ -437,6 +437,6 @@ void snic_trc_debugfs_init(void)
 void
 snic_trc_debugfs_term(void)
 {
-       debugfs_remove(debugfs_lookup(TRC_FILE, snic_glob->trc_root));
-       debugfs_remove(debugfs_lookup(TRC_ENABLE_FILE, snic_glob->trc_root));
+       debugfs_lookup_and_remove(TRC_FILE, snic_glob->trc_root);
+       debugfs_lookup_and_remove(TRC_ENABLE_FILE, snic_glob->trc_root);
 }