Linux filesystem development
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-fsdevel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
	Joel Granados <joel.granados@kernel.org>,
	Kees Cook <kees@kernel.org>, Luis Chamberlain <mcgrof@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Joel Granados <j.granados@samsung.com>
Subject: [PATCH v2] sysctl: Reduce dput(child) calls in proc_sys_fill_cache()
Date: Wed, 23 Oct 2024 17:27:11 +0200	[thread overview]
Message-ID: <582379a6-dea3-482f-86e4-259d4b23204e@web.de> (raw)
In-Reply-To: <t4phgjtexlsw3njituayfa6x5ahzhpvv6vc2m6xk6ffcbzizkl@ybhnpzkhih7z>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 23 Oct 2024 16:54:59 +0200

Replace two dput(child) calls with one that occurs immediately before
the IS_ERR evaluation. This transformation can be performed because
dput() gets called regardless of the value returned by IS_ERR(res).

This issue was transformed by using a script for the
semantic patch language like the following.
<SmPL>
@extended_adjustment@
expression e, f != { mutex_unlock }, x, y;
@@
+f(e);
 if (...)
 {
 <+... when != \( e = x \| y(..., &e, ...) \)
-   f(e);
 ...+>
 }
-f(e);
</SmPL>

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

V2:
* This update suggestion was rebased on source files of the software
  “Linux next-20241023”.

* The change description was adjusted according to the wording preferences
  by Joel Granados.

* An SmPL script example was appended.


 fs/proc/proc_sysctl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 9b9dfc450cb3..b277a1ca392e 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -698,11 +698,11 @@ static bool proc_sys_fill_cache(struct file *file,
 			res = d_splice_alias(inode, child);
 			d_lookup_done(child);
 			if (unlikely(res)) {
-				if (IS_ERR(res)) {
-					dput(child);
-					return false;
-				}
 				dput(child);
+
+				if (IS_ERR(res))
+					return false;
+
 				child = res;
 			}
 		}
--
2.47.0


  reply	other threads:[~2024-10-23 15:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26  8:20 [PATCH] sysctl: Reduce dput(child) calls in proc_sys_fill_cache() Markus Elfring
2024-10-23 11:11 ` Joel Granados
2024-10-23 12:10   ` Markus Elfring
2024-10-23 13:20     ` Joel Granados
2024-10-23 15:27       ` Markus Elfring [this message]
2024-10-28  9:23         ` [PATCH v2] " Joel Granados
2024-10-28 12:56           ` [v2] " Markus Elfring
2024-10-31 10:19         ` [PATCH v2] " Joel Granados

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=582379a6-dea3-482f-86e4-259d4b23204e@web.de \
    --to=markus.elfring@web.de \
    --cc=j.granados@samsung.com \
    --cc=joel.granados@kernel.org \
    --cc=kees@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox