[v1,10/14] extcon: use dev_of_node(dev) instead of dev->of_node

Message ID 20230322144005.40368-11-andriy.shevchenko@linux.intel.com
State New
Headers
Series extcon: Core cleanups and documentation fixes |

Commit Message

Andy Shevchenko March 22, 2023, 2:40 p.m. UTC
  The dev_of_node function should be preferred.
In the result we may drop unneeded NULL check
of the pointer to the device object.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/extcon/extcon.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
  

Comments

Chanwoo Choi April 3, 2023, 2:17 p.m. UTC | #1
On 23. 3. 22. 23:40, Andy Shevchenko wrote:
> The dev_of_node function should be preferred.
> In the result we may drop unneeded NULL check
> of the pointer to the device object.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/extcon/extcon.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index 5cadbfc151e6..32e96cb49067 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -1429,21 +1429,17 @@ struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
>   */
>  struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
>  {
> -	struct device_node *node;
> +	struct device_node *node, *np = dev_of_node(dev);
>  	struct extcon_dev *edev;
>  
> -	if (!dev)
> -		return ERR_PTR(-EINVAL);
> -
> -	if (!dev->of_node) {
> +	if (!np) {
>  		dev_dbg(dev, "device does not have a device node entry\n");
>  		return ERR_PTR(-EINVAL);
>  	}
>  
> -	node = of_parse_phandle(dev->of_node, "extcon", index);
> +	node = of_parse_phandle(np, "extcon", index);
>  	if (!node) {
> -		dev_dbg(dev, "failed to get phandle in %pOF node\n",
> -			dev->of_node);
> +		dev_dbg(dev, "failed to get phandle in %pOF node\n", np);
>  		return ERR_PTR(-ENODEV);
>  	}
>  

Applied it with the following patch title.
Just use capital letter at the beginning char of title

- extcon: Use dev_of_node(dev) instead of dev->of_node
  

Patch

diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 5cadbfc151e6..32e96cb49067 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -1429,21 +1429,17 @@  struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
  */
 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
 {
-	struct device_node *node;
+	struct device_node *node, *np = dev_of_node(dev);
 	struct extcon_dev *edev;
 
-	if (!dev)
-		return ERR_PTR(-EINVAL);
-
-	if (!dev->of_node) {
+	if (!np) {
 		dev_dbg(dev, "device does not have a device node entry\n");
 		return ERR_PTR(-EINVAL);
 	}
 
-	node = of_parse_phandle(dev->of_node, "extcon", index);
+	node = of_parse_phandle(np, "extcon", index);
 	if (!node) {
-		dev_dbg(dev, "failed to get phandle in %pOF node\n",
-			dev->of_node);
+		dev_dbg(dev, "failed to get phandle in %pOF node\n", np);
 		return ERR_PTR(-ENODEV);
 	}