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: 51954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp272371wrn; Thu, 2 Feb 2023 06:31:52 -0800 (PST) X-Google-Smtp-Source: AK7set/wzVNMSHdk+GGpDnKz3vTx+Zylo+z2RJOn/7nCmtJ4ezWRTZfBhTjuAkVM/y8H3SQYbmyA X-Received: by 2002:a17:907:7211:b0:88d:ba89:184f with SMTP id dr17-20020a170907721100b0088dba89184fmr2663156ejc.32.1675348312078; Thu, 02 Feb 2023 06:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675348312; cv=none; d=google.com; s=arc-20160816; b=zW/LrbJZYwAkpo/ujYws4e28wthvtkK7G6+1hiCHEkOiYypQeYGiJNhFjdg80oE019 T0W9aLIjd30TZQ/4mBDXl952NaEMpsQhsrbaIMhxZTKwmcvqXh2e2beGc9J0Dz1OED0l P6jTMBF6fvhEEc2aoRDNPAyEEJYedK4WwCfIJ1Tv9qb22JWg3EbdGjX3TEUUYQQi6bMv fKOaGN7gj6fj5ipwdwaopcu+FgyDzQ3/Ek2MThW4Vf6B1J3+KN7qkLay5FA0Lmo/G0Yz nUU2nCppVn6SPCKd7h2cJv2hZgnSEUufohKAoiOXLm/GvMfmtfgXXvA+CofZUICTVVR7 87gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=cIHri4ggR0umtD3oLQiOVNjssoscEB1UXe4smu1IblI=; b=ef0/49nvJbQq+EiQZlKDLcgrRnlb/QnpnthgsXOzHbKoVgbhGaj427Nf0OufVq7WX6 HWBb2w78fbWrzPhJYb9xPaLd8EvSr55A/hC8JA9nGyqj7DXo1EuR5h20/yw5Q0/lUU2q q7Ut8Tjsl0vuDGzpTsULKY2D4t/ETkinA6XOiTk76EYfP8gj+x1aEmrPjl07OthG+A4h 4F5133Pas51VVueSEeivzHj9ghRAlUwkdPsYkWVv/nOxF1p8icm0s2sOT5tRU4YNBCcm 9olBBfn7HeQKXwRmDrmQaiulvXhR1KZQ7hOXt0GRm8bQm5X37qonkAsajhXggUh2s3Av Kg7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bNZJn+s5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fe19-20020a1709072a5300b0088d11b71f97si7439485ejc.324.2023.02.02.06.31.14; Thu, 02 Feb 2023 06:31:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bNZJn+s5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232361AbjBBOUD (ORCPT + 99 others); Thu, 2 Feb 2023 09:20:03 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756730031634163656?= X-GMAIL-MSGID: =?utf-8?q?1756730031634163656?= 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); }