lkml.org 
[lkml]   [2026]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v7 phy-next 16/27] phy: make phy_get_mode(), phy_(get|set)_bus_width() NULL tolerant
Date
The PHY API has an optional "get" which returns NULL, so it needs to
accept that NULL coming back in.

Most PHY functions do this, only the formerly static inline attribute
dereferences did not.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v2->v7: none
v1->v2: patch is new
---
drivers/phy/phy-core.c | 9 ++++++++-
include/linux/phy/phy.h | 2 ++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index a1aff00fba7c..0d0be494cfd7 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -624,19 +624,26 @@ EXPORT_SYMBOL_GPL(phy_validate);

enum phy_mode phy_get_mode(struct phy *phy)
{
+ if (!phy)
+ return PHY_MODE_INVALID;
+
return phy->attrs.mode;
}
EXPORT_SYMBOL_GPL(phy_get_mode);

int phy_get_bus_width(struct phy *phy)
{
+ if (!phy)
+ return 0;
+
return phy->attrs.bus_width;
}
EXPORT_SYMBOL_GPL(phy_get_bus_width);

void phy_set_bus_width(struct phy *phy, int bus_width)
{
- phy->attrs.bus_width = bus_width;
+ if (phy)
+ phy->attrs.bus_width = bus_width;
}
EXPORT_SYMBOL_GPL(phy_set_bus_width);

diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index f208edd25afe..a7e2432ca1ae 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -248,6 +248,8 @@ static inline int phy_notify_state(struct phy *phy, union phy_notify state)

static inline int phy_get_bus_width(struct phy *phy)
{
+ if (!phy)
+ return 0;
return -ENOSYS;
}

--
2.34.1

\
 
 \ /
  Last update: 2026-04-30 13:16    [W:0.250 / U:22.195 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog