From patchwork Thu Feb 2 14:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 13126144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1884C636D4 for ; Thu, 2 Feb 2023 14:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232354AbjBBOUC (ORCPT ); Thu, 2 Feb 2023 09:20:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjBBOUB (ORCPT ); Thu, 2 Feb 2023 09:20:01 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 301378E687; Thu, 2 Feb 2023 06:20:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C230B617D1; Thu, 2 Feb 2023 14:20:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98C29C433D2; Thu, 2 Feb 2023 14:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675347600; bh=K15Vvy6+BvWfLlwuCjyeWnreBztTdkQml9K8G93FCxc=; h=From:To:Cc:Subject:Date:From; b=bNZJn+s5epbkGQO5tuPYRj8Ru5lkmBsX5iynUtpgvY39sRNoiBsQTgUuVB0mwzdVV Z6W2iO+ZwJ8XTwOaPVBLq9Lls//LfWqNF7FmAqbeEgfqzzdJro7tLAlSd9dZS3ZBbb kv8zqJ4zDC3zTR2JGi2bSQqitRohr1tpuImmUoV4= From: Greg Kroah-Hartman To: linux-trace-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Jens Axboe , Steven Rostedt , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] trace/blktrace: fix memory leak with using debugfs_lookup() Date: Thu, 2 Feb 2023 15:19:56 +0100 Message-Id: <20230202141956.2299521-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1254; i=gregkh@linuxfoundation.org; h=from:subject; bh=K15Vvy6+BvWfLlwuCjyeWnreBztTdkQml9K8G93FCxc=; b=owGbwMvMwCRo6H6F97bub03G02pJDMm3j3XvOlXx3Ov0X0/fIx/aW3/sDp23Y/Jz4wVauh/FL4pE iz0z6ohlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJyBswLLhaUyb26KmgZ9mt6RyzUx tfGLVEfmJYsErxTmvxjOJA8f8pBzkSVDftC+HxAQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org 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 Cc: Steven Rostedt Cc: Masami Hiramatsu 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 Reviewed-by: Bart Van Assche --- 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); }