Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c More correctly handle I?C exec ioctls with both ...



details:   https://anonhg.NetBSD.org/src/rev/bbf1fdd640fb
branches:  trunk
changeset: 335738:bbf1fdd640fb
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Thu Jan 22 17:56:35 2015 +0000

description:
More correctly handle I?C exec ioctls with both a command and write data
phase. Previously the data phase of ioctl writes was sending uninitialized
kernel stack to the addressed device.

diffstat:

 sys/dev/i2c/i2c.c |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (41 lines):

diff -r 5e216623e80d -r bbf1fdd640fb sys/dev/i2c/i2c.c
--- a/sys/dev/i2c/i2c.c Thu Jan 22 17:49:41 2015 +0000
+++ b/sys/dev/i2c/i2c.c Thu Jan 22 17:56:35 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2c.c,v 1.45 2014/12/07 00:32:35 jmcneill Exp $        */
+/*     $NetBSD: i2c.c,v 1.46 2015/01/22 17:56:35 jakllsch Exp $        */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.45 2014/12/07 00:32:35 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.46 2015/01/22 17:56:35 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -525,6 +525,13 @@
                }
        }
 
+       if (iie->iie_buf != NULL && I2C_OP_WRITE_P(iie->iie_op)) {
+               error = copyin(iie->iie_buf, buf, iie->iie_buflen);
+               if (error) {
+                       return error;
+               }
+       }
+
        iic_acquire_bus(ic, 0);
        error = iic_exec(ic, iie->iie_op, iie->iie_addr, cmd, iie->iie_cmdlen,
            buf, iie->iie_buflen, 0);
@@ -542,7 +549,7 @@
        if (error)
                return error;
 
-       if (iie->iie_buf)
+       if (iie->iie_buf != NULL && I2C_OP_READ_P(iie->iie_op))
                error = copyout(buf, iie->iie_buf, iie->iie_buflen);
 
        return error;



Home | Main Index | Thread Index | Old Index