diff mbox series

[v2] wifi: ath10k: Drop of_get_property() call

Message ID 20250314233831.2535170-1-robh@kernel.org (mailing list archive)
State New
Delegated to: Jeff Johnson
Headers show
Series [v2] wifi: ath10k: Drop of_get_property() call | expand

Checks

Context Check Description
wifibot/fixes_present success Fixes tag not required for -next series
wifibot/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
wifibot/tree_selection success Guessed tree name to be wireless-next
wifibot/ynl success Generated files up to date; no warnings/errors; no diff in generated;
wifibot/build_32bit success Errors and warnings before: 0 this patch: 0
wifibot/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
wifibot/build_clang success Errors and warnings before: 0 this patch: 0
wifibot/build_clang_rust success No Rust files in patch. Skipping build
wifibot/build_tools success No tools touched, skip
wifibot/check_selftest success No net selftest shell script
wifibot/checkpatch warning WARNING: line length of 90 exceeds 80 columns
wifibot/deprecated_api success None detected
wifibot/header_inline success No static functions without inline keyword in header files
wifibot/kdoc success Errors and warnings before: 0 this patch: 0
wifibot/source_inline success Was 0 now: 0
wifibot/verify_fixes success No Fixes tag
wifibot/verify_signedoff success Signed-off-by tag matches author and committer

Commit Message

Rob Herring (Arm) March 14, 2025, 11:38 p.m. UTC
There's no need to check the property presence and length before calling
of_property_read_u8_array() as it will return an error if the property
is missing or the length is too small. The return errno doesn't matter
to the caller, so no change in behavior there.

Change of_property_read_u8_array() to of_property_read_variable_u8_array()
as the former allows properties to be longer than the requested length.
Now the property has to be the exact length requested as the removed
check required.

This part of a larger effort to remove DT functions like
of_get_property() and of_find_property() which return raw DT data
having no reference counting.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
v2:
 - Add check that cal_data_len is non-zero
---
 drivers/net/wireless/ath/ath10k/core.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

Comments

Jonas Gorski March 15, 2025, 10:07 a.m. UTC | #1
Hi,

On Sat, Mar 15, 2025 at 12:39 AM Rob Herring (Arm) <robh@kernel.org> wrote:
>
> There's no need to check the property presence and length before calling
> of_property_read_u8_array() as it will return an error if the property
> is missing or the length is too small. The return errno doesn't matter
> to the caller, so no change in behavior there.
>
> Change of_property_read_u8_array() to of_property_read_variable_u8_array()
> as the former allows properties to be longer than the requested length.
> Now the property has to be the exact length requested as the removed
> check required.
>
> This part of a larger effort to remove DT functions like
> of_get_property() and of_find_property() which return raw DT data
> having no reference counting.
>
> Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
> ---
> v2:
>  - Add check that cal_data_len is non-zero
> ---
>  drivers/net/wireless/ath/ath10k/core.c | 24 +++++++-----------------
>  1 file changed, 7 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
> index b3294287bce1..47206b171aa5 100644
> --- a/drivers/net/wireless/ath/ath10k/core.c
> +++ b/drivers/net/wireless/ath/ath10k/core.c
> @@ -1889,39 +1889,29 @@ static int ath10k_download_cal_file(struct ath10k *ar,
>  static int ath10k_download_cal_dt(struct ath10k *ar, const char *dt_name)
>  {
>         struct device_node *node;
> -       int data_len;
> +       int data_len = ar->hw_params.cal_data_len;
>         void *data;
>         int ret;
>
>         node = ar->dev->of_node;
> -       if (!node)
> +       if (!node || !data_len)
>                 /* Device Tree is optional, don't print any warnings if
>                  * there's no node for ath10k.
>                  */
>                 return -ENOENT;
>
> -       if (!of_get_property(node, dt_name, &data_len)) {
> -               /* The calibration data node is optional */
> -               return -ENOENT;
> -       }
> -
> -       if (data_len != ar->hw_params.cal_data_len) {
> -               ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
> -                           data_len);
> -               ret = -EMSGSIZE;
> -               goto out;
> -       }
> -
>         data = kmalloc(data_len, GFP_KERNEL);
>         if (!data) {
>                 ret = -ENOMEM;
>                 goto out;
>         }
>
> -       ret = of_property_read_u8_array(node, dt_name, data, data_len);
> +       ret = of_property_read_variable_u8_array(node, dt_name, data, data_len, data_len);
>         if (ret) {

of_property_read_u8_array() returns 0 on success, but
of_property_read_variable_u8_array() returns the number of elements
read on success, so this check needs to be ret < 0 now.

> -               ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
> -                           ret);
> +               /* Don't warn if optional property not found  */
> +               if (ret != -EINVAL)
> +                       ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
> +                                   ret);

Best regards,
Jonas
Rob Herring (Arm) March 17, 2025, 5:19 p.m. UTC | #2
On Sat, Mar 15, 2025 at 5:07 AM Jonas Gorski <jonas.gorski@gmail.com> wrote:
>
> Hi,
>
> On Sat, Mar 15, 2025 at 12:39 AM Rob Herring (Arm) <robh@kernel.org> wrote:
> >
> > There's no need to check the property presence and length before calling
> > of_property_read_u8_array() as it will return an error if the property
> > is missing or the length is too small. The return errno doesn't matter
> > to the caller, so no change in behavior there.
> >
> > Change of_property_read_u8_array() to of_property_read_variable_u8_array()
> > as the former allows properties to be longer than the requested length.
> > Now the property has to be the exact length requested as the removed
> > check required.
> >
> > This part of a larger effort to remove DT functions like
> > of_get_property() and of_find_property() which return raw DT data
> > having no reference counting.
> >
> > Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
> > ---
> > v2:
> >  - Add check that cal_data_len is non-zero
> > ---
> >  drivers/net/wireless/ath/ath10k/core.c | 24 +++++++-----------------
> >  1 file changed, 7 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
> > index b3294287bce1..47206b171aa5 100644
> > --- a/drivers/net/wireless/ath/ath10k/core.c
> > +++ b/drivers/net/wireless/ath/ath10k/core.c
> > @@ -1889,39 +1889,29 @@ static int ath10k_download_cal_file(struct ath10k *ar,
> >  static int ath10k_download_cal_dt(struct ath10k *ar, const char *dt_name)
> >  {
> >         struct device_node *node;
> > -       int data_len;
> > +       int data_len = ar->hw_params.cal_data_len;
> >         void *data;
> >         int ret;
> >
> >         node = ar->dev->of_node;
> > -       if (!node)
> > +       if (!node || !data_len)
> >                 /* Device Tree is optional, don't print any warnings if
> >                  * there's no node for ath10k.
> >                  */
> >                 return -ENOENT;
> >
> > -       if (!of_get_property(node, dt_name, &data_len)) {
> > -               /* The calibration data node is optional */
> > -               return -ENOENT;
> > -       }
> > -
> > -       if (data_len != ar->hw_params.cal_data_len) {
> > -               ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
> > -                           data_len);
> > -               ret = -EMSGSIZE;
> > -               goto out;
> > -       }
> > -
> >         data = kmalloc(data_len, GFP_KERNEL);
> >         if (!data) {
> >                 ret = -ENOMEM;
> >                 goto out;
> >         }
> >
> > -       ret = of_property_read_u8_array(node, dt_name, data, data_len);
> > +       ret = of_property_read_variable_u8_array(node, dt_name, data, data_len, data_len);
> >         if (ret) {
>
> of_property_read_u8_array() returns 0 on success, but
> of_property_read_variable_u8_array() returns the number of elements
> read on success, so this check needs to be ret < 0 now.

Indeed. Thanks for catching that.

Rob
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
index b3294287bce1..47206b171aa5 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -1889,39 +1889,29 @@  static int ath10k_download_cal_file(struct ath10k *ar,
 static int ath10k_download_cal_dt(struct ath10k *ar, const char *dt_name)
 {
 	struct device_node *node;
-	int data_len;
+	int data_len = ar->hw_params.cal_data_len;
 	void *data;
 	int ret;
 
 	node = ar->dev->of_node;
-	if (!node)
+	if (!node || !data_len)
 		/* Device Tree is optional, don't print any warnings if
 		 * there's no node for ath10k.
 		 */
 		return -ENOENT;
 
-	if (!of_get_property(node, dt_name, &data_len)) {
-		/* The calibration data node is optional */
-		return -ENOENT;
-	}
-
-	if (data_len != ar->hw_params.cal_data_len) {
-		ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
-			    data_len);
-		ret = -EMSGSIZE;
-		goto out;
-	}
-
 	data = kmalloc(data_len, GFP_KERNEL);
 	if (!data) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
-	ret = of_property_read_u8_array(node, dt_name, data, data_len);
+	ret = of_property_read_variable_u8_array(node, dt_name, data, data_len, data_len);
 	if (ret) {
-		ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
-			    ret);
+		/* Don't warn if optional property not found  */
+		if (ret != -EINVAL)
+			ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
+				    ret);
 		goto out_free;
 	}