All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: rshearma@brocade.com
Cc: netdev@vger.kernel.org, tom@herbertland.com,
	roopa@cumulusnetworks.com, david.lebrun@uclouvain.be,
	tgraf@suug.ch, dsa@cumulusnetworks.com
Subject: Re: [PATCH net v2 2/2] lwtunnel: Fix oops on state free after encap module unload
Date: Mon, 23 Jan 2017 15:42:48 -0500 (EST)	[thread overview]
Message-ID: <20170123.154248.261820530578170635.davem@davemloft.net> (raw)
In-Reply-To: <1484958086-6151-3-git-send-email-rshearma@brocade.com>

From: Robert Shearman <rshearma@brocade.com>
Date: Sat, 21 Jan 2017 00:21:26 +0000

> @@ -115,8 +115,12 @@ int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
>  	ret = -EOPNOTSUPP;
>  	rcu_read_lock();

Here 'ret' equals -EOPNOTSUPP

>  	ops = rcu_dereference(lwtun_encaps[encap_type]);
> -	if (likely(ops && ops->build_state))
> -		ret = ops->build_state(dev, encap, family, cfg, lws);
> +	if (likely(ops)) {
> +		if (likely(try_module_get(ops->owner) && ops->build_state))
> +			ret = ops->build_state(dev, encap, family, cfg, lws);
> +		if (ret)
> +			module_put(ops->owner);

If try_module_get() fails, 'ret' will still be -EOPNOTSUPP and we will
module_put() on a module we did not grab a reference to.

I think you need to adjust the logic here.  You only want to 'put' if
try_module_get() succeeds and ->build_state() returns an error.

  reply	other threads:[~2017-01-23 20:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 15:32 [PATCH net 0/2] net: Fix oops on state free after lwt module unload Robert Shearman
2017-01-18 15:32 ` [PATCH net 1/2] lwtunnel: Fix oops on state free after encap " Robert Shearman
2017-01-18 15:32 ` [PATCH net 2/2] ila: Fix memory leak of lwt dst cache on " Robert Shearman
2017-01-20 17:03 ` [PATCH net 0/2] net: Fix oops on state free after lwt " David Miller
2017-01-20 20:21   ` Robert Shearman
2017-01-21  0:21 ` [PATCH net v2 " Robert Shearman
2017-01-21  0:21   ` [PATCH net v2 1/2] net: Specify the owning module for lwtunnel ops Robert Shearman
2017-01-21  0:21   ` [PATCH net v2 2/2] lwtunnel: Fix oops on state free after encap module unload Robert Shearman
2017-01-23 20:42     ` David Miller [this message]
2017-01-24 16:26       ` Robert Shearman
2017-01-24 16:26   ` [PATCH net v3 0/2] net: Fix oops on state free after lwt " Robert Shearman
2017-01-24 16:26     ` [PATCH net v3 1/2] net: Specify the owning module for lwtunnel ops Robert Shearman
2017-01-24 16:26     ` [PATCH net v3 2/2] lwtunnel: Fix oops on state free after encap module unload Robert Shearman
2017-01-24 21:21     ` [PATCH net v3 0/2] net: Fix oops on state free after lwt " 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=20170123.154248.261820530578170635.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=david.lebrun@uclouvain.be \
    --cc=dsa@cumulusnetworks.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    --cc=rshearma@brocade.com \
    --cc=tgraf@suug.ch \
    --cc=tom@herbertland.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.