From 77c8c4e6710b7b5cba3f6a8d733c76c3b5f9809b Mon Sep 17 00:00:00 2001 From: mlelstv Date: Sun, 13 Jun 2021 09:48:04 +0000 Subject: [PATCH] iic_acquire_bus can fail --- sys/dev/i2c/lm_i2c.c | 10 ++++++---- sys/dev/i2c/spdmem_i2c.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/sys/dev/i2c/lm_i2c.c b/sys/dev/i2c/lm_i2c.c index b651363d41b9..dbbe0a7e77ed 100644 --- a/sys/dev/i2c/lm_i2c.c +++ b/sys/dev/i2c/lm_i2c.c @@ -1,4 +1,4 @@ -/* $NetBSD: lm_i2c.c,v 1.6 2020/06/24 19:11:49 jdolecek Exp $ */ +/* $NetBSD: lm_i2c.c,v 1.7 2021/06/13 09:48:44 mlelstv Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.6 2020/06/24 19:11:49 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.7 2021/06/13 09:48:44 mlelstv Exp $"); #include #include @@ -119,7 +119,8 @@ lm_i2c_readreg(struct lm_softc *lmsc, int reg) struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc; uint8_t cmd, data; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return 0; cmd = reg; iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, @@ -137,7 +138,8 @@ lm_i2c_writereg(struct lm_softc *lmsc, int reg, uint8_t val) struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc; uint8_t cmd, data; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0)) + return; cmd = reg; data = val; diff --git a/sys/dev/i2c/spdmem_i2c.c b/sys/dev/i2c/spdmem_i2c.c index 0e53cd86b241..1b191181b696 100644 --- a/sys/dev/i2c/spdmem_i2c.c +++ b/sys/dev/i2c/spdmem_i2c.c @@ -1,4 +1,4 @@ -/* $NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $ */ +/* $NetBSD: spdmem_i2c.c,v 1.22 2021/06/13 09:48:04 mlelstv Exp $ */ /* * Copyright (c) 2007 Nicolas Joly @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.22 2021/06/13 09:48:04 mlelstv Exp $"); #include #include @@ -107,7 +107,9 @@ spdmem_reset_page(struct spdmem_i2c_softc *sc) reg = 0; - iic_acquire_bus(sc->sc_tag, 0); + rv = iic_acquire_bus(sc->sc_tag, 0); + if (rv) + return rv; /* * Try to read byte 0 and 2. If it failed, it's not spdmem or a device @@ -265,7 +267,9 @@ spdmem_i2c_read(struct spdmem_softc *softc, uint16_t addr, uint8_t *val) reg = addr & 0xff; - iic_acquire_bus(sc->sc_tag, 0); + rv = iic_acquire_bus(sc->sc_tag, 0); + if (rv) + return rv; if (addr & 0x100) { rv = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_page1,