-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'net-improve-devres-helpers'
Bartosz Golaszewski says: ==================== net: improve devres helpers So it seems like there's no support for relaxing certain networking devres helpers to not require previously allocated structures to also be managed. However the way mdio devres variants are implemented is still wrong and I modified my series to address it while keeping the functions strict. First two patches modify the ixgbe driver to get rid of the last user of devm_mdiobus_free(). Patches 3, 4, 5 and 6 are mostly cosmetic. Patch 7 fixes the way devm_mdiobus_register() is implemented. Patches 8 & 9 provide a managed variant of of_mdiobus_register() and last patch uses it in mtk-star-emac driver. v1 -> v2: - drop the patch relaxing devm_register_netdev() - require struct mii_bus to be managed in devm_mdiobus_register() and devm_of_mdiobus_register() but don't store that information in the structure itself: use devres_find() instead ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
11 changed files
with
174 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include <linux/device.h> | ||
#include <linux/of_mdio.h> | ||
#include <linux/phy.h> | ||
#include <linux/stddef.h> | ||
|
||
struct mdiobus_devres { | ||
struct mii_bus *mii; | ||
}; | ||
|
||
static void devm_mdiobus_free(struct device *dev, void *this) | ||
{ | ||
struct mdiobus_devres *dr = this; | ||
|
||
mdiobus_free(dr->mii); | ||
} | ||
|
||
/** | ||
* devm_mdiobus_alloc_size - Resource-managed mdiobus_alloc_size() | ||
* @dev: Device to allocate mii_bus for | ||
* @sizeof_priv: Space to allocate for private structure | ||
* | ||
* Managed mdiobus_alloc_size. mii_bus allocated with this function is | ||
* automatically freed on driver detach. | ||
* | ||
* RETURNS: | ||
* Pointer to allocated mii_bus on success, NULL on out-of-memory error. | ||
*/ | ||
struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv) | ||
{ | ||
struct mdiobus_devres *dr; | ||
|
||
dr = devres_alloc(devm_mdiobus_free, sizeof(*dr), GFP_KERNEL); | ||
if (!dr) | ||
return NULL; | ||
|
||
dr->mii = mdiobus_alloc_size(sizeof_priv); | ||
if (!dr->mii) { | ||
devres_free(dr); | ||
return NULL; | ||
} | ||
|
||
devres_add(dev, dr); | ||
return dr->mii; | ||
} | ||
EXPORT_SYMBOL(devm_mdiobus_alloc_size); | ||
|
||
static void devm_mdiobus_unregister(struct device *dev, void *this) | ||
{ | ||
struct mdiobus_devres *dr = this; | ||
|
||
mdiobus_unregister(dr->mii); | ||
} | ||
|
||
static int mdiobus_devres_match(struct device *dev, | ||
void *this, void *match_data) | ||
{ | ||
struct mdiobus_devres *res = this; | ||
struct mii_bus *mii = match_data; | ||
|
||
return mii == res->mii; | ||
} | ||
|
||
/** | ||
* __devm_mdiobus_register - Resource-managed variant of mdiobus_register() | ||
* @dev: Device to register mii_bus for | ||
* @bus: MII bus structure to register | ||
* @owner: Owning module | ||
* | ||
* Returns 0 on success, negative error number on failure. | ||
*/ | ||
int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus, | ||
struct module *owner) | ||
{ | ||
struct mdiobus_devres *dr; | ||
int ret; | ||
|
||
if (WARN_ON(!devres_find(dev, devm_mdiobus_free, | ||
mdiobus_devres_match, bus))) | ||
return -EINVAL; | ||
|
||
dr = devres_alloc(devm_mdiobus_unregister, sizeof(*dr), GFP_KERNEL); | ||
if (!dr) | ||
return -ENOMEM; | ||
|
||
ret = __mdiobus_register(bus, owner); | ||
if (ret) { | ||
devres_free(dr); | ||
return ret; | ||
} | ||
|
||
dr->mii = bus; | ||
devres_add(dev, dr); | ||
return 0; | ||
} | ||
EXPORT_SYMBOL(__devm_mdiobus_register); | ||
|
||
#if IS_ENABLED(CONFIG_OF_MDIO) | ||
/** | ||
* devm_of_mdiobus_register - Resource managed variant of of_mdiobus_register() | ||
* @dev: Device to register mii_bus for | ||
* @mdio: MII bus structure to register | ||
* @np: Device node to parse | ||
*/ | ||
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio, | ||
struct device_node *np) | ||
{ | ||
struct mdiobus_devres *dr; | ||
int ret; | ||
|
||
if (WARN_ON(!devres_find(dev, devm_mdiobus_free, | ||
mdiobus_devres_match, mdio))) | ||
return -EINVAL; | ||
|
||
dr = devres_alloc(devm_mdiobus_unregister, sizeof(*dr), GFP_KERNEL); | ||
if (!dr) | ||
return -ENOMEM; | ||
|
||
ret = of_mdiobus_register(mdio, np); | ||
if (ret) { | ||
devres_free(dr); | ||
return ret; | ||
} | ||
|
||
dr->mii = mdio; | ||
devres_add(dev, dr); | ||
return 0; | ||
} | ||
EXPORT_SYMBOL(devm_of_mdiobus_register); | ||
#endif /* CONFIG_OF_MDIO */ | ||
|
||
MODULE_LICENSE("GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.