netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Daniil Dulov <d.dulov@aladdin.ru>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] net: sfp: remove redundant NULL check
Date: Thu, 15 Feb 2024 16:02:26 +0000	[thread overview]
Message-ID: <Zc41kuP2iwK3AlWv@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240211150824.3947-1-d.dulov@aladdin.ru>

On Sun, Feb 11, 2024 at 07:08:24AM -0800, Daniil Dulov wrote:
> bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove
> redundant NULL check.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.

It probably would've been better to include in here details of the two
paths that lead to this point, and indicate why it's safe to remove the
NULL check.

The first path is via sfp_register_socket(), which checks that
bus->upstream_ops is not NULL prior to calling sfp_register_bus().
Therefore, "ops" can not be NULL when sfp_register_bus() is called
via this path.

The second path is via sfp_bus_add_upstream(), and this path assumes
that the "ops" passed into this function will not be NULL. Nothing in
this code makes that guarantee, and it's up to the design(er) to
determine whether NULL is permitted or not. It's not something that
an automated checker ought to be suggesting.

In this particular instance, I, as the interface designer, do indeed
intend that "ops" will not be NULL here, so the patch can remove the
check is acceptable in this instance.

However, I'll go back to my original point: this is *not* something
that automated tools should be identifying, and it is *not* something
that should be used to throw patches randomly out, especially where
the commit message doesn't include human analysis details.


> 
> Fixes: ce0aa27ff3f6 ("sfp: add sfp-bus to bridge between network devices and sfp cages")
> Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
> ---
>  drivers/net/phy/sfp-bus.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c
> index 850915a37f4c..829cb1dccc27 100644
> --- a/drivers/net/phy/sfp-bus.c
> +++ b/drivers/net/phy/sfp-bus.c
> @@ -478,14 +478,12 @@ static int sfp_register_bus(struct sfp_bus *bus)
>  	const struct sfp_upstream_ops *ops = bus->upstream_ops;
>  	int ret;
>  
> -	if (ops) {
> -		if (ops->link_down)
> -			ops->link_down(bus->upstream);
> -		if (ops->connect_phy && bus->phydev) {
> -			ret = ops->connect_phy(bus->upstream, bus->phydev);
> -			if (ret)
> -				return ret;
> -		}
> +	if (ops->link_down)
> +		ops->link_down(bus->upstream);
> +	if (ops->connect_phy && bus->phydev) {
> +		ret = ops->connect_phy(bus->upstream, bus->phydev);
> +		if (ret)
> +			return ret;
>  	}
>  	bus->registered = true;
>  	bus->socket_ops->attach(bus->sfp);
> -- 
> 2.25.1
> 
> 

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

  parent reply	other threads:[~2024-02-15 16:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-11 15:08 [PATCH] net: sfp: remove redundant NULL check Daniil Dulov
2024-02-13 12:43 ` Paolo Abeni
2024-02-14  1:26   ` Jakub Kicinski
2024-02-15 16:02 ` Russell King (Oracle) [this message]
2024-02-15 17:32   ` Andrew Lunn

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=Zc41kuP2iwK3AlWv@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=andrew@lunn.ch \
    --cc=d.dulov@aladdin.ru \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=netdev@vger.kernel.org \
    /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).