Skip to content

Commit

Permalink
net: wwan: debugfs obtained dev reference not dropped
Browse files Browse the repository at this point in the history
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 <m.chetan.kumar@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
M Chetan Kumar authored and David S. Miller committed Feb 14, 2022
1 parent 1e997d0 commit 76f05d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions drivers/net/wwan/wwan_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/linux/wwan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 76f05d8

Please sign in to comment.