Commit 52797d29 authored by Dan Carpenter's avatar Dan Carpenter Committed by Greg Kroah-Hartman

drivers: phy: tweaks to phy_create()

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: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c1b1731d
...@@ -437,23 +437,18 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops, ...@@ -437,23 +437,18 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
int id; int id;
struct phy *phy; struct phy *phy;
if (!dev) { if (WARN_ON(!dev))
dev_WARN(dev, "no device provided for PHY\n"); return ERR_PTR(-EINVAL);
ret = -EINVAL;
goto err0;
}
phy = kzalloc(sizeof(*phy), GFP_KERNEL); phy = kzalloc(sizeof(*phy), GFP_KERNEL);
if (!phy) { if (!phy)
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto err0;
}
id = ida_simple_get(&phy_ida, 0, 0, GFP_KERNEL); id = ida_simple_get(&phy_ida, 0, 0, GFP_KERNEL);
if (id < 0) { if (id < 0) {
dev_err(dev, "unable to get id\n"); dev_err(dev, "unable to get id\n");
ret = id; ret = id;
goto err1; goto free_phy;
} }
device_initialize(&phy->dev); device_initialize(&phy->dev);
...@@ -468,11 +463,11 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops, ...@@ -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); ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id);
if (ret) if (ret)
goto err2; goto put_dev;
ret = device_add(&phy->dev); ret = device_add(&phy->dev);
if (ret) if (ret)
goto err2; goto put_dev;
if (pm_runtime_enabled(dev)) { if (pm_runtime_enabled(dev)) {
pm_runtime_enable(&phy->dev); pm_runtime_enable(&phy->dev);
...@@ -481,12 +476,11 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops, ...@@ -481,12 +476,11 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
return phy; return phy;
err2: put_dev:
ida_remove(&phy_ida, phy->id);
put_device(&phy->dev); put_device(&phy->dev);
err1: ida_remove(&phy_ida, phy->id);
free_phy:
kfree(phy); kfree(phy);
err0:
return ERR_PTR(ret); return ERR_PTR(ret);
} }
EXPORT_SYMBOL_GPL(phy_create); EXPORT_SYMBOL_GPL(phy_create);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment