From 43a98662f3a794f51305a26475c102e10fd09f50 Mon Sep 17 00:00:00 2001 From: Augusto Fraga Giachero Date: Thu, 18 Feb 2021 08:17:44 -0300 Subject: [PATCH] lpc17xx_40xx/lpc17_40_i2c.c: Propagate I2C I/O errors Check if all messages were transferred, if not, return -ENXIO. This is particularly useful when the slave returns an unexpected NAK, the application code should catch the error to avoid failing silently. --- arch/arm/src/lpc17xx_40xx/lpc17_40_i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_i2c.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_i2c.c index 03223feab7..0c1547c4e9 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_i2c.c +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_i2c.c @@ -242,7 +242,9 @@ static int lpc17_40_i2c_start(struct lpc17_40_i2cdev_s *priv) lpc17_40_i2c_timeout, (wdparm_t)priv); nxsem_wait(&priv->wait); - return priv->nmsg; + /* Remaining messages should be zero or an error occurred */ + + return priv->nmsg ? -ENXIO : OK; } /****************************************************************************