scsi: snic: fix memory leak with using debugfs_lookup()

Message ID 20230202141009.2290380-1-gregkh@linuxfoundation.org
State New
Headers
Series scsi: snic: fix memory leak with using debugfs_lookup() |

Commit Message

Greg KH Feb. 2, 2023, 2:10 p.m. UTC
  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.

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>
---
 drivers/scsi/snic/snic_debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Martin K. Petersen Feb. 8, 2023, 11:50 p.m. UTC | #1
Greg,

> 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.

Applied to 6.3/scsi-staging, thanks!
  
Greg KH Feb. 9, 2023, 12:27 p.m. UTC | #2
On Wed, Feb 08, 2023 at 06:50:53PM -0500, Martin K. Petersen wrote:
> 
> Greg,
> 
> > 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.
> 
> Applied to 6.3/scsi-staging, thanks!

Wonderful, thank you!
  
Martin K. Petersen Feb. 14, 2023, 4:57 p.m. UTC | #3
On Thu, 02 Feb 2023 15:10:09 +0100, Greg Kroah-Hartman wrote:

> 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.
> 
> 

Applied to 6.3/scsi-queue, thanks!

[1/1] scsi: snic: fix memory leak with using debugfs_lookup()
      https://git.kernel.org/mkp/scsi/c/ad0e4e2fab92
  

Patch

diff --git a/drivers/scsi/snic/snic_debugfs.c b/drivers/scsi/snic/snic_debugfs.c
index 57bdc3ba49d9..9dd975b36b5b 100644
--- a/drivers/scsi/snic/snic_debugfs.c
+++ b/drivers/scsi/snic/snic_debugfs.c
@@ -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);
 }