diff mbox series

[net-next] net: mdio: warn once if addr parameter is invalid in mdiobus_get_phy()

Message ID daec3f08-6192-ba79-f74b-5beb436cab6c@gmail.com (mailing list archive)
State Accepted
Commit 8a8b70b3f2cf1155b164ddf649b3c033085451e4
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: mdio: warn once if addr parameter is invalid in mdiobus_get_phy() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -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: 0 this patch: 0
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Heiner Kallweit Jan. 20, 2023, 10:18 p.m. UTC
If mdiobus_get_phy() is called with an invalid addr parameter, then the
caller has a bug. Print a call trace to help identifying the caller.

Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/mdio_bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Andrew Lunn Jan. 24, 2023, 2:17 a.m. UTC | #1
On Fri, Jan 20, 2023 at 11:18:32PM +0100, Heiner Kallweit wrote:
> If mdiobus_get_phy() is called with an invalid addr parameter, then the
> caller has a bug. Print a call trace to help identifying the caller.
> 
> Suggested-by: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
patchwork-bot+netdevbpf@kernel.org Jan. 24, 2023, 5:40 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 20 Jan 2023 23:18:32 +0100 you wrote:
> If mdiobus_get_phy() is called with an invalid addr parameter, then the
> caller has a bug. Print a call trace to help identifying the caller.
> 
> Suggested-by: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/phy/mdio_bus.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Here is the summary with links:
  - [net-next] net: mdio: warn once if addr parameter is invalid in mdiobus_get_phy()
    https://git.kernel.org/netdev/net-next/c/8a8b70b3f2cf

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 16e021b47..ed66a1986 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -108,9 +108,10 @@  EXPORT_SYMBOL(mdiobus_unregister_device);
 
 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
 {
+	bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map);
 	struct mdio_device *mdiodev;
 
-	if (addr < 0 || addr >= ARRAY_SIZE(bus->mdio_map))
+	if (WARN_ONCE(!addr_valid, "addr %d out of range\n", addr))
 		return NULL;
 
 	mdiodev = bus->mdio_map[addr];