diff mbox series

[net] mctp: Remove device type check at unregister

Message ID 20221214061044.892446-1-matt@codeconstruct.com.au (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] mctp: Remove device type check at unregister | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Matt Johnston Dec. 14, 2022, 6:10 a.m. UTC
The check could be incorrectly triggered if a netdev
changes its type after register. That is possible for a tun device
using TUNSETLINK ioctl, resulting in mctp unregister failing
and the netdev unregister waiting forever.

This was encountered by https://github.com/openthread/openthread/issues/8523

The check is not required, it was added in an attempt to track down mctp_ptr
being set unexpectedly, which should not happen in normal operation.

Fixes: 7b1871af75f3 ("mctp: Warn if pointer is set for a wrong dev type")
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
---
 net/mctp/device.c | 6 ------
 1 file changed, 6 deletions(-)

Comments

Alexander Duyck Dec. 14, 2022, 4:42 p.m. UTC | #1
On Wed, 2022-12-14 at 14:10 +0800, Matt Johnston wrote:
> The check could be incorrectly triggered if a netdev
> changes its type after register. That is possible for a tun device
> using TUNSETLINK ioctl, resulting in mctp unregister failing
> and the netdev unregister waiting forever.
> 
> This was encountered by https://github.com/openthread/openthread/issues/8523
> 
> The check is not required, it was added in an attempt to track down mctp_ptr
> being set unexpectedly, which should not happen in normal operation.
> 
> Fixes: 7b1871af75f3 ("mctp: Warn if pointer is set for a wrong dev type")
> Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
> ---
>  net/mctp/device.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/net/mctp/device.c b/net/mctp/device.c
> index 99a3bda8852f..dec730b5fe7e 100644
> --- a/net/mctp/device.c
> +++ b/net/mctp/device.c
> @@ -429,12 +429,6 @@ static void mctp_unregister(struct net_device *dev)
>  	struct mctp_dev *mdev;
>  
>  	mdev = mctp_dev_get_rtnl(dev);
> -	if (mdev && !mctp_known(dev)) {
> -		// Sanity check, should match what was set in mctp_register
> -		netdev_warn(dev, "%s: BUG mctp_ptr set for unknown type %d",
> -			    __func__, dev->type);
> -		return;
> -	}
>  	if (!mdev)
>  		return;
>  

It looks like this is incomplete if we are going to allow for these
type of changes. We might as well also remove the block in
mctp_register that was doing a similar check for devices that already
have the mctp_ptr set. Otherwise you will likely need to follow up on
this later.

Alternatively if you are wanting to be consistent you could just drop
the "return", in which case you will still get the warn in both cases
but it doesn't seem to affect behavior otherwise.

In addition you may want to look at registering a notifier to catch
NETDEV_PRE_TYPE_CHANGE and NETDEV_PRE_TYPE_CHANGE. It would enable you
to catch these types of things in the future if you are wanting to
allow changing types.
Matt Johnston Dec. 15, 2022, 5:45 a.m. UTC | #2
On Wed, 2022-12-14 at 08:42 -0800, Alexander H Duyck wrote:
> > diff --git a/net/mctp/device.c b/net/mctp/device.c
> > index 99a3bda8852f..dec730b5fe7e 100644
> > --- a/net/mctp/device.c
> > +++ b/net/mctp/device.c
> > @@ -429,12 +429,6 @@ static void mctp_unregister(struct net_device *dev)
> >  	struct mctp_dev *mdev;
> >  
> >  	mdev = mctp_dev_get_rtnl(dev);
> > -	if (mdev && !mctp_known(dev)) {
> > -		// Sanity check, should match what was set in mctp_register
> > -		netdev_warn(dev, "%s: BUG mctp_ptr set for unknown type %d",
> > -			    __func__, dev->type);
> > -		return;
> > -	}
> >  	if (!mdev)
> >  		return;
> >  
> 
> It looks like this is incomplete if we are going to allow for these
> type of changes. We might as well also remove the block in
> mctp_register that was doing a similar check for devices that already
> have the mctp_ptr set. Otherwise you will likely need to follow up on
> this later.

I'm not sure it's possible to hit that, I'll remove it in a v2.

Thanks for the review.

Cheers,
Matt
diff mbox series

Patch

diff --git a/net/mctp/device.c b/net/mctp/device.c
index 99a3bda8852f..dec730b5fe7e 100644
--- a/net/mctp/device.c
+++ b/net/mctp/device.c
@@ -429,12 +429,6 @@  static void mctp_unregister(struct net_device *dev)
 	struct mctp_dev *mdev;
 
 	mdev = mctp_dev_get_rtnl(dev);
-	if (mdev && !mctp_known(dev)) {
-		// Sanity check, should match what was set in mctp_register
-		netdev_warn(dev, "%s: BUG mctp_ptr set for unknown type %d",
-			    __func__, dev->type);
-		return;
-	}
 	if (!mdev)
 		return;