netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: davem@davemloft.net, jiri@resnulli.us, andrew@lunn.ch,
	f.fainelli@gmail.com, netdev@vger.kernel.org,
	oss-drivers@netronome.com
Subject: Re: [PATCH net-next 4/5] nfp: add .ndo_get_devlink
Date: Fri, 22 Feb 2019 11:04:50 +0100	[thread overview]
Message-ID: <20190222100450.GR23151@unicorn.suse.cz> (raw)
In-Reply-To: <20190221174620.12144-5-jakub.kicinski@netronome.com>

On Thu, Feb 21, 2019 at 09:46:19AM -0800, Jakub Kicinski wrote:
> Support getting devlink instance from a new NDO.
> 
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> ---
>  drivers/net/ethernet/netronome/nfp/nfp_app.h        |  2 ++
>  drivers/net/ethernet/netronome/nfp/nfp_devlink.c    | 11 +++++++++++
>  drivers/net/ethernet/netronome/nfp/nfp_net_common.c |  1 +
>  drivers/net/ethernet/netronome/nfp/nfp_net_repr.c   |  1 +
>  4 files changed, 15 insertions(+)
> 
> diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.h b/drivers/net/ethernet/netronome/nfp/nfp_app.h
> index d578d856a009..f8d422713705 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfp_app.h
> +++ b/drivers/net/ethernet/netronome/nfp/nfp_app.h
> @@ -433,4 +433,6 @@ int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
>  int nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
>  				   struct nfp_net *nn, unsigned int id);
>  
> +struct devlink *nfp_devlink_get_devlink(struct net_device *netdev);
> +
>  #endif
> diff --git a/drivers/net/ethernet/netronome/nfp/nfp_devlink.c b/drivers/net/ethernet/netronome/nfp/nfp_devlink.c
> index db2da99f6aa7..e9eca99cf493 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfp_devlink.c
> +++ b/drivers/net/ethernet/netronome/nfp/nfp_devlink.c
> @@ -376,3 +376,14 @@ void nfp_devlink_port_unregister(struct nfp_port *port)
>  {
>  	devlink_port_unregister(&port->dl_port);
>  }
> +
> +struct devlink *nfp_devlink_get_devlink(struct net_device *netdev)
> +{
> +	struct nfp_app *app;
> +
> +	app = nfp_app_from_netdev(netdev);
> +	if (!app)
> +		return NULL;
> +
> +	return priv_to_devlink(app->pf);
> +}

AFAICS this would return a pointer to zero initialized struct devlink
when built with CONFIG_DEVLINK=n. Then devlink_compat_running_version()
would execute

	if (!dev->netdev_ops->ndo_get_devlink)
		return;

	devlink = dev->netdev_ops->ndo_get_devlink(dev);
	if (!devlink || !devlink->ops->info_get)
		return;

with non-null devlink but null devlink->ops so that it dereferences null
pointer (and so does devlink_compat_flash_update()).

Maybe it would be safer not to call ndo_get_devlink directly and have
an inline wrapper like

#if IS_ENABLED(CONFIG_NET_DEVLINK)
static inline struct devlink *dev_get_devlink(struct net_device *dev)
{
	if (dev->netdev_ops->ndo_get_devlink)
		return dev->netdev_ops->ndo_get_devlink();
	else
		retrurn NULL;
}
#else
static inline struct devlink *dev_get_devlink(struct net_device *dev)
{
	return NULL;
}
#endif

so that one can simply call the wrapper and check return value for NULL.

Michal

  reply	other threads:[~2019-02-22 10:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 17:46 [PATCH net-next 0/5] devlink: make ethtool compat reliable Jakub Kicinski
2019-02-21 17:46 ` [PATCH net-next 1/5] net: devlink: turn devlink into a built-in Jakub Kicinski
2019-02-21 17:46 ` [PATCH net-next 2/5] ethtool: hold a reference to the netdevice around devlink compat Jakub Kicinski
2019-02-21 17:46 ` [PATCH net-next 3/5] devlink: create a special NDO for getting the devlink instance Jakub Kicinski
2019-02-22  9:51   ` Michal Kubecek
2019-02-22 16:56     ` Jakub Kicinski
2019-02-21 17:46 ` [PATCH net-next 4/5] nfp: add .ndo_get_devlink Jakub Kicinski
2019-02-22 10:04   ` Michal Kubecek [this message]
2019-02-22 17:02     ` Jakub Kicinski
2019-02-22 17:27       ` Michal Kubecek
2019-02-22 18:53         ` Jakub Kicinski
2019-02-21 17:46 ` [PATCH net-next 5/5] nfp: remove ethtool flashing fallback Jakub Kicinski

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=20190222100450.GR23151@unicorn.suse.cz \
    --to=mkubecek@suse.cz \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=jiri@resnulli.us \
    --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).