mbox series

[net-next,v2,00/13] net: Simplified with scoped function

Message ID 20240828032343.1218749-1-ruanjinjie@huawei.com (mailing list archive)
Headers show
Series net: Simplified with scoped function | expand

Message

Jinjie Ruan Aug. 28, 2024, 3:23 a.m. UTC
Simplify with scoped for each OF child loop and __free(), as well as
dev_err_probe().

Changes in v2:
- Subject prefix: next -> net-next.
- Split __free() from scoped for each OF child loop clean.
- Fix use of_node_put() instead of __free() for the 5th patch.

Jinjie Ruan (13):
  net: stmmac: dwmac-sun8i: Use for_each_child_of_node_scoped()
  net: stmmac: dwmac-sun8i: Use __free() to simplify code
  net: dsa: realtek: Use for_each_child_of_node_scoped()
  net: dsa: realtek: Use __free() to simplify code
  net: phy: Fix missing of_node_put() for leds
  net: phy: Use for_each_available_child_of_node_scoped()
  net: mdio: mux-mmioreg: Simplified with scoped function
  net: mdio: mux-mmioreg: Simplified with dev_err_probe()
  net: mv643xx_eth: Simplify with scoped for each OF child loop
  net: dsa: microchip: Use scoped function to simplfy code
  net: dsa: microchip: Use __free() to simplfy code
  net: bcmasp: Simplify with scoped for each OF child loop
  net: bcmasp: Simplify with __free()

 drivers/net/dsa/microchip/ksz_common.c        | 12 ++---
 drivers/net/dsa/realtek/rtl8366rb.c           | 11 ++--
 drivers/net/ethernet/broadcom/asp2/bcmasp.c   | 18 +++----
 drivers/net/ethernet/marvell/mv643xx_eth.c    |  5 +-
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 20 +++-----
 drivers/net/mdio/mdio-mux-mmioreg.c           | 51 ++++++++-----------
 drivers/net/phy/phy_device.c                  |  7 +--
 7 files changed, 48 insertions(+), 76 deletions(-)

Comments

Andrew Lunn Aug. 28, 2024, 2:32 p.m. UTC | #1
On Wed, Aug 28, 2024 at 11:23:30AM +0800, Jinjie Ruan wrote:
> Simplify with scoped for each OF child loop and __free(), as well as
> dev_err_probe().
> 
> Changes in v2:
> - Subject prefix: next -> net-next.
> - Split __free() from scoped for each OF child loop clean.
> - Fix use of_node_put() instead of __free() for the 5th patch.

I personally think all these __free() are ugly and magical. Can it
somehow be made part of of_get_child_by_name()? Add an
of_get_child_by_name_func_ref() which holds a reference to the node
for the scope of the function?

for_each_available_child_of_node_scoped() is fine. Once you have fixed
all the reverse christmas tree, please submit them. But i would like
to see alternatives to __free(), once which are less ugly.

	Andrew

---
pw-bot: cr
Krzysztof Kozlowski Aug. 28, 2024, 2:45 p.m. UTC | #2
On 28/08/2024 16:32, Andrew Lunn wrote:
> On Wed, Aug 28, 2024 at 11:23:30AM +0800, Jinjie Ruan wrote:
>> Simplify with scoped for each OF child loop and __free(), as well as
>> dev_err_probe().
>>
>> Changes in v2:
>> - Subject prefix: next -> net-next.
>> - Split __free() from scoped for each OF child loop clean.
>> - Fix use of_node_put() instead of __free() for the 5th patch.
> 
> I personally think all these __free() are ugly and magical. Can it

It is code readability so quite subjective. Jakub also rejected one of
such __free() changes, so maybe all these cases here should be rejected?

> somehow be made part of of_get_child_by_name()? Add an
> of_get_child_by_name_func_ref() which holds a reference to the node
> for the scope of the function?

That's interesting, scoped-wrapper. I am afraid we would need quite a
lot of them, though, for every of_get_xxx call.

Best regards,
Krzysztof
Andrew Lunn Aug. 28, 2024, 3:24 p.m. UTC | #3
On Wed, Aug 28, 2024 at 04:45:32PM +0200, Krzysztof Kozlowski wrote:
> On 28/08/2024 16:32, Andrew Lunn wrote:
> > On Wed, Aug 28, 2024 at 11:23:30AM +0800, Jinjie Ruan wrote:
> >> Simplify with scoped for each OF child loop and __free(), as well as
> >> dev_err_probe().
> >>
> >> Changes in v2:
> >> - Subject prefix: next -> net-next.
> >> - Split __free() from scoped for each OF child loop clean.
> >> - Fix use of_node_put() instead of __free() for the 5th patch.
> > 
> > I personally think all these __free() are ugly and magical. Can it
> 
> It is code readability so quite subjective.

Try.

But the __ is also a red flag. Anything starting with _ or __ in
general should not be used in common code. That prefix is supposed to
indicate it is internal plumbing which should be hidden away, out of
sight, not to be used directly. Yet here it is, being scattered
everywhere.

I also wounder if this is lipstick on a pig. I suspect the reference
counting on DT object is broken everywhere, because it is almost never
used. In general, DT blobs exist from boot to shutdown. They don't go
away, so these reference counts are never used. DT overlays do exist,
but account for what, 1% of DT objects? And how often does an overlay
actually get unloaded? Has anybody written a fuzzer to try unloading
parts of DT blobs? I suspect we would quickly drown in bug reports.

Adding missing of_node_put() seems to be high on the list of bot
driven patches, which cause a lot of maintainer effort for no real
gain. And those submitting the patches probably have little
understanding of what they are doing, other than making the bot happy.
Do we really want to be adding ugly code, probably with a few
additional bugs thrown in, just to make a bot happy, but probably no
real benefit?

	Andrew
Jakub Kicinski Aug. 28, 2024, 6:10 p.m. UTC | #4
On Wed, 28 Aug 2024 16:45:32 +0200 Krzysztof Kozlowski wrote:
> On 28/08/2024 16:32, Andrew Lunn wrote:
> > On Wed, Aug 28, 2024 at 11:23:30AM +0800, Jinjie Ruan wrote:  
> >> Simplify with scoped for each OF child loop and __free(), as well as
> >> dev_err_probe().
> >>
> >> Changes in v2:
> >> - Subject prefix: next -> net-next.
> >> - Split __free() from scoped for each OF child loop clean.
> >> - Fix use of_node_put() instead of __free() for the 5th patch.  
> > 
> > I personally think all these __free() are ugly and magical. Can it  
> 
> It is code readability so quite subjective. Jakub also rejected one of
> such __free() changes, so maybe all these cases here should be rejected?

Andrew's comments on refcounting on DT objects notwithstanding --
I do like the _scoped() iterator quite a bit, FWIW. I think it's one 
of the better uses of the auto-cleanup and local variable declarations.

Direct uses of __free() are more questionable in my opinion.

Using advanced constructs to build clean subsystem APIs is great,
sprinkling unreadable constructs to save LoC is what C++ is for. 
(Lets see how many people this offends ;))
Jinjie Ruan Aug. 29, 2024, 3:26 a.m. UTC | #5
On 2024/8/28 22:32, Andrew Lunn wrote:
> On Wed, Aug 28, 2024 at 11:23:30AM +0800, Jinjie Ruan wrote:
>> Simplify with scoped for each OF child loop and __free(), as well as
>> dev_err_probe().
>>
>> Changes in v2:
>> - Subject prefix: next -> net-next.
>> - Split __free() from scoped for each OF child loop clean.
>> - Fix use of_node_put() instead of __free() for the 5th patch.
> 
> I personally think all these __free() are ugly and magical. Can it
> somehow be made part of of_get_child_by_name()? Add an
> of_get_child_by_name_func_ref() which holds a reference to the node
> for the scope of the function?

Yes, that is a good idea, and the __free() doesn't look as readable as
or_each_*child_of_node_scoped().

> 
> for_each_available_child_of_node_scoped() is fine. Once you have fixed
> all the reverse christmas tree, please submit them. But i would like
> to see alternatives to __free(), once which are less ugly.

Thank you!

> 
> 	Andrew
> 
> ---
> pw-bot: cr
>