From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: davem@davemloft.net, jiri@resnulli.us
Cc: mkubecek@suse.cz, andrew@lunn.ch, f.fainelli@gmail.com,
netdev@vger.kernel.org, oss-drivers@netronome.com,
Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCH net-next v3 5/6] devlink: hold a reference to the netdevice around ethtool compat
Date: Fri, 22 Feb 2019 14:07:56 -0800 [thread overview]
Message-ID: <20190222220758.7117-6-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20190222220758.7117-1-jakub.kicinski@netronome.com>
When ethtool is calling into devlink compat code make sure we have
a reference on the netdevice on which the operation was invoked.
v3: move the hold/lock logic into devlink_compat_* functions (Florian)
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
net/core/devlink.c | 34 +++++++++++++++++++++++-----------
net/core/ethtool.c | 13 ++-----------
2 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/net/core/devlink.c b/net/core/devlink.c
index a13055160be0..78c6ea1870ca 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -6430,27 +6430,39 @@ void devlink_compat_running_version(struct net_device *dev,
{
struct devlink *devlink;
+ dev_hold(dev);
+ rtnl_unlock();
+
devlink = netdev_to_devlink(dev);
- if (!devlink || !devlink->ops || !devlink->ops->info_get)
- return;
+ if (devlink && devlink->ops && devlink->ops->info_get) {
+ mutex_lock(&devlink->lock);
+ __devlink_compat_running_version(devlink, buf, len);
+ mutex_unlock(&devlink->lock);
+ }
- mutex_lock(&devlink->lock);
- __devlink_compat_running_version(devlink, buf, len);
- mutex_unlock(&devlink->lock);
+ rtnl_lock();
+ dev_put(dev);
}
int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
{
struct devlink *devlink;
- int ret;
+ int ret = -EOPNOTSUPP;
+
+ dev_hold(dev);
+ rtnl_unlock();
devlink = netdev_to_devlink(dev);
- if (!devlink || !devlink->ops || !devlink->ops->flash_update)
- return -EOPNOTSUPP;
+ if (devlink && devlink->ops && devlink->ops->flash_update) {
+ mutex_lock(&devlink->lock);
+ ret = devlink->ops->flash_update(devlink, file_name,
+ NULL, NULL);
+ mutex_unlock(&devlink->lock);
+ }
+
+ rtnl_lock();
+ dev_put(dev);
- mutex_lock(&devlink->lock);
- ret = devlink->ops->flash_update(devlink, file_name, NULL, NULL);
- mutex_unlock(&devlink->lock);
return ret;
}
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 1320e8dce559..47558ffae423 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -805,11 +805,9 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
if (ops->get_eeprom_len)
info.eedump_len = ops->get_eeprom_len(dev);
- rtnl_unlock();
if (!info.fw_version[0])
devlink_compat_running_version(dev, info.fw_version,
sizeof(info.fw_version));
- rtnl_lock();
if (copy_to_user(useraddr, &info, sizeof(info)))
return -EFAULT;
@@ -2040,15 +2038,8 @@ static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
return -EFAULT;
efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
- if (!dev->ethtool_ops->flash_device) {
- int ret;
-
- rtnl_unlock();
- ret = devlink_compat_flash_update(dev, efl.data);
- rtnl_lock();
-
- return ret;
- }
+ if (!dev->ethtool_ops->flash_device)
+ return devlink_compat_flash_update(dev, efl.data);
return dev->ethtool_ops->flash_device(dev, &efl);
}
--
2.19.2
next prev parent reply other threads:[~2019-02-22 22:15 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 22:07 [PATCH net-next v3 0/6] devlink: make ethtool compat reliable Jakub Kicinski
2019-02-22 22:07 ` [PATCH net-next v3 1/6] net: devlink: turn devlink into a built-in Jakub Kicinski
2019-02-24 10:46 ` Jiri Pirko
2019-02-22 22:07 ` [PATCH net-next v3 2/6] devlink: create a special NDO for getting the devlink instance Jakub Kicinski
2019-02-24 10:51 ` Jiri Pirko
2019-02-22 22:07 ` [PATCH net-next v3 3/6] nfp: add .ndo_get_devlink Jakub Kicinski
2019-02-24 10:52 ` Jiri Pirko
2019-02-25 2:05 ` Florian Fainelli
2019-02-22 22:07 ` [PATCH net-next v3 4/6] nfp: remove ethtool flashing fallback Jakub Kicinski
2019-02-24 10:53 ` Jiri Pirko
2019-02-25 2:06 ` Florian Fainelli
2019-02-22 22:07 ` Jakub Kicinski [this message]
2019-02-24 11:00 ` [PATCH net-next v3 5/6] devlink: hold a reference to the netdevice around ethtool compat Jiri Pirko
2019-02-25 18:31 ` Jakub Kicinski
2019-02-26 3:07 ` Jakub Kicinski
2019-02-26 6:50 ` Jiri Pirko
2019-02-22 22:07 ` [PATCH net-next v3 6/6] devlink: add missing NULL checks for devlink ops Jakub Kicinski
2019-02-24 11:03 ` Jiri Pirko
2019-02-25 18:32 ` Jakub Kicinski
2019-02-26 6:50 ` Jiri Pirko
2019-02-25 1:43 ` [PATCH net-next v3 0/6] devlink: make ethtool compat reliable David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190222220758.7117-6-jakub.kicinski@netronome.com \
--to=jakub.kicinski@netronome.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=jiri@resnulli.us \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).