* [PATCH] net: sfp: remove redundant NULL check
@ 2024-02-11 15:08 Daniil Dulov
2024-02-13 12:43 ` Paolo Abeni
2024-02-15 16:02 ` Russell King (Oracle)
0 siblings, 2 replies; 5+ messages in thread
From: Daniil Dulov @ 2024-02-11 15:08 UTC (permalink / raw)
To: Russell King
Cc: Daniil Dulov, Andrew Lunn, Heiner Kallweit, David S. Miller,
Jakub Kicinski, netdev, linux-kernel, lvc-project
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 <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
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] net: sfp: remove redundant NULL check 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) 1 sibling, 1 reply; 5+ messages in thread From: Paolo Abeni @ 2024-02-13 12:43 UTC (permalink / raw) To: Daniil Dulov, Russell King Cc: Andrew Lunn, Heiner Kallweit, David S. Miller, Jakub Kicinski, netdev, linux-kernel, lvc-project 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: sfp: remove redundant NULL check 2024-02-13 12:43 ` Paolo Abeni @ 2024-02-14 1:26 ` Jakub Kicinski 0 siblings, 0 replies; 5+ messages in thread From: Jakub Kicinski @ 2024-02-14 1:26 UTC (permalink / raw) To: Russell King, Andrew Lunn Cc: Paolo Abeni, Daniil Dulov, Heiner Kallweit, David S. Miller, netdev, linux-kernel, lvc-project 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. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: sfp: remove redundant NULL check 2024-02-11 15:08 [PATCH] net: sfp: remove redundant NULL check Daniil Dulov 2024-02-13 12:43 ` Paolo Abeni @ 2024-02-15 16:02 ` Russell King (Oracle) 2024-02-15 17:32 ` Andrew Lunn 1 sibling, 1 reply; 5+ messages in thread From: Russell King (Oracle) @ 2024-02-15 16:02 UTC (permalink / raw) To: Daniil Dulov Cc: Andrew Lunn, Heiner Kallweit, David S. Miller, Jakub Kicinski, netdev, linux-kernel, lvc-project 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! ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: sfp: remove redundant NULL check 2024-02-15 16:02 ` Russell King (Oracle) @ 2024-02-15 17:32 ` Andrew Lunn 0 siblings, 0 replies; 5+ messages in thread From: Andrew Lunn @ 2024-02-15 17:32 UTC (permalink / raw) To: Russell King (Oracle) Cc: Daniil Dulov, Heiner Kallweit, David S. Miller, Jakub Kicinski, netdev, linux-kernel, lvc-project > 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-15 17:32 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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) 2024-02-15 17:32 ` Andrew Lunn
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).