[PATCH net-next v2 00/11] net: stmmac: introduce devres helpers for stmmac platform drivers

From: Bartosz Golaszewski
Date: Fri Jun 23 2023 - 06:05:10 EST


From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>

The goal of this series is two-fold: to make the API for stmmac platforms more
logically correct (by providing functions that acquire resources with release
counterparts that undo only their actions and nothing more) and to provide
devres variants of commonly use registration functions that allows to
significantly simplify the platform drivers.

The current pattern for stmmac platform drivers is to call
stmmac_probe_config_dt(), possibly the platform's init() callback and then
call stmmac_drv_probe(). The resources allocated by these calls will then
be released by calling stmmac_pltfr_remove(). This goes against the commonly
accepted way of providing each function that allocated a resource with a
function that frees it.

First: provide wrappers around platform's init() and exit() callbacks that
allow users to skip checking if the callbacks exist manually.

Second: provide stmmac_pltfr_probe() which calls the platform init() callback
and then calls stmmac_drv_probe() together with a variant of
stmmac_pltfr_remove() that DOES NOT call stmmac_remove_config_dt(). For now
this variant is called stmmac_pltfr_remove_no_dt() but once all users of
the old stmmac_pltfr_remove() are converted to the devres helper, it will be
renamed back to stmmac_pltfr_remove() and the no_dt function removed.

Finally use the devres helpers in dwmac-qco-ethqos to show how much simplier
the driver's probe() becomes.

This series obviously just starts the conversion process and other platform
drivers will need to be converted once the helpers land in net/.

v1 -> v2:
- fix build for !CONFIG_OF

Bartosz Golaszewski (11):
net: stmmac: platform: provide stmmac_pltfr_init()
net: stmmac: dwmac-generic: use stmmac_pltfr_init()
net: stmmac: platform: provide stmmac_pltfr_exit()
net: stmmac: dwmac-generic: use stmmac_pltfr_exit()
net: stmmac: platform: provide stmmac_pltfr_probe()
net: stmmac: dwmac-generic: use stmmac_pltfr_probe()
net: stmmac: platform: provide stmmac_pltfr_remove_no_dt()
net: stmmac: platform: provide devm_stmmac_probe_config_dt()
net: stmmac: dwmac-qco-ethqos: use devm_stmmac_probe_config_dt()
net: stmmac: platform: provide devm_stmmac_pltfr_probe()
net: stmmac: dwmac-qcom-ethqos: use devm_stmmac_pltfr_probe()

.../ethernet/stmicro/stmmac/dwmac-generic.c | 14 +-
.../stmicro/stmmac/dwmac-qcom-ethqos.c | 48 ++---
.../ethernet/stmicro/stmmac/stmmac_platform.c | 164 +++++++++++++++++-
.../ethernet/stmicro/stmmac/stmmac_platform.h | 14 ++
4 files changed, 185 insertions(+), 55 deletions(-)

--
2.39.2