diff mbox series

[net-next,5/5] net: stmmac: stm32: Use syscon_regmap_lookup_by_phandle_args

Message ID 20250112-syscon-phandle-args-net-v1-5-3423889935f7@linaro.org (mailing list archive)
State New
Headers show
Series net: ethernet: Simplify few things | expand

Commit Message

Krzysztof Kozlowski Jan. 12, 2025, 1:32 p.m. UTC
Use syscon_regmap_lookup_by_phandle_args() which is a wrapper over
syscon_regmap_lookup_by_phandle() combined with getting the syscon
argument.  Except simpler code this annotates within one line that given
phandle has arguments, so grepping for code would be easier.

There is also no real benefit in printing errors on missing syscon
argument, because this is done just too late: runtime check on
static/build-time data.  Dtschema and Devicetree bindings offer the
static/build-time check for this already.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Yanteng Si Jan. 13, 2025, 8:05 a.m. UTC | #1
在 2025/1/12 21:32, Krzysztof Kozlowski 写道:
> Use syscon_regmap_lookup_by_phandle_args() which is a wrapper over
> syscon_regmap_lookup_by_phandle() combined with getting the syscon
> argument.  Except simpler code this annotates within one line that given
> phandle has arguments, so grepping for code would be easier.
> 
> There is also no real benefit in printing errors on missing syscon
> argument, because this is done just too late: runtime check on
> static/build-time data.  Dtschema and Devicetree bindings offer the
> static/build-time check for this already.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>   drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 9 ++-------
>   1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> index 1e8bac665cc9bc95c3aa96e87a8e95d9c63ba8e1..1fcb74e9e3ffacdc7581b267febb55d015a83aed 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> @@ -419,16 +419,11 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac,
>   	}
>   
>   	/* Get mode register */
> -	dwmac->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscon");
> +	dwmac->regmap = syscon_regmap_lookup_by_phandle_args(np, "st,syscon",
> +							     1, &dwmac->mode_reg);
The network subsystem still requires that the length of
each line of code should not exceed 80 characters.
So, let's silence the warning:

WARNING: line length of 83 exceeds 80 columns
#33: FILE: drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c:307:
+							     &dwmac->intf_reg_off);


BTW, The other two stmmac patches also need to adjust
the code so that each line doesn't exceed 80 characters.

Thanks,
Yanteng
Krzysztof Kozlowski Jan. 13, 2025, 11:08 a.m. UTC | #2
On 13/01/2025 09:05, Yanteng Si wrote:
>> -	dwmac->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscon");
>> +	dwmac->regmap = syscon_regmap_lookup_by_phandle_args(np, "st,syscon",
>> +							     1, &dwmac->mode_reg);
> The network subsystem still requires that the length of
> each line of code should not exceed 80 characters.


Please read the coding style regarding this issue, before you nitpick
such things.

I see you send comments like:
WARNING: line length of 81 exceeds 80 columns

which is not really helpful. That's not the review aspect necessary to
point.

> So, let's silence the warning:
> 
> WARNING: line length of 83 exceeds 80 columns
> #33: FILE: drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c:307:
> +							     &dwmac->intf_reg_off);

Unless networking maintainers tell me otherwise, I find my code more
readable thus it follows the coding style.

Best regards,
Krzysztof
Andrew Lunn Jan. 13, 2025, 5:01 p.m. UTC | #3
On Mon, Jan 13, 2025 at 04:05:13PM +0800, Yanteng Si wrote:
> 在 2025/1/12 21:32, Krzysztof Kozlowski 写道:
> > Use syscon_regmap_lookup_by_phandle_args() which is a wrapper over
> > syscon_regmap_lookup_by_phandle() combined with getting the syscon
> > argument.  Except simpler code this annotates within one line that given
> > phandle has arguments, so grepping for code would be easier.
> > 
> > There is also no real benefit in printing errors on missing syscon
> > argument, because this is done just too late: runtime check on
> > static/build-time data.  Dtschema and Devicetree bindings offer the
> > static/build-time check for this already.
> > 
> > Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > ---
> >   drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 9 ++-------
> >   1 file changed, 2 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> > index 1e8bac665cc9bc95c3aa96e87a8e95d9c63ba8e1..1fcb74e9e3ffacdc7581b267febb55d015a83aed 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> > @@ -419,16 +419,11 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac,
> >   	}
> >   	/* Get mode register */
> > -	dwmac->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscon");
> > +	dwmac->regmap = syscon_regmap_lookup_by_phandle_args(np, "st,syscon",
> > +							     1, &dwmac->mode_reg);
> The network subsystem still requires that the length of
> each line of code should not exceed 80 characters.
> So, let's silence the warning:
> 
> WARNING: line length of 83 exceeds 80 columns
> #33: FILE: drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c:307:
> +							     &dwmac->intf_reg_off);

checkpatch should be considered a guide, not a strict conformance
tool. You often need to look at its output and consider does what it
suggest really make the code better? In this case, i would disagree
with checkpatch and allow this code.

If the code had all been on one long line, then i would suggest to
wrap it. But as it is, it keeps with the spirit of 80 characters, even
if it is technically not.

	Andrew
Yanteng Si Jan. 14, 2025, 1:58 a.m. UTC | #4
在 2025/1/14 01:01, Andrew Lunn 写道:
> On Mon, Jan 13, 2025 at 04:05:13PM +0800, Yanteng Si wrote:
>> 在 2025/1/12 21:32, Krzysztof Kozlowski 写道:
>>> Use syscon_regmap_lookup_by_phandle_args() which is a wrapper over
>>> syscon_regmap_lookup_by_phandle() combined with getting the syscon
>>> argument.  Except simpler code this annotates within one line that given
>>> phandle has arguments, so grepping for code would be easier.
>>>
>>> There is also no real benefit in printing errors on missing syscon
>>> argument, because this is done just too late: runtime check on
>>> static/build-time data.  Dtschema and Devicetree bindings offer the
>>> static/build-time check for this already.
>>>
>>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>> ---
>>>    drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 9 ++-------
>>>    1 file changed, 2 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
>>> index 1e8bac665cc9bc95c3aa96e87a8e95d9c63ba8e1..1fcb74e9e3ffacdc7581b267febb55d015a83aed 100644
>>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
>>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
>>> @@ -419,16 +419,11 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac,
>>>    	}
>>>    	/* Get mode register */
>>> -	dwmac->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscon");
>>> +	dwmac->regmap = syscon_regmap_lookup_by_phandle_args(np, "st,syscon",
>>> +							     1, &dwmac->mode_reg);
>> The network subsystem still requires that the length of
>> each line of code should not exceed 80 characters.
>> So, let's silence the warning:
>>
>> WARNING: line length of 83 exceeds 80 columns
>> #33: FILE: drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c:307:
>> +							     &dwmac->intf_reg_off);
> checkpatch should be considered a guide, not a strict conformance
> tool. You often need to look at its output and consider does what it
> suggest really make the code better? In this case, i would disagree
> with checkpatch and allow this code.
>
> If the code had all been on one long line, then i would suggest to
> wrap it. But as it is, it keeps with the spirit of 80 characters, even
> if it is technically not.
Oh, I got it! Thanks for explaining. You cleared up my confusion.

I made those comments based on my past experience. Actually, I
hesitated for ages before hitting the send button. I couldn't
figure out a better way other than refactoring the function.
I guess I might have come across as a bit unreasonable. But
now I understand the reasoning behind the ‘80 - character’
thing. I'll be more confident when dealing with this kind
of situation in the future.


Thanks,
Yanteng

> 	Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
index 1e8bac665cc9bc95c3aa96e87a8e95d9c63ba8e1..1fcb74e9e3ffacdc7581b267febb55d015a83aed 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
@@ -419,16 +419,11 @@  static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac,
 	}
 
 	/* Get mode register */
-	dwmac->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscon");
+	dwmac->regmap = syscon_regmap_lookup_by_phandle_args(np, "st,syscon",
+							     1, &dwmac->mode_reg);
 	if (IS_ERR(dwmac->regmap))
 		return PTR_ERR(dwmac->regmap);
 
-	err = of_property_read_u32_index(np, "st,syscon", 1, &dwmac->mode_reg);
-	if (err) {
-		dev_err(dev, "Can't get sysconfig mode offset (%d)\n", err);
-		return err;
-	}
-
 	if (dwmac->ops->is_mp2)
 		return 0;