Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c - dbcool_pmf_suspend() set the wrong bit out of ...



details:   https://anonhg.NetBSD.org/src/rev/42fa42ac21c0
branches:  trunk
changeset: 448448:42fa42ac21c0
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Feb 03 11:58:02 2019 +0000

description:
- dbcool_pmf_suspend() set the wrong bit out of the suspended data as
  it is stored as a bool and thus when bit 2 was wanted, bit 1 was
  restored.  found by GCC7's "don't use ~ on bool" checker.
- consolidate the dbcool_pmf_suspend()/dbcool_pmf_resume() guts in to
  a shared function dbcool_do_pmf() as they are identical except for
  1 vs 2 lines.

diffstat:

 sys/dev/i2c/dbcool.c |  46 +++++++++++++++++++++++-----------------------
 1 files changed, 23 insertions(+), 23 deletions(-)

diffs (83 lines):

diff -r 3e1d87e8a3ec -r 42fa42ac21c0 sys/dev/i2c/dbcool.c
--- a/sys/dev/i2c/dbcool.c      Sun Feb 03 11:57:25 2019 +0000
+++ b/sys/dev/i2c/dbcool.c      Sun Feb 03 11:58:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dbcool.c,v 1.52 2018/06/26 06:03:57 thorpej Exp $ */
+/*     $NetBSD: dbcool.c,v 1.53 2019/02/03 11:58:02 mrg Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.52 2018/06/26 06:03:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.53 2019/02/03 11:58:02 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -825,8 +825,13 @@
        return 0;
 }
 
-/* On suspend, we save the state of the SHDN bit, then set it */
-bool dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual)
+/*
+ * On suspend, we save the state of the SHDN bit, then set it
+ * On resume, we restore the previous state of the SHDN bit (which
+ * we saved in sc_suspend)
+ */
+static bool
+dbcool_do_pmf(device_t dev, const pmf_qual_t *qual, bool suspend)
 {
        struct dbcool_softc *sc = device_private(dev);
        uint8_t reg, bit, cfg;
@@ -842,34 +847,29 @@
                bit = DBCOOL_CFG2_SHDN;
        }
        cfg = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
-       sc->sc_suspend = cfg & bit;
-       cfg |= bit;
+       if (suspend) {
+               sc->sc_suspend = (cfg & bit) != 0;
+               cfg |= bit;
+       } else {
+               cfg &= sc->sc_suspend ? bit : 0;
+       }
        sc->sc_dc.dc_writereg(&sc->sc_dc, reg, cfg);
 
        return true;
 }
 
-/* On resume, we restore the previous state of the SHDN bit (which
-   we saved in sc_suspend) */
-bool dbcool_pmf_resume(device_t dev, const pmf_qual_t *qual)
+bool
+dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual)
 {
-       struct dbcool_softc *sc = device_private(dev);
-       uint8_t reg, cfg;
-
-       if ((sc->sc_dc.dc_chip->flags & DBCFLAG_HAS_SHDN) == 0)
-               return true;
 
-       if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADT7466) {
-               reg = DBCOOL_ADT7466_CONFIG2;
-       } else {
-               reg = DBCOOL_CONFIG2_REG;
-       }
-       cfg = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
-       cfg &= ~sc->sc_suspend;
-       sc->sc_dc.dc_writereg(&sc->sc_dc, reg, cfg);
+       return dbcool_do_pmf(dev, qual, true);
+}
 
-       return true;
+bool
+dbcool_pmf_resume(device_t dev, const pmf_qual_t *qual)
+{
 
+       return dbcool_do_pmf(dev, qual, false);
 }
 
 uint8_t



Home | Main Index | Thread Index | Old Index