Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/spi Fix usage of uninitialised variable holding numb...



details:   https://anonhg.NetBSD.org/src/rev/5f0f056800e7
branches:  trunk
changeset: 784964:5f0f056800e7
user:      rkujawa <rkujawa%NetBSD.org@localhost>
date:      Fri Feb 15 17:44:40 2013 +0000

description:
Fix usage of uninitialised variable holding number of slave devices.
The sc_nslaves has to be initialised before it is used in allocation of a memory holding save devices' configuration, otherwise slave drivers are causing kernel crashes.

Patch from Semihalf.
Author: Michal Dubiel <md%semihalf.com@localhost>

diffstat:

 sys/dev/spi/spi.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (34 lines):

diff -r 2473ee6af95f -r 5f0f056800e7 sys/dev/spi/spi.c
--- a/sys/dev/spi/spi.c Fri Feb 15 17:09:38 2013 +0000
+++ b/sys/dev/spi/spi.c Fri Feb 15 17:44:40 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.7 2013/01/04 22:23:06 jakllsch Exp $ */
+/* $NetBSD: spi.c,v 1.8 2013/02/15 17:44:40 rkujawa Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.7 2013/01/04 22:23:06 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.8 2013/02/15 17:44:40 rkujawa Exp $");
 
 #include "locators.h"
 
@@ -143,6 +143,7 @@
        aprint_normal(": SPI bus\n");
 
        sc->sc_controller = *sba->sba_controller;
+       sc->sc_nslaves = sba->sba_controller->sct_nslaves;
        /* allocate slave structures */
        sc->sc_slaves = malloc(sizeof (struct spi_handle) * sc->sc_nslaves,
            M_DEVBUF, M_WAITOK | M_ZERO);
@@ -153,7 +154,6 @@
        /*
         * Initialize slave handles
         */
-       sc->sc_nslaves = sba->sba_controller->sct_nslaves;
        for (i = 0; i < sc->sc_nslaves; i++) {
                sc->sc_slaves[i].sh_slave = i;
                sc->sc_slaves[i].sh_sc = sc;



Home | Main Index | Thread Index | Old Index