diff mbox series

[v4,8/8] driver core: Move 2 one line device finding APIs to header

Message ID 20241218-class_fix-v4-8-3c40f098356b@quicinc.com (mailing list archive)
State New, archived
Headers show
Series driver core: class: Fix bug and code improvements for class APIs | expand

Commit Message

Zijun Hu Dec. 18, 2024, 12:01 a.m. UTC
From: Zijun Hu <quic_zijuhu@quicinc.com>

The following device finding APIs only have one line code in function body
device_find_child_by_name()
device_find_any_child()

Move them to header as static inline function.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/core.c    | 32 --------------------------------
 include/linux/device.h | 14 +++++++++++---
 2 files changed, 11 insertions(+), 35 deletions(-)

Comments

Jonathan Cameron Dec. 23, 2024, 8:11 p.m. UTC | #1
On Wed, 18 Dec 2024 08:01:38 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> The following device finding APIs only have one line code in function body
> device_find_child_by_name()
> device_find_any_child()
> 
> Move them to header as static inline function.
Why drop the docs?

> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/base/core.c    | 32 --------------------------------
>  include/linux/device.h | 14 +++++++++++---
>  2 files changed, 11 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 930e43a970952b20cd1c71856bdef889698f51b4..3f37a2aecb1d11561f4edd72e973a1c43368de04 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4100,38 +4100,6 @@ struct device *device_find_child(struct device *parent, const void *data,
>  }
>  EXPORT_SYMBOL_GPL(device_find_child);
>  
> -/**
> - * device_find_child_by_name - device iterator for locating a child device.
> - * @parent: parent struct device
> - * @name: name of the child device
> - *
> - * This is similar to the device_find_child() function above, but it
> - * returns a reference to a device that has the name @name.
> - *
> - * NOTE: you will need to drop the reference with put_device() after use.
> - */
> -struct device *device_find_child_by_name(struct device *parent,
> -					 const char *name)
> -{
> -	return device_find_child(parent, name, device_match_name);
> -}
> -EXPORT_SYMBOL_GPL(device_find_child_by_name);
> -
> -/**
> - * device_find_any_child - device iterator for locating a child device, if any.
> - * @parent: parent struct device
> - *
> - * This is similar to the device_find_child() function above, but it
> - * returns a reference to a child device, if any.
> - *
> - * NOTE: you will need to drop the reference with put_device() after use.
> - */
> -struct device *device_find_any_child(struct device *parent)
> -{
> -	return device_find_child(parent, NULL, device_match_any);
> -}
> -EXPORT_SYMBOL_GPL(device_find_any_child);
> -
>  int __init devices_init(void)
>  {
>  	devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 36d1a1607712f5a6b0668ac02a6cf6b2d0651a2d..d1871a764be62e6857595bc10b9e54862c99dfa2 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -1083,9 +1083,17 @@ int device_for_each_child_reverse_from(struct device *parent,
>  				       device_iter_t fn);
>  struct device *device_find_child(struct device *parent, const void *data,
>  				 device_match_t match);
> -struct device *device_find_child_by_name(struct device *parent,
> -					 const char *name);
> -struct device *device_find_any_child(struct device *parent);
> +
> +static inline struct device *device_find_child_by_name(struct device *parent,
> +						       const char *name)
> +{
> +	return device_find_child(parent, name, device_match_name);
> +}
> +
> +static inline struct device *device_find_any_child(struct device *parent)
> +{
> +	return device_find_child(parent, NULL, device_match_any);
> +}
>  
>  int device_rename(struct device *dev, const char *new_name);
>  int device_move(struct device *dev, struct device *new_parent,
>
Zijun Hu Dec. 24, 2024, 12:33 p.m. UTC | #2
On 2024/12/24 04:11, Jonathan Cameron wrote:
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> The following device finding APIs only have one line code in function body
>> device_find_child_by_name()
>> device_find_any_child()
>>
>> Move them to header as static inline function.
> Why drop the docs?
> 
thank you Jonathan for code review.

will add these comments back in next revision.

i do not notice the comments include important info, and think the API
name prompts what the API does, so remove the comments. my mistake.

>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Jonathan Cameron Dec. 24, 2024, 4:21 p.m. UTC | #3
On Tue, 24 Dec 2024 20:33:44 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> On 2024/12/24 04:11, Jonathan Cameron wrote:
> >> From: Zijun Hu <quic_zijuhu@quicinc.com>
> >>
> >> The following device finding APIs only have one line code in function body
> >> device_find_child_by_name()
> >> device_find_any_child()
> >>
> >> Move them to header as static inline function.  
> > Why drop the docs?
> >   
> thank you Jonathan for code review.
> 
> will add these comments back in next revision.
> 
> i do not notice the comments include important info, and think the API
> name prompts what the API does, so remove the comments. my mistake.
I don't mind that much, just that you should state your reasoning in the
patch description.

Jonathan

> 
> >> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>  
> 
>
diff mbox series

Patch

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 930e43a970952b20cd1c71856bdef889698f51b4..3f37a2aecb1d11561f4edd72e973a1c43368de04 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4100,38 +4100,6 @@  struct device *device_find_child(struct device *parent, const void *data,
 }
 EXPORT_SYMBOL_GPL(device_find_child);
 
-/**
- * device_find_child_by_name - device iterator for locating a child device.
- * @parent: parent struct device
- * @name: name of the child device
- *
- * This is similar to the device_find_child() function above, but it
- * returns a reference to a device that has the name @name.
- *
- * NOTE: you will need to drop the reference with put_device() after use.
- */
-struct device *device_find_child_by_name(struct device *parent,
-					 const char *name)
-{
-	return device_find_child(parent, name, device_match_name);
-}
-EXPORT_SYMBOL_GPL(device_find_child_by_name);
-
-/**
- * device_find_any_child - device iterator for locating a child device, if any.
- * @parent: parent struct device
- *
- * This is similar to the device_find_child() function above, but it
- * returns a reference to a child device, if any.
- *
- * NOTE: you will need to drop the reference with put_device() after use.
- */
-struct device *device_find_any_child(struct device *parent)
-{
-	return device_find_child(parent, NULL, device_match_any);
-}
-EXPORT_SYMBOL_GPL(device_find_any_child);
-
 int __init devices_init(void)
 {
 	devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
diff --git a/include/linux/device.h b/include/linux/device.h
index 36d1a1607712f5a6b0668ac02a6cf6b2d0651a2d..d1871a764be62e6857595bc10b9e54862c99dfa2 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1083,9 +1083,17 @@  int device_for_each_child_reverse_from(struct device *parent,
 				       device_iter_t fn);
 struct device *device_find_child(struct device *parent, const void *data,
 				 device_match_t match);
-struct device *device_find_child_by_name(struct device *parent,
-					 const char *name);
-struct device *device_find_any_child(struct device *parent);
+
+static inline struct device *device_find_child_by_name(struct device *parent,
+						       const char *name)
+{
+	return device_find_child(parent, name, device_match_name);
+}
+
+static inline struct device *device_find_any_child(struct device *parent)
+{
+	return device_find_child(parent, NULL, device_match_any);
+}
 
 int device_rename(struct device *dev, const char *new_name);
 int device_move(struct device *dev, struct device *new_parent,