Module Name: src Committed By: jmcneill Date: Sun Oct 2 21:12:43 UTC 2011
Modified Files: src/sys/dev/i2c: i2c.c Log Message: iic_ioctl_exec: initialize cmd before using it To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/sys/dev/i2c/i2c.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/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.33 src/sys/dev/i2c/i2c.c:1.34 --- src/sys/dev/i2c/i2c.c:1.33 Sun Oct 2 18:58:45 2011 +++ src/sys/dev/i2c/i2c.c Sun Oct 2 21:12:43 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.33 2011/10/02 18:58:45 jmcneill Exp $ */ +/* $NetBSD: i2c.c,v 1.34 2011/10/02 21:12:43 jmcneill Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.33 2011/10/02 18:58:45 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.34 2011/10/02 21:12:43 jmcneill Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.33 #include <sys/event.h> #include <sys/conf.h> #include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/kthread.h> #include <sys/proc.h> #include <sys/kernel.h> @@ -479,8 +480,8 @@ iic_ioctl_exec(struct iic_softc *sc, i2c { i2c_tag_t ic = sc->sc_tag; uint8_t buf[I2C_EXEC_MAX_BUFLEN]; + void *cmd = NULL; int error; - void *cmd; /* Validate parameters */ if (iie->iie_addr > I2C_MAX_ADDR) @@ -502,9 +503,14 @@ iic_ioctl_exec(struct iic_softc *sc, i2c #endif if (iie->iie_cmd != NULL) { + cmd = kmem_alloc(iie->iie_cmdlen, KM_SLEEP); + if (cmd == NULL) + return ENOMEM; error = copyin(iie->iie_cmd, cmd, iie->iie_cmdlen); - if (error) + if (error) { + kmem_free(cmd, iie->iie_cmdlen); return error; + } } iic_acquire_bus(ic, 0); @@ -512,6 +518,9 @@ iic_ioctl_exec(struct iic_softc *sc, i2c buf, iie->iie_buflen, 0); iic_release_bus(ic, 0); + if (cmd) + kmem_free(cmd, iie->iie_cmdlen); + if (error) return error;