Re: [PATCHv1 1/2] net: ethernet: stmmac: dwmac-rk: fix optional clock handling

From: Jakub Kicinski
Date: Tue Mar 21 2023 - 23:10:20 EST


On Fri, 17 Mar 2023 18:42:42 +0100 Sebastian Reichel wrote:
> - bsp_priv->mac_clk_rx = devm_clk_get(dev, "mac_clk_rx");
> + bsp_priv->mac_clk_rx = devm_clk_get_optional(dev, "mac_clk_rx");
> if (IS_ERR(bsp_priv->mac_clk_rx))
> - dev_err(dev, "cannot get clock %s\n",
> - "mac_clk_rx");
> + return dev_err_probe(dev, PTR_ERR(bsp_priv->mac_clk_rx),
> + "cannot get clock %s\n", "mac_clk_rx");
>
> - bsp_priv->mac_clk_tx = devm_clk_get(dev, "mac_clk_tx");
> + bsp_priv->mac_clk_tx = devm_clk_get_optional(dev, "mac_clk_tx");
> if (IS_ERR(bsp_priv->mac_clk_tx))
> - dev_err(dev, "cannot get clock %s\n",
> - "mac_clk_tx");
> + return dev_err_probe(dev, PTR_ERR(bsp_priv->mac_clk_tx),
> + "cannot get clock %s\n", "mac_clk_tx");
>
> - bsp_priv->aclk_mac = devm_clk_get(dev, "aclk_mac");
> + bsp_priv->aclk_mac = devm_clk_get_optional(dev, "aclk_mac");
> if (IS_ERR(bsp_priv->aclk_mac))
> - dev_err(dev, "cannot get clock %s\n",
> - "aclk_mac");
> + return dev_err_probe(dev, PTR_ERR(bsp_priv->aclk_mac),
> + "cannot get clock %s\n", "aclk_mac");

Can we turn this into a loop

struct {
struct whatever **ptr;
const char *name;
} clocks[] = {
{ &bsp_priv->mac_clk_rx, "mac_clk_rx" },
{ &bsp_priv->mac_clk_tx, "mac_clk_tx" },
...
}

for (i=0; i < ARRAY_SIZE...) {
*clocks[i]->ptr = devm_clk_get_optional(dev, clocks[i]->name);
if (IS_ERR(*clocks[i]->ptr))
return dev_err_probe(dev, PTR_ERR(*clocks[i]->ptr),
"cannot get clock %s\n",
*clocks[i]->name);
}

?

Or alternatively inline the name of the clock into the error message?
Right now the %s format printing looks neither here nor there, and also
the continuation line is misaligned (should start right under "dev").


FWIW seems like it should be fine for net-next without the fixes tag.