Skip to contentSkip to conversation

net: wwan: debugfs dev reference not dropped

PATCH Applied M Chetan Kumar 2 participants 4 messages Feb 14, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover net: wwan: debugfs dev reference not dropped

This patch series contains WWAN subsystem & IOSM Driver changes to drop dev reference obtained as part of wwan debugfs dir entry retrieval.

PATCH1: A new debugfs interface is introduced in wwan subsystem so that wwan driver can drop the obtained dev reference post debugfs use.

PATCH2: IOSM Driver uses new debugfs interface to drop dev reference.

Please refer to commit messages for details.

M Chetan Kumar (2):
net: wwan: debugfs obtained dev reference not dropped
net: wwan: iosm: drop debugfs dev reference

 drivers/net/wwan/iosm/iosm_ipc_debugfs.c |  5 ++--
 drivers/net/wwan/iosm/iosm_ipc_imem.h    |  2 ++
 drivers/net/wwan/wwan_core.c             | 35 ++++++++++++++++++++++++
 include/linux/wwan.h                     |  2 ++
 4 files changed, 42 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 net: wwan: debugfs obtained dev reference not dropped

WWAN driver call's wwan_get_debugfs_dir() to obtain WWAN debugfs dir entry. As part of this procedure it returns a reference to a found device.

Since there is no debugfs interface available at WWAN subsystem, it is not possible to drop dev reference post debugfs use. This leads to side effects like post wwan driver load and reload the wwan instance gets increment from wwanX to wwanX+1.

A new debugfs interface is added in wwan subsystem so that wwan driver can drop the obtained dev reference post debugfs use.

void wwan_put_debugfs_dir(struct dentry *dir)

---
 drivers/net/wwan/wwan_core.c | 35 +++++++++++++++++++++++++++++++++++
 include/linux/wwan.h         |  2 ++
 2 files changed, 37 insertions(+)
drivers/net/wwan/wwan_core.c +36 -0
index 1508dc2a497b..147b88464cbd 100644
@@ -160,6 +160,42 @@ struct dentry *wwan_get_debugfs_dir(struct device *parent)
 	return wwandev->debugfs_dir;
 }
 EXPORT_SYMBOL_GPL(wwan_get_debugfs_dir);
+
+static int wwan_dev_debugfs_match(struct device *dev, const void *dir)
+{
+	struct wwan_device *wwandev;
+
+	if (dev->type != &wwan_dev_type)
+		return 0;
+
+	wwandev = to_wwan_dev(dev);
+
+	return wwandev->debugfs_dir == dir;
+}
+
+static struct wwan_device *wwan_dev_get_by_debugfs(struct dentry *dir)
+{
+	struct device *dev;
+
+	dev = class_find_device(wwan_class, NULL, dir, wwan_dev_debugfs_match);
+	if (!dev)
+		return ERR_PTR(-ENODEV);
+
+	return to_wwan_dev(dev);
+}
+
+void wwan_put_debugfs_dir(struct dentry *dir)
+{
+	struct wwan_device *wwandev = wwan_dev_get_by_debugfs(dir);
+
+	if (WARN_ON(IS_ERR(wwandev)))
+		return;
+
+	/* wwan_dev_get_by_debugfs() also got a reference */
+	put_device(&wwandev->dev);
+	put_device(&wwandev->dev);
+}
+EXPORT_SYMBOL_GPL(wwan_put_debugfs_dir);
 #endif
 
 /* This function allocates and registers a new WWAN device OR if a WWAN device
include/linux/wwan.h +2 -0
index afb3334ec8c5..5ce2acf444fb 100644
@@ -174,11 +174,13 @@ void wwan_unregister_ops(struct device *parent);
 
 #ifdef CONFIG_WWAN_DEBUGFS
 struct dentry *wwan_get_debugfs_dir(struct device *parent);
+void wwan_put_debugfs_dir(struct dentry *dir);
 #else
 static inline struct dentry *wwan_get_debugfs_dir(struct device *parent)
 {
 	return ERR_PTR(-ENODEV);
 }
+static inline void wwan_put_debugfs_dir(struct dentry *dir) {}
 #endif
 
 #endif /* __WWAN_H */
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 net: wwan: iosm: drop debugfs dev reference

In reply to M Chetan Kumar

Post debugfs use call wwan_put_debugfs_dir()to drop debugfs dev reference.

---
 drivers/net/wwan/iosm/iosm_ipc_debugfs.c | 5 +++--
 drivers/net/wwan/iosm/iosm_ipc_imem.h    | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_debugfs.c +3 -2
index f2f57751a7d2..e916139b8cd4 100644
@@ -12,10 +12,10 @@
 
 void ipc_debugfs_init(struct iosm_imem *ipc_imem)
 {
-	struct dentry *debugfs_pdev = wwan_get_debugfs_dir(ipc_imem->dev);
+	ipc_imem->debugfs_wwan_dir = wwan_get_debugfs_dir(ipc_imem->dev);
 
 	ipc_imem->debugfs_dir = debugfs_create_dir(KBUILD_MODNAME,
-						   debugfs_pdev);
+						   ipc_imem->debugfs_wwan_dir);
 
 	ipc_imem->trace = ipc_trace_init(ipc_imem);
 	if (!ipc_imem->trace)
@@ -26,4 +26,5 @@ void ipc_debugfs_deinit(struct iosm_imem *ipc_imem)
 {
 	ipc_trace_deinit(ipc_imem->trace);
 	debugfs_remove_recursive(ipc_imem->debugfs_dir);
+	wwan_put_debugfs_dir(ipc_imem->debugfs_wwan_dir);
 }
drivers/net/wwan/iosm/iosm_ipc_imem.h +2 -0
index 5682e8d6be7b..e700dc8bfe0a 100644
@@ -341,6 +341,7 @@ enum ipc_phase {
  * @ev_mux_net_transmit_pending:0 means inform the IPC tasklet to pass
  * @reset_det_n:		Reset detect flag
  * @pcie_wake_n:		Pcie wake flag
+ * @debugfs_wwan_dir:		WWAN Debug FS directory entry
  * @debugfs_dir:		Debug FS directory for driver-specific entries
  */
 struct iosm_imem {
@@ -384,6 +385,7 @@ struct iosm_imem {
 	   reset_det_n:1,
 	   pcie_wake_n:1;
 #ifdef CONFIG_WWAN_DEBUGFS
+	struct dentry *debugfs_wwan_dir;
 	struct dentry *debugfs_dir;
 #endif
 };
Signature · 1 line
2.25.1
#3 lore raw
In reply to M Chetan Kumar
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Mon, 14 Feb 2022 12:46:51 +0530 you wrote:

This patch series contains WWAN subsystem & IOSM Driver changes to drop dev reference obtained as part of wwan debugfs dir entry retrieval.

PATCH1: A new debugfs interface is introduced in wwan subsystem so that wwan driver can drop the obtained dev reference post debugfs use.

PATCH2: IOSM Driver uses new debugfs interface to drop dev reference.

[...]

Here is the summary with links:
- [net-next,1/2] net: wwan: debugfs obtained dev reference not dropped

    https://git.kernel.org/netdev/net-next/c/76f05d88623e
  - [net-next,2/2] net: wwan: iosm: drop debugfs dev reference
    https://git.kernel.org/netdev/net-next/c/163f69ae22e5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html