From: Jaehoon Chung <jh80.chung@samsung.com>
To: linux-kernel@vger.kernel.org
Cc: kishon@ti.com, Jaehoon Chung <jh80.chung@samsung.com>
Subject: [PATCH] phy: core: check whether ops callback function is assigned
Date: Thu, 22 Dec 2016 18:42:22 +0900 [thread overview]
Message-ID: <20161222094222.6871-1-jh80.chung@samsung.com> (raw)
In-Reply-To: CGME20161222094224epcas1p49349afba1cf8468d350b66ca29e8590e@epcas1p4.samsung.com
If some ops-> callback function are not assigend, then it should do the
unexpect behavior.
To prevent the potential NULL pointer dereference, check the each
callback functions before doing operation.
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
---
drivers/phy/phy-core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index a268f4d6f3e9..e4eb4431c8a4 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -219,7 +219,7 @@ int phy_init(struct phy *phy)
{
int ret;
- if (!phy)
+ if (!phy || !phy->ops->init)
return 0;
ret = phy_pm_runtime_get_sync(phy);
@@ -248,7 +248,7 @@ int phy_exit(struct phy *phy)
{
int ret;
- if (!phy)
+ if (!phy || !phy->ops->exit)
return 0;
ret = phy_pm_runtime_get_sync(phy);
@@ -277,7 +277,7 @@ int phy_power_on(struct phy *phy)
{
int ret = 0;
- if (!phy)
+ if (!phy || !phy->ops->power_on)
goto out;
if (phy->pwr) {
@@ -319,7 +319,7 @@ int phy_power_off(struct phy *phy)
{
int ret;
- if (!phy)
+ if (!phy || !phy->ops->power_off)
return 0;
mutex_lock(&phy->mutex);
--
2.11.0
next parent reply other threads:[~2016-12-22 9:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20161222094224epcas1p49349afba1cf8468d350b66ca29e8590e@epcas1p4.samsung.com>
2016-12-22 9:42 ` Jaehoon Chung [this message]
2016-12-27 8:31 ` [PATCH] phy: core: check whether ops callback function is assigned Kishon Vijay Abraham I
2016-12-27 8:37 ` Jaehoon Chung
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161222094222.6871-1-jh80.chung@samsung.com \
--to=jh80.chung@samsung.com \
--cc=kishon@ti.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).