[PATCH net-next] net: ti: icssg-prueth: Make pa_stats optional
Andrew Lunn
andrew at lunn.ch
Thu Sep 5 06:17:29 PDT 2024
On Thu, Sep 05, 2024 at 03:47:39PM +0530, MD Danish Anwar wrote:
> pa_stats is optional in dt bindings, make it optional in driver as well.
> Currently if pa_stats syscon regmap is not found driver returns -ENODEV.
> Fix this by not returning an error in case pa_stats is not found and
> continue generating ethtool stats without pa_stats.
>
> Fixes: 550ee90ac61c ("net: ti: icssg-prueth: Add support for PA Stats")
> Signed-off-by: MD Danish Anwar <danishanwar at ti.com>
> ---
> Cc: Jan Kiszka <jan.kiszka at siemens.com>
> NOTE: This fix is targetted to net-next because the concerned commit is not
> yet synced to net. So the issue isn't present in net.
>
> drivers/net/ethernet/ti/icssg/icssg_ethtool.c | 17 ++++++++++-----
> drivers/net/ethernet/ti/icssg/icssg_prueth.c | 4 +---
> drivers/net/ethernet/ti/icssg/icssg_stats.c | 21 ++++++++++++-------
> 3 files changed, 26 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index 5073ec195854..b85c03172f68 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> @@ -68,9 +68,13 @@ static int emac_nway_reset(struct net_device *ndev)
>
> static int emac_get_sset_count(struct net_device *ndev, int stringset)
> {
> + struct prueth_emac *emac = netdev_priv(ndev);
> switch (stringset) {
> case ETH_SS_STATS:
> - return ICSSG_NUM_ETHTOOL_STATS;
> + if (IS_ERR(emac->prueth->pa_stats))
All these IS_ERR() are not so nice. What you often see is during
probe, if getting an optional resource returns an error, you replace
the error code with NULL. The code then becomes
> + if (emac->prueth->pa_stats)
> + return ICSSG_NUM_ETHTOOL_STATS;
> + else
> + return ICSSG_NUM_ETHTOOL_STATS - ICSSG_NUM_PA_STATS;
which looks nicer.
Andrew
More information about the linux-arm-kernel
mailing list