Module Name: src Committed By: martin Date: Mon Jul 20 19:00:40 UTC 2020
Modified Files: src/sys/dev/i2c [netbsd-8]: sdtemp.c Log Message: Pull up the following revisions, requested by msaitoh in ticket #1580: sys/dev/i2c/sdtemp.c 1.35, 1.37-1.39 - Check the return value of iic_acquire_bus() because this function may fail. - Fix typo in comment. - KNF. To generate a diff of this commit: cvs rdiff -u -r1.32.8.1 -r1.32.8.2 src/sys/dev/i2c/sdtemp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/i2c/sdtemp.c diff -u src/sys/dev/i2c/sdtemp.c:1.32.8.1 src/sys/dev/i2c/sdtemp.c:1.32.8.2 --- src/sys/dev/i2c/sdtemp.c:1.32.8.1 Thu Mar 8 14:29:12 2018 +++ src/sys/dev/i2c/sdtemp.c Mon Jul 20 19:00:40 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: sdtemp.c,v 1.32.8.1 2018/03/08 14:29:12 martin Exp $ */ +/* $NetBSD: sdtemp.c,v 1.32.8.2 2020/07/20 19:00:40 martin Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.32.8.1 2018/03/08 14:29:12 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.32.8.2 2020/07/20 19:00:40 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -214,8 +214,13 @@ sdtemp_match(device_t parent, cfdata_t c if ((ia->ia_addr & SDTEMP_ADDRMASK) != SDTEMP_ADDR) return 0; - /* Verify that we can read the manufacturer ID, Device ID and the capability */ - iic_acquire_bus(sc.sc_tag, 0); + /* + * Verify that we can read the manufacturer ID, Device ID and the + * capability + */ + error = iic_acquire_bus(sc.sc_tag, 0); + if (error) + return 0; error = sdtemp_read_16(&sc, SDTEMP_REG_MFG_ID, &mfgid) | sdtemp_read_16(&sc, SDTEMP_REG_DEV_REV, &devid) | sdtemp_read_16(&sc, SDTEMP_REG_CAPABILITY, &cap); @@ -234,8 +239,8 @@ sdtemp_match(device_t parent, cfdata_t c } /* - * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the alarm - * capability, too. + * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the + * alarm capability, too. */ if ((cap & SDTEMP_CAP_HAS_ALARM) == 0) return 0; @@ -255,7 +260,10 @@ sdtemp_attach(device_t parent, device_t sc->sc_address = ia->ia_addr; sc->sc_dev = self; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error) + return; + if ((error = sdtemp_read_16(sc, SDTEMP_REG_MFG_ID, &mfgid)) != 0 || (error = sdtemp_read_16(sc, SDTEMP_REG_DEV_REV, &devid)) != 0) { iic_release_bus(sc->sc_tag, 0); @@ -297,7 +305,7 @@ sdtemp_attach(device_t parent, device_t * IDT's devices and some Microchip's devices have the resolution * register in the vendor specific registers area. The devices' * resolution bits in the capability register are not the maximum - * resolution but the current vaule of the setting. + * resolution but the current value of the setting. */ if (sdtemp_dev_table[i].sdtemp_config != NULL) sdtemp_dev_table[i].sdtemp_config(sc); @@ -428,7 +436,9 @@ sdtemp_get_limits(struct sysmon_envsys * uint16_t lim; *props = 0; - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0) != 0) + return; + if (sdtemp_read_16(sc, SDTEMP_REG_LOWER_LIM, &lim) == 0 && lim != 0) { limits->sel_warnmin = sdtemp_decode_temp(sc, lim); *props |= PROP_WARNMIN; @@ -458,7 +468,9 @@ sdtemp_set_limits(struct sysmon_envsys * limits = &sc->sc_deflims; props = &sc->sc_defprops; } - iic_acquire_bus(sc->sc_tag, 0); + if (iic_acquire_bus(sc->sc_tag, 0) != 0) + return; + if (*props & PROP_WARNMIN) { val = __UK2C(limits->sel_warnmin); (void)sdtemp_write_16(sc, SDTEMP_REG_LOWER_LIM, @@ -570,7 +582,12 @@ sdtemp_refresh(struct sysmon_envsys *sme uint16_t val; int error; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error) { + edata->state = ENVSYS_SINVALID; + return; + } + error = sdtemp_read_16(sc, SDTEMP_REG_AMBIENT_TEMP, &val); iic_release_bus(sc->sc_tag, 0); @@ -598,7 +615,7 @@ sdtemp_refresh(struct sysmon_envsys *sme } /* - * power management functions + * Power management functions * * We go into "shutdown" mode at suspend time, and return to normal * mode upon resume. This reduces power consumption by disabling @@ -612,7 +629,10 @@ sdtemp_pmf_suspend(device_t dev, const p int error; uint16_t config; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error != 0) + return false; + error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, &config); if (error == 0) { config |= SDTEMP_CONFIG_SHUTDOWN_MODE; @@ -629,7 +649,10 @@ sdtemp_pmf_resume(device_t dev, const pm int error; uint16_t config; - iic_acquire_bus(sc->sc_tag, 0); + error = iic_acquire_bus(sc->sc_tag, 0); + if (error != 0) + return false; + error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, &config); if (error == 0) { config &= ~SDTEMP_CONFIG_SHUTDOWN_MODE;