Skip to content

Commit 76f05d8

Browse files
mchetankumardavem330
authored andcommitted
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) Signed-off-by: M Chetan Kumar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1e997d0 commit 76f05d8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

drivers/net/wwan/wwan_core.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,42 @@ struct dentry *wwan_get_debugfs_dir(struct device *parent)
160160
return wwandev->debugfs_dir;
161161
}
162162
EXPORT_SYMBOL_GPL(wwan_get_debugfs_dir);
163+
164+
static int wwan_dev_debugfs_match(struct device *dev, const void *dir)
165+
{
166+
struct wwan_device *wwandev;
167+
168+
if (dev->type != &wwan_dev_type)
169+
return 0;
170+
171+
wwandev = to_wwan_dev(dev);
172+
173+
return wwandev->debugfs_dir == dir;
174+
}
175+
176+
static struct wwan_device *wwan_dev_get_by_debugfs(struct dentry *dir)
177+
{
178+
struct device *dev;
179+
180+
dev = class_find_device(wwan_class, NULL, dir, wwan_dev_debugfs_match);
181+
if (!dev)
182+
return ERR_PTR(-ENODEV);
183+
184+
return to_wwan_dev(dev);
185+
}
186+
187+
void wwan_put_debugfs_dir(struct dentry *dir)
188+
{
189+
struct wwan_device *wwandev = wwan_dev_get_by_debugfs(dir);
190+
191+
if (WARN_ON(IS_ERR(wwandev)))
192+
return;
193+
194+
/* wwan_dev_get_by_debugfs() also got a reference */
195+
put_device(&wwandev->dev);
196+
put_device(&wwandev->dev);
197+
}
198+
EXPORT_SYMBOL_GPL(wwan_put_debugfs_dir);
163199
#endif
164200

165201
/* This function allocates and registers a new WWAN device OR if a WWAN device

include/linux/wwan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ void wwan_unregister_ops(struct device *parent);
174174

175175
#ifdef CONFIG_WWAN_DEBUGFS
176176
struct dentry *wwan_get_debugfs_dir(struct device *parent);
177+
void wwan_put_debugfs_dir(struct dentry *dir);
177178
#else
178179
static inline struct dentry *wwan_get_debugfs_dir(struct device *parent)
179180
{
180181
return ERR_PTR(-ENODEV);
181182
}
183+
static inline void wwan_put_debugfs_dir(struct dentry *dir) {}
182184
#endif
183185

184186
#endif /* __WWAN_H */

0 commit comments

Comments
 (0)