Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sdmmc Fix uninitialized variable use:



details:   https://anonhg.NetBSD.org/src/rev/87d5e69737fd
branches:  trunk
changeset: 829649:87d5e69737fd
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Feb 07 14:42:07 2018 +0000

description:
Fix uninitialized variable use:
if there is an error, or if we are using a SPI controller,
sdmmc_mem_send_op_cond() doens't assign a value to *ocrp,
but it is used unconditionally in sdmmc_mem_enable() to see if we can switch
to low voltage.

In sdmmc_mem_send_op_cond(), if the new ocr is not returned by the
card for whatever reason, set *ocrp to the orig value.

diffstat:

 sys/dev/sdmmc/sdmmc_mem.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (37 lines):

diff -r 4766a51164ba -r 87d5e69737fd sys/dev/sdmmc/sdmmc_mem.c
--- a/sys/dev/sdmmc/sdmmc_mem.c Wed Feb 07 14:03:18 2018 +0000
+++ b/sys/dev/sdmmc/sdmmc_mem.c Wed Feb 07 14:42:07 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdmmc_mem.c,v 1.63 2017/09/12 13:43:37 jmcneill Exp $  */
+/*     $NetBSD: sdmmc_mem.c,v 1.64 2018/02/07 14:42:07 bouyer Exp $    */
 /*     $OpenBSD: sdmmc_mem.c,v 1.10 2009/01/09 10:55:22 jsg Exp $      */
 
 /*
@@ -45,7 +45,7 @@
 /* Routines for SD/MMC memory cards. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.63 2017/09/12 13:43:37 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.64 2018/02/07 14:42:07 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -644,10 +644,14 @@
                error = ETIMEDOUT;
                sdmmc_delay(10000);
        }
-       if (error == 0 &&
-           ocrp != NULL &&
-           !ISSET(sc->sc_caps, SMC_CAPS_SPI_MODE))
-               *ocrp = MMC_R3(cmd.c_resp);
+       if (ocrp != NULL) {
+               if (error == 0 &&
+                   !ISSET(sc->sc_caps, SMC_CAPS_SPI_MODE)) {
+                       *ocrp = MMC_R3(cmd.c_resp);
+               } else {
+                       *ocrp = ocr;
+               }
+       }
        DPRINTF(("%s: sdmmc_mem_send_op_cond: error=%d, ocr=%#x\n",
            SDMMCDEVNAME(sc), error, MMC_R3(cmd.c_resp)));
        return error;



Home | Main Index | Thread Index | Old Index