can: mcp251x: Use devm_clk_get_optional() to get the input clock
Simplify the code which fetches the input clock by using devm_clk_get_optional(). This comes with a small functional change: previously all errors were ignored when platform data is present. Now all errors are treated as errors. If no input clock is present devm_clk_get_optional() will return NULL instead of an error which matches the behavior of the old code. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:

committed by
Marc Kleine-Budde

parent
f6cae800bf
commit
b4cb76961c
@@ -994,15 +994,13 @@ static int mcp251x_can_probe(struct spi_device *spi)
|
|||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
int freq, ret;
|
int freq, ret;
|
||||||
|
|
||||||
clk = devm_clk_get(&spi->dev, NULL);
|
clk = devm_clk_get_optional(&spi->dev, NULL);
|
||||||
if (IS_ERR(clk)) {
|
if (IS_ERR(clk))
|
||||||
if (pdata)
|
return PTR_ERR(clk);
|
||||||
freq = pdata->oscillator_frequency;
|
|
||||||
else
|
freq = clk_get_rate(clk);
|
||||||
return PTR_ERR(clk);
|
if (freq == 0 && pdata)
|
||||||
} else {
|
freq = pdata->oscillator_frequency;
|
||||||
freq = clk_get_rate(clk);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (freq < 1000000 || freq > 25000000)
|
if (freq < 1000000 || freq > 25000000)
|
||||||
@@ -1013,11 +1011,9 @@ static int mcp251x_can_probe(struct spi_device *spi)
|
|||||||
if (!net)
|
if (!net)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!IS_ERR(clk)) {
|
ret = clk_prepare_enable(clk);
|
||||||
ret = clk_prepare_enable(clk);
|
if (ret)
|
||||||
if (ret)
|
goto out_free;
|
||||||
goto out_free;
|
|
||||||
}
|
|
||||||
|
|
||||||
net->netdev_ops = &mcp251x_netdev_ops;
|
net->netdev_ops = &mcp251x_netdev_ops;
|
||||||
net->flags |= IFF_ECHO;
|
net->flags |= IFF_ECHO;
|
||||||
@@ -1102,8 +1098,7 @@ error_probe:
|
|||||||
mcp251x_power_enable(priv->power, 0);
|
mcp251x_power_enable(priv->power, 0);
|
||||||
|
|
||||||
out_clk:
|
out_clk:
|
||||||
if (!IS_ERR(clk))
|
clk_disable_unprepare(clk);
|
||||||
clk_disable_unprepare(clk);
|
|
||||||
|
|
||||||
out_free:
|
out_free:
|
||||||
free_candev(net);
|
free_candev(net);
|
||||||
@@ -1121,8 +1116,7 @@ static int mcp251x_can_remove(struct spi_device *spi)
|
|||||||
|
|
||||||
mcp251x_power_enable(priv->power, 0);
|
mcp251x_power_enable(priv->power, 0);
|
||||||
|
|
||||||
if (!IS_ERR(priv->clk))
|
clk_disable_unprepare(priv->clk);
|
||||||
clk_disable_unprepare(priv->clk);
|
|
||||||
|
|
||||||
free_candev(net);
|
free_candev(net);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user