Skip to content

Commit 3555def

Browse files
Joakim Zhanggregkh
authored andcommitted
can: flexcan: flexcan_chip_stop(): add error handling and propagate error value
[ Upstream commit 9ad02c7 ] This patch implements error handling and propagates the error value of flexcan_chip_stop(). This function will be called from flexcan_suspend() in an upcoming patch in some SoCs which support LPSR mode. Add a new function flexcan_chip_stop_disable_on_error() that tries to disable the chip even in case of errors. Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com> [mkl: introduce flexcan_chip_stop_disable_on_error() and use it in flexcan_close()] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Link: https://lore.kernel.org/r/20200922144429.2613631-11-mkl@pengutronix.de Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent eb46fbc commit 3555def

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

drivers/net/can/flexcan.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,18 +1260,23 @@ static int flexcan_chip_start(struct net_device *dev)
12601260
return err;
12611261
}
12621262

1263-
/* flexcan_chip_stop
1263+
/* __flexcan_chip_stop
12641264
*
1265-
* this functions is entered with clocks enabled
1265+
* this function is entered with clocks enabled
12661266
*/
1267-
static void flexcan_chip_stop(struct net_device *dev)
1267+
static int __flexcan_chip_stop(struct net_device *dev, bool disable_on_error)
12681268
{
12691269
struct flexcan_priv *priv = netdev_priv(dev);
12701270
struct flexcan_regs __iomem *regs = priv->regs;
1271+
int err;
12711272

12721273
/* freeze + disable module */
1273-
flexcan_chip_freeze(priv);
1274-
flexcan_chip_disable(priv);
1274+
err = flexcan_chip_freeze(priv);
1275+
if (err && !disable_on_error)
1276+
return err;
1277+
err = flexcan_chip_disable(priv);
1278+
if (err && !disable_on_error)
1279+
goto out_chip_unfreeze;
12751280

12761281
/* Disable all interrupts */
12771282
priv->write(0, &regs->imask2);
@@ -1281,6 +1286,23 @@ static void flexcan_chip_stop(struct net_device *dev)
12811286

12821287
flexcan_transceiver_disable(priv);
12831288
priv->can.state = CAN_STATE_STOPPED;
1289+
1290+
return 0;
1291+
1292+
out_chip_unfreeze:
1293+
flexcan_chip_unfreeze(priv);
1294+
1295+
return err;
1296+
}
1297+
1298+
static inline int flexcan_chip_stop_disable_on_error(struct net_device *dev)
1299+
{
1300+
return __flexcan_chip_stop(dev, true);
1301+
}
1302+
1303+
static inline int flexcan_chip_stop(struct net_device *dev)
1304+
{
1305+
return __flexcan_chip_stop(dev, false);
12841306
}
12851307

12861308
static int flexcan_open(struct net_device *dev)
@@ -1362,7 +1384,7 @@ static int flexcan_close(struct net_device *dev)
13621384

13631385
netif_stop_queue(dev);
13641386
can_rx_offload_disable(&priv->offload);
1365-
flexcan_chip_stop(dev);
1387+
flexcan_chip_stop_disable_on_error(dev);
13661388

13671389
can_rx_offload_del(&priv->offload);
13681390
free_irq(dev->irq, dev);

0 commit comments

Comments
 (0)