diff mbox series

[net-next] net: dsa: realtek: make use of dev_err_cast_probe()

Message ID 20240828121805.3696631-1-lihongbo22@huawei.com (mailing list archive)
State Accepted
Commit 9023fda2f186168e45bb8e7397ad15ff17fd7bf8
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: dsa: realtek: make use of dev_err_cast_probe() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-29--15-00 (tests: 711)

Commit Message

Hongbo Li Aug. 28, 2024, 12:18 p.m. UTC
Using dev_err_cast_probe() to simplify the code.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
 drivers/net/dsa/realtek/rtl83xx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Andrew Lunn Aug. 28, 2024, 3:51 p.m. UTC | #1
On Wed, Aug 28, 2024 at 08:18:05PM +0800, Hongbo Li wrote:
> Using dev_err_cast_probe() to simplify the code.
> 
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Alvin Šipraga Aug. 28, 2024, 4:14 p.m. UTC | #2
On Wed, Aug 28, 2024 at 08:18:05PM GMT, Hongbo Li wrote:
> Using dev_err_cast_probe() to simplify the code.
> 
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
> ---
>  drivers/net/dsa/realtek/rtl83xx.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c
> index 35709a1756ae..3c5018d5e1f9 100644
> --- a/drivers/net/dsa/realtek/rtl83xx.c
> +++ b/drivers/net/dsa/realtek/rtl83xx.c
> @@ -185,11 +185,9 @@ rtl83xx_probe(struct device *dev,
> 
>         /* TODO: if power is software controlled, set up any regulators here */
>         priv->reset_ctl = devm_reset_control_get_optional(dev, NULL);
> -       if (IS_ERR(priv->reset_ctl)) {
> -               ret = PTR_ERR(priv->reset_ctl);
> -               dev_err_probe(dev, ret, "failed to get reset control\n");
> -               return ERR_CAST(priv->reset_ctl);
> -       }
> +       if (IS_ERR(priv->reset_ctl))
> +               return dev_err_cast_probe(dev, priv->reset_ctl,
> +                                         "failed to get reset control\n");

The change is fine, but maybe it would be nice to fix up the other two
similar cases as well? The errors would be stringified but that's OK.

   159          rc.lock_arg = priv;
   160          priv->map = devm_regmap_init(dev, NULL, priv, &rc);
   161          if (IS_ERR(priv->map)) {
   162                  ret = PTR_ERR(priv->map);
   163                  dev_err(dev, "regmap init failed: %d\n", ret);
   164                  return ERR_PTR(ret);
   165          }
   166  
   167          rc.disable_locking = true;
   168          priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc);
   169          if (IS_ERR(priv->map_nolock)) {
   170                  ret = PTR_ERR(priv->map_nolock);
   171                  dev_err(dev, "regmap init failed: %d\n", ret);
   172                  return ERR_PTR(ret);
   173          }

Then you can remove the ret variable altogether.

Either way,

Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Hongbo Li Aug. 29, 2024, 1:34 a.m. UTC | #3
On 2024/8/29 0:14, Alvin Šipraga wrote:
> On Wed, Aug 28, 2024 at 08:18:05PM GMT, Hongbo Li wrote:
>> Using dev_err_cast_probe() to simplify the code.
>>
>> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
>> ---
>>   drivers/net/dsa/realtek/rtl83xx.c | 8 +++-----
>>   1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c
>> index 35709a1756ae..3c5018d5e1f9 100644
>> --- a/drivers/net/dsa/realtek/rtl83xx.c
>> +++ b/drivers/net/dsa/realtek/rtl83xx.c
>> @@ -185,11 +185,9 @@ rtl83xx_probe(struct device *dev,
>>
>>          /* TODO: if power is software controlled, set up any regulators here */
>>          priv->reset_ctl = devm_reset_control_get_optional(dev, NULL);
>> -       if (IS_ERR(priv->reset_ctl)) {
>> -               ret = PTR_ERR(priv->reset_ctl);
>> -               dev_err_probe(dev, ret, "failed to get reset control\n");
>> -               return ERR_CAST(priv->reset_ctl);
>> -       }
>> +       if (IS_ERR(priv->reset_ctl))
>> +               return dev_err_cast_probe(dev, priv->reset_ctl,
>> +                                         "failed to get reset control\n");
> 
> The change is fine, but maybe it would be nice to fix up the other two
> similar cases as well? The errors would be stringified but that's OK.
> 
>     159          rc.lock_arg = priv;
>     160          priv->map = devm_regmap_init(dev, NULL, priv, &rc);
>     161          if (IS_ERR(priv->map)) {
>     162                  ret = PTR_ERR(priv->map);
>     163                  dev_err(dev, "regmap init failed: %d\n", ret);
>     164                  return ERR_PTR(ret);
It's similar, but not the same. Now we just have the dev_err_cast_probe 
which wraps the dev_err_probe. The dev_err_probe is not completely 
equivalent to dev_err.

Thanks,
Hongbo

>     165          }
>     166
>     167          rc.disable_locking = true;
>     168          priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc);
>     169          if (IS_ERR(priv->map_nolock)) {
>     170                  ret = PTR_ERR(priv->map_nolock);
>     171                  dev_err(dev, "regmap init failed: %d\n", ret);
>     172                  return ERR_PTR(ret);
>     173          }
> 
> Then you can remove the ret variable altogether.
> 
> Either way,
> 
> Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk>
patchwork-bot+netdevbpf@kernel.org Aug. 29, 2024, 7 p.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 28 Aug 2024 20:18:05 +0800 you wrote:
> Using dev_err_cast_probe() to simplify the code.
> 
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
> ---
>  drivers/net/dsa/realtek/rtl83xx.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)

Here is the summary with links:
  - [net-next] net: dsa: realtek: make use of dev_err_cast_probe()
    https://git.kernel.org/netdev/net-next/c/9023fda2f186

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c
index 35709a1756ae..3c5018d5e1f9 100644
--- a/drivers/net/dsa/realtek/rtl83xx.c
+++ b/drivers/net/dsa/realtek/rtl83xx.c
@@ -185,11 +185,9 @@  rtl83xx_probe(struct device *dev,
 
 	/* TODO: if power is software controlled, set up any regulators here */
 	priv->reset_ctl = devm_reset_control_get_optional(dev, NULL);
-	if (IS_ERR(priv->reset_ctl)) {
-		ret = PTR_ERR(priv->reset_ctl);
-		dev_err_probe(dev, ret, "failed to get reset control\n");
-		return ERR_CAST(priv->reset_ctl);
-	}
+	if (IS_ERR(priv->reset_ctl))
+		return dev_err_cast_probe(dev, priv->reset_ctl,
+					  "failed to get reset control\n");
 
 	priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
 	if (IS_ERR(priv->reset)) {