]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.4-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 10 Sep 2022 06:26:56 +0000 (08:26 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 10 Sep 2022 06:26:56 +0000 (08:26 +0200)
added patches:
debugfs-add-debugfs_lookup_and_remove.patch

queue-5.4/debugfs-add-debugfs_lookup_and_remove.patch [new file with mode: 0644]
queue-5.4/series

diff --git a/queue-5.4/debugfs-add-debugfs_lookup_and_remove.patch b/queue-5.4/debugfs-add-debugfs_lookup_and_remove.patch
new file mode 100644 (file)
index 0000000..147058e
--- /dev/null
@@ -0,0 +1,79 @@
+From dec9b2f1e0455a151a7293c367da22ab973f713e Mon Sep 17 00:00:00 2001
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Date: Fri, 2 Sep 2022 16:59:15 +0200
+Subject: debugfs: add debugfs_lookup_and_remove()
+
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+commit dec9b2f1e0455a151a7293c367da22ab973f713e upstream.
+
+There is a very common pattern of using
+debugfs_remove(debufs_lookup(..)) which results in a dentry leak of the
+dentry that was looked up.  Instead of having to open-code the correct
+pattern of calling dput() on the dentry, create
+debugfs_lookup_and_remove() to handle this pattern automatically and
+properly without any memory leaks.
+
+Cc: stable <stable@kernel.org>
+Reported-by: Kuyo Chang <kuyo.chang@mediatek.com>
+Tested-by: Kuyo Chang <kuyo.chang@mediatek.com>
+Link: https://lore.kernel.org/r/YxIaQ8cSinDR881k@kroah.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ fs/debugfs/inode.c      |   22 ++++++++++++++++++++++
+ include/linux/debugfs.h |    6 ++++++
+ 2 files changed, 28 insertions(+)
+
+--- a/fs/debugfs/inode.c
++++ b/fs/debugfs/inode.c
+@@ -743,6 +743,28 @@ void debugfs_remove(struct dentry *dentr
+ EXPORT_SYMBOL_GPL(debugfs_remove);
+ /**
++ * debugfs_lookup_and_remove - lookup a directory or file and recursively remove it
++ * @name: a pointer to a string containing the name of the item to look up.
++ * @parent: a pointer to the parent dentry of the item.
++ *
++ * This is the equlivant of doing something like
++ * debugfs_remove(debugfs_lookup(..)) but with the proper reference counting
++ * handled for the directory being looked up.
++ */
++void debugfs_lookup_and_remove(const char *name, struct dentry *parent)
++{
++      struct dentry *dentry;
++
++      dentry = debugfs_lookup(name, parent);
++      if (!dentry)
++              return;
++
++      debugfs_remove(dentry);
++      dput(dentry);
++}
++EXPORT_SYMBOL_GPL(debugfs_lookup_and_remove);
++
++/**
+  * debugfs_remove_recursive - recursively removes a directory
+  * @dentry: a pointer to a the dentry of the directory to be removed.  If this
+  *          parameter is NULL or an error value, nothing will be done.
+--- a/include/linux/debugfs.h
++++ b/include/linux/debugfs.h
+@@ -85,6 +85,8 @@ struct dentry *debugfs_create_automount(
+ void debugfs_remove(struct dentry *dentry);
+ void debugfs_remove_recursive(struct dentry *dentry);
++void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
++
+ const struct file_operations *debugfs_real_fops(const struct file *filp);
+ int debugfs_file_get(struct dentry *dentry);
+@@ -216,6 +218,10 @@ static inline void debugfs_remove(struct
+ static inline void debugfs_remove_recursive(struct dentry *dentry)
+ { }
++static inline void debugfs_lookup_and_remove(const char *name,
++                                           struct dentry *parent)
++{ }
++
+ const struct file_operations *debugfs_real_fops(const struct file *filp);
+ static inline int debugfs_file_get(struct dentry *dentry)
index 2569cc42b4fcb17e92dc0b83bc6d1347aaa3e312..c4af72dd51efc54daf9a589840a9872184b8a06e 100644 (file)
@@ -78,3 +78,4 @@ alsa-emu10k1-fix-out-of-bounds-access-in-snd_emu10k1_pcm_channel_alloc.patch
 alsa-aloop-fix-random-zeros-in-capture-data-when-using-jiffies-timer.patch
 alsa-usb-audio-fix-an-out-of-bounds-bug-in-__snd_usb_parse_audio_interface.patch
 kprobes-prohibit-probes-in-gate-area.patch
+debugfs-add-debugfs_lookup_and_remove.patch