Message ID | f53a1bcca637ceeafb04ce3540a605532d3bc34a.1674036164.git.geert+renesas@glider.be (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | phy: Add devm_of_phy_optional_get() helper | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Guessed tree name to be net-next |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/subject_prefix | success | Link |
netdev/cover_letter | success | Series has a cover letter |
netdev/patch_count | success | Link |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 100 this patch: 100 |
netdev/cc_maintainers | success | CCed 3 of 3 maintainers |
netdev/build_clang | success | Errors and warnings before: 25 this patch: 25 |
netdev/module_param | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/check_selftest | success | No net selftest shell script |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 98 this patch: 98 |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 53 lines checked |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
On Wed, 18 Jan 2023 11:15:14 +0100 Geert Uytterhoeven wrote: > Add an optional variant of devm_of_phy_get(), so drivers no longer have > to open-code this operation. For merging could you put this one on an immutable branch and then everyone can pull + apply patches for callers from their section?
On 18-01-23, 19:28, Jakub Kicinski wrote: > On Wed, 18 Jan 2023 11:15:14 +0100 Geert Uytterhoeven wrote: > > Add an optional variant of devm_of_phy_get(), so drivers no longer have > > to open-code this operation. > > For merging could you put this one on an immutable branch and then > everyone can pull + apply patches for callers from their section? Since this is phy, I can do that and everyone else can merge that in or all changes can go thru phy tree Thanks
On Thu, 19 Jan 2023 16:44:35 +0530 Vinod Koul wrote: > > For merging could you put this one on an immutable branch and then > > everyone can pull + apply patches for callers from their section? > > Since this is phy, I can do that and everyone else can merge that in or > all changes can go thru phy tree Great! The microchip and ti drivers are relatively actively developed, I reckon it's worth going the branch way.
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index d93ddf1262c5178b..ea009a611e19c705 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -879,6 +879,32 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, } EXPORT_SYMBOL_GPL(devm_of_phy_get); +/** + * devm_of_phy_optional_get() - lookup and obtain a reference to an optional + * phy. + * @dev: device that requests this phy + * @np: node containing the phy + * @con_id: name of the phy from device's point of view + * + * Gets the phy using of_phy_get(), and associates a device with it using + * devres. On driver detach, release function is invoked on the devres data, + * then, devres data is freed. This differs to devm_of_phy_get() in + * that if the phy does not exist, it is not considered an error and + * -ENODEV will not be returned. Instead the NULL phy is returned, + * which can be passed to all other phy consumer calls. + */ +struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np, + const char *con_id) +{ + struct phy *phy = devm_of_phy_get(dev, np, con_id); + + if (PTR_ERR(phy) == -ENODEV) + phy = NULL; + + return phy; +} +EXPORT_SYMBOL_GPL(devm_of_phy_optional_get); + /** * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index. * @dev: device that requests this phy diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index 559c3da515073697..5f6e669b616da0b0 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -255,6 +255,8 @@ struct phy *devm_phy_get(struct device *dev, const char *string); struct phy *devm_phy_optional_get(struct device *dev, const char *string); struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, const char *con_id); +struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np, + const char *con_id); struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index); void of_phy_put(struct phy *phy); @@ -450,6 +452,13 @@ static inline struct phy *devm_of_phy_get(struct device *dev, return ERR_PTR(-ENOSYS); } +static inline struct phy *devm_of_phy_optional_get(struct device *dev, + struct device_node *np, + const char *con_id) +{ + return NULL; +} + static inline struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index)
Add an optional variant of devm_of_phy_get(), so drivers no longer have to open-code this operation. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> --- drivers/phy/phy-core.c | 26 ++++++++++++++++++++++++++ include/linux/phy/phy.h | 9 ++++++++ 2 files changed, 35 insertions(+)