iic_acquire_bus can fail

This commit is contained in:
mlelstv 2021-06-13 09:48:04 +00:00
parent 65c5d463c9
commit 77c8c4e671
2 changed files with 14 additions and 8 deletions

View File

@ -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. * Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -119,7 +119,8 @@ lm_i2c_readreg(struct lm_softc *lmsc, int reg)
struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc; struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc;
uint8_t cmd, data; uint8_t cmd, data;
iic_acquire_bus(sc->sc_tag, 0); if (iic_acquire_bus(sc->sc_tag, 0))
return 0;
cmd = reg; cmd = reg;
iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, 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; struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc;
uint8_t cmd, data; uint8_t cmd, data;
iic_acquire_bus(sc->sc_tag, 0); if (iic_acquire_bus(sc->sc_tag, 0))
return;
cmd = reg; cmd = reg;
data = val; data = val;

View File

@ -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 * Copyright (c) 2007 Nicolas Joly
@ -40,7 +40,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/param.h> #include <sys/param.h>
#include <sys/device.h> #include <sys/device.h>
@ -107,7 +107,9 @@ spdmem_reset_page(struct spdmem_i2c_softc *sc)
reg = 0; 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 * 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; 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) { if (addr & 0x100) {
rv = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_page1, rv = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_page1,