[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <582379a6-dea3-482f-86e4-259d4b23204e@web.de>
Date: Wed, 23 Oct 2024 17:27:11 +0200
From: Markus Elfring <Markus.Elfring@....de>
To: linux-fsdevel@...r.kernel.org, Al Viro <viro@...iv.linux.org.uk>,
Joel Granados <joel.granados@...nel.org>, Kees Cook <kees@...nel.org>,
Luis Chamberlain <mcgrof@...nel.org>
Cc: LKML <linux-kernel@...r.kernel.org>, kernel-janitors@...r.kernel.org,
Joel Granados <j.granados@...sung.com>
Subject: [PATCH v2] sysctl: Reduce dput(child) calls in proc_sys_fill_cache()
From: Markus Elfring <elfring@...rs.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@...rs.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
Powered by blists - more mailing lists