2024-02-11 15:10:42

by Daniil Dulov

[permalink] [raw]
Subject: [PATCH] net: sfp: remove redundant NULL check

bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove
redundant NULL check.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: ce0aa27ff3f6 ("sfp: add sfp-bus to bridge between network devices and sfp cages")
Signed-off-by: Daniil Dulov <[email protected]>
---
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



2024-02-13 12:46:53

by Paolo Abeni

[permalink] [raw]
Subject: Re: [PATCH] net: sfp: remove redundant NULL check

On Sun, 2024-02-11 at 07:08 -0800, Daniil Dulov wrote:
> bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove
> redundant NULL check.

I'm unsure about that?!? in theory drivers could call
sfp_bus_add_upstream()/phy_sfp_probe() with NULL ops, even it that very
likely doesn't make any sense.

@Russel, @Andrew: WDYT?

Thanks,

Paolo



2024-02-14 01:37:26

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH] net: sfp: remove redundant NULL check

On Tue, 13 Feb 2024 13:43:57 +0100 Paolo Abeni wrote:
> On Sun, 2024-02-11 at 07:08 -0800, Daniil Dulov wrote:
> > bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove
> > redundant NULL check.
>
> I'm unsure about that?!? in theory drivers could call
> sfp_bus_add_upstream()/phy_sfp_probe() with NULL ops, even it that very
> likely doesn't make any sense.
>
> @Russel, @Andrew: WDYT?

Since Russell is AFK let me discard this instead of queuing.
We'll resurrect if any of the maintainers sends review tags or alike.

2024-02-15 17:32:17

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH] net: sfp: remove redundant NULL check

> 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.

Hi Daniil

Could you work on SVACE and make it dump how it decided it was safe to
remove the NULL check. I assume it found the path via
sfp_register_socket(), and the NULL check in that. So it should be
able to dump that info in some form. sfp_bus_add_upstream() seems more
interesting and it would be interesting to know why it though a NULL
from there was impossible.

It would be great if the tool dumped some text which could be
cut/paste into the commit message as a justification for the change.

Andrew