Module Name:    src
Committed By:   rkujawa
Date:           Fri Feb 15 17:44:41 UTC 2013

Modified Files:
        src/sys/dev/spi: spi.c

Log Message:
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 <[email protected]>


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/spi/spi.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/spi/spi.c
diff -u src/sys/dev/spi/spi.c:1.7 src/sys/dev/spi/spi.c:1.8
--- src/sys/dev/spi/spi.c:1.7	Fri Jan  4 22:23:06 2013
+++ src/sys/dev/spi/spi.c	Fri Feb 15 17:44:40 2013
@@ -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 @@ spi_attach(device_t parent, device_t sel
 	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 @@ spi_attach(device_t parent, device_t sel
 	/*
 	 * 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;

Reply via email to