Skip to contentSkip to conversation

phy: core: Allow phy_pm_runtime_xxx API calls with NULL phy

PATCH Superseded Manu Gautam 3 participants 3 messages Mar 16, 2018 – Mar 19, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: core: Allow phy_pm_runtime_xxx API calls with NULL phy

phy_init() and phy_exit() calls, and phy_power_on() and phy_power_off() already accept NULL as valid PHY refernece and act as NOP. Extend same concept to phy runtime_pm APIs to keep drivers (e.g. dwc3) code simple while dealing with optional PHYs.

---
 drivers/phy/phy-core.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/phy/phy-core.c +18 -0
index 09ac8af..48b9615 100644
@@ -153,6 +153,9 @@ int phy_pm_runtime_get(struct phy *phy)
 {
 	int ret;
 
+	if (!phy)
+		return 0;
+
 	if (!pm_runtime_enabled(&phy->dev))
 		return -ENOTSUPP;
 
@@ -168,6 +171,9 @@ int phy_pm_runtime_get_sync(struct phy *phy)
 {
 	int ret;
 
+	if (!phy)
+		return 0;
+
 	if (!pm_runtime_enabled(&phy->dev))
 		return -ENOTSUPP;
 
@@ -181,6 +187,9 @@ int phy_pm_runtime_get_sync(struct phy *phy)
 
 int phy_pm_runtime_put(struct phy *phy)
 {
+	if (!phy)
+		return 0;
+
 	if (!pm_runtime_enabled(&phy->dev))
 		return -ENOTSUPP;
 
@@ -190,6 +199,9 @@ int phy_pm_runtime_put(struct phy *phy)
 
 int phy_pm_runtime_put_sync(struct phy *phy)
 {
+	if (!phy)
+		return 0;
+
 	if (!pm_runtime_enabled(&phy->dev))
 		return -ENOTSUPP;
 
@@ -199,6 +211,9 @@ int phy_pm_runtime_put_sync(struct phy *phy)
 
 void phy_pm_runtime_allow(struct phy *phy)
 {
+	if (!phy)
+		return 0;
+
 	if (!pm_runtime_enabled(&phy->dev))
 		return;
 
@@ -208,6 +223,9 @@ void phy_pm_runtime_allow(struct phy *phy)
 
 void phy_pm_runtime_forbid(struct phy *phy)
 {
+	if (!phy)
+		return 0;
+
 	if (!pm_runtime_enabled(&phy->dev))
 		return;
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Manu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v4.16-rc4]
[also build test WARNING on next-20180316]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Manu-Gautam/phy-core-Allow-phy_pm_runtime_xxx-API-calls-with-NULL-phy/20180317-114302
config: x86_64-randconfig-x002-201810 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

drivers/phy/phy-core.c: In function 'phy_pm_runtime_allow':

>> drivers/phy/phy-core.c:215:10: warning: 'return' with a value, in function returning void
      return 0;
             ^
   drivers/phy/phy-core.c:212:6: note: declared here
    void phy_pm_runtime_allow(struct phy *phy)
         ^~~~~~~~~~~~~~~~~~~~
   drivers/phy/phy-core.c: In function 'phy_pm_runtime_forbid':
   drivers/phy/phy-core.c:227:10: warning: 'return' with a value, in function returning void
      return 0;
             ^

drivers/phy/phy-core.c:224:6: note: declared here
void phy_pm_runtime_forbid(struct phy *phy)
^~~~~~~~~~~~~~~~~~~~~

vim +/return +215 drivers/phy/phy-core.c

211
212 void phy_pm_runtime_allow(struct phy *phy)
213 {
214 if (!phy)

 > 215			return 0;

216
217 if (!pm_runtime_enabled(&phy->dev))
218 return;
219
220 pm_runtime_allow(&phy->dev);
221 }
222 EXPORT_SYMBOL_GPL(phy_pm_runtime_allow);
223

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
In reply to Manu Gautam
Quoted 16 lines · Manu Gautam

phy_init() and phy_exit() calls, and phy_power_on() and phy_power_off() already accept NULL as valid PHY refernece and act as NOP. Extend same concept to phy runtime_pm APIs to keep drivers (e.g. dwc3) code simple while dealing with optional PHYs.

---
 drivers/phy/phy-core.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/phy/phy-core.c +0 -0
index 09ac8af..48b9615 100644

drivers/phy/phy-core.c int phy_pm_runtime_get(struct phy *phy) · line 159

Quoted 7 lines
drivers/phy/phy-core.c +3 -0
@@ -153,6 +153,9 @@ int phy_pm_runtime_get(struct phy *phy)
 {
 	int ret;
 
+	if (!phy)
+		return 0;
+
 	if (!pm_runtime_enabled(&phy->dev))

Were we already trying to dereference a NULL here? That shouldn't be good i guess.
Kishon, do we not expect phys to be NULL here?

<snip>

regards
Vivek