diff mbox series

trace/blktrace: fix memory leak with using debugfs_lookup()

Message ID 20230202141956.2299521-1-gregkh@linuxfoundation.org (mailing list archive)
State Handled Elsewhere
Headers show
Series trace/blktrace: fix memory leak with using debugfs_lookup() | expand

Commit Message

Greg Kroah-Hartman Feb. 2, 2023, 2:19 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: Jens Axboe <axboe@kernel.dk>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-trace-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 kernel/trace/blktrace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bart Van Assche Feb. 4, 2023, 11:17 p.m. UTC | #1
On 2/2/23 06:19, 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.
> 
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: linux-block@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-trace-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>   kernel/trace/blktrace.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index 918a7d12df8f..5743be559415 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -320,8 +320,8 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
>   	 * under 'q->debugfs_dir', thus lookup and remove them.
>   	 */
>   	if (!bt->dir) {
> -		debugfs_remove(debugfs_lookup("dropped", q->debugfs_dir));
> -		debugfs_remove(debugfs_lookup("msg", q->debugfs_dir));
> +		debugfs_lookup_and_remove("dropped", q->debugfs_dir);
> +		debugfs_lookup_and_remove("msg", q->debugfs_dir);
>   	} else {
>   		debugfs_remove(bt->dir);
>   	}

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Jens Axboe Feb. 6, 2023, 4:29 p.m. UTC | #2
On Thu, 02 Feb 2023 15:19:56 +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, thanks!

[1/1] trace/blktrace: fix memory leak with using debugfs_lookup()
      commit: 83e8864fee26f63a7435e941b7c36a20fd6fe93e

Best regards,
diff mbox series

Patch

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 918a7d12df8f..5743be559415 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -320,8 +320,8 @@  static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
 	 * under 'q->debugfs_dir', thus lookup and remove them.
 	 */
 	if (!bt->dir) {
-		debugfs_remove(debugfs_lookup("dropped", q->debugfs_dir));
-		debugfs_remove(debugfs_lookup("msg", q->debugfs_dir));
+		debugfs_lookup_and_remove("dropped", q->debugfs_dir);
+		debugfs_lookup_and_remove("msg", q->debugfs_dir);
 	} else {
 		debugfs_remove(bt->dir);
 	}