[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190224105157.GF2759@nanopsycho.orion>
Date: Sun, 24 Feb 2019 11:51:57 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: Jakub Kicinski <jakub.kicinski@...ronome.com>
Cc: davem@...emloft.net, mkubecek@...e.cz, andrew@...n.ch,
f.fainelli@...il.com, netdev@...r.kernel.org,
oss-drivers@...ronome.com
Subject: Re: [PATCH net-next v3 2/6] devlink: create a special NDO for
getting the devlink instance
Fri, Feb 22, 2019 at 11:07:53PM CET, jakub.kicinski@...ronome.com wrote:
>Instead of iterating over all devlink ports add a NDO which
>will return the devlink instance from the driver.
>
>v2: add the netdev_to_devlink() helper (Michal)
>v3: check that devlink has ops (Florian)
>
>Suggested-by: Jiri Pirko <jiri@...nulli.us>
>Signed-off-by: Jakub Kicinski <jakub.kicinski@...ronome.com>
>Reviewed-by: Florian Fainelli <f.fainelli@...il.com>
[...]
> void devlink_compat_running_version(struct net_device *dev,
> char *buf, size_t len)
> {
>- struct devlink_port *devlink_port;
> struct devlink *devlink;
>
>- mutex_lock(&devlink_mutex);
>- list_for_each_entry(devlink, &devlink_list, list) {
>- mutex_lock(&devlink->lock);
>- list_for_each_entry(devlink_port, &devlink->port_list, list) {
>- if (devlink_port->type == DEVLINK_PORT_TYPE_ETH &&
>- devlink_port->type_dev == dev) {
>- __devlink_compat_running_version(devlink,
>- buf, len);
>- mutex_unlock(&devlink->lock);
>- goto out;
>- }
>- }
>- mutex_unlock(&devlink->lock);
>- }
>-out:
>- mutex_unlock(&devlink_mutex);
>+ devlink = netdev_to_devlink(dev);
What prevents devlink from being unregistered now from another thread?
I think you should hold &devlink_mutex here to prevent it.
>+ if (!devlink || !devlink->ops || !devlink->ops->info_get)
>+ return;
>+
>+ mutex_lock(&devlink->lock);
>+ __devlink_compat_running_version(devlink, buf, len);
>+ mutex_unlock(&devlink->lock);
> }
>
> int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
> {
>- struct devlink_port *devlink_port;
> struct devlink *devlink;
>+ int ret;
>
>- mutex_lock(&devlink_mutex);
>- list_for_each_entry(devlink, &devlink_list, list) {
>- mutex_lock(&devlink->lock);
>- list_for_each_entry(devlink_port, &devlink->port_list, list) {
>- int ret = -EOPNOTSUPP;
>-
>- if (devlink_port->type != DEVLINK_PORT_TYPE_ETH ||
>- devlink_port->type_dev != dev)
>- continue;
>-
>- mutex_unlock(&devlink_mutex);
>- if (devlink->ops->flash_update)
>- ret = devlink->ops->flash_update(devlink,
>- file_name,
>- NULL, NULL);
>- mutex_unlock(&devlink->lock);
>- return ret;
>- }
>- mutex_unlock(&devlink->lock);
>- }
>- mutex_unlock(&devlink_mutex);
>+ devlink = netdev_to_devlink(dev);
Same here.
>+ if (!devlink || !devlink->ops || !devlink->ops->flash_update)
>+ return -EOPNOTSUPP;
>
>- return -EOPNOTSUPP;
>+ mutex_lock(&devlink->lock);
>+ ret = devlink->ops->flash_update(devlink, file_name, NULL, NULL);
>+ mutex_unlock(&devlink->lock);
>+ return ret;
> }
>
> static int __init devlink_init(void)
>--
>2.19.2
>
Powered by blists - more mailing lists