From: Kishon Vijay Abraham I <kishon@ti.com>
To: <gregkh@linuxfoundation.org>, <linux-kernel@vger.kernel.org>
Cc: <kishon@ti.com>, Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH 2/3] drivers: phy: tweaks to phy_create()
Date: Fri, 6 Dec 2013 17:51:19 +0530 [thread overview]
Message-ID: <1386332480-31671-3-git-send-email-kishon@ti.com> (raw)
In-Reply-To: <1386332480-31671-1-git-send-email-kishon@ti.com>
From: Dan Carpenter <dan.carpenter@oracle.com>
If this was called with a NULL "dev" then it lead to a NULL dereference
when we called dev_WARN(). I have changed it to WARN_ON() so that we
get a stack dump and can fix the caller.
The rest of this patch is just cleanup like returning directly instead
of having do-nothing gotos. Using descriptive labels instead of
GW-BASIC style "err0" and "err1". I also flipped the order of
put_device() and ida_remove() so they are a mirror reflection of the
order they were allocated.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
drivers/phy/phy-core.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 712b358..58e0e97 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -437,23 +437,18 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
int id;
struct phy *phy;
- if (!dev) {
- dev_WARN(dev, "no device provided for PHY\n");
- ret = -EINVAL;
- goto err0;
- }
+ if (WARN_ON(!dev))
+ return ERR_PTR(-EINVAL);
phy = kzalloc(sizeof(*phy), GFP_KERNEL);
- if (!phy) {
- ret = -ENOMEM;
- goto err0;
- }
+ if (!phy)
+ return ERR_PTR(-ENOMEM);
id = ida_simple_get(&phy_ida, 0, 0, GFP_KERNEL);
if (id < 0) {
dev_err(dev, "unable to get id\n");
ret = id;
- goto err1;
+ goto free_phy;
}
device_initialize(&phy->dev);
@@ -468,11 +463,11 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id);
if (ret)
- goto err2;
+ goto put_dev;
ret = device_add(&phy->dev);
if (ret)
- goto err2;
+ goto put_dev;
if (pm_runtime_enabled(dev)) {
pm_runtime_enable(&phy->dev);
@@ -481,12 +476,11 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
return phy;
-err2:
- ida_remove(&phy_ida, phy->id);
+put_dev:
put_device(&phy->dev);
-err1:
+ ida_remove(&phy_ida, phy->id);
+free_phy:
kfree(phy);
-err0:
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(phy_create);
--
1.7.10.4
next prev parent reply other threads:[~2013-12-06 12:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-06 12:21 [PATCH 0/3] PHY: Fixes for 3.13-rc Kishon Vijay Abraham I
2013-12-06 12:21 ` [PATCH 1/3] drivers: phy: Fix memory leak Kishon Vijay Abraham I
2013-12-06 12:21 ` Kishon Vijay Abraham I [this message]
2013-12-06 12:21 ` [PATCH 3/3] phy: kconfig: add depends on "USB_PHY" to OMAP_USB2 and TWL4030_USB Kishon Vijay Abraham I
2013-12-10 20:55 ` [PATCH 0/3] PHY: Fixes for 3.13-rc Greg KH
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=1386332480-31671-3-git-send-email-kishon@ti.com \
--to=kishon@ti.com \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--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
all inboxes | Powered by JetHome®