Module Name:    src
Committed By:   martin
Date:           Sun Feb  2 15:01:35 UTC 2025

Modified Files:
        src/sys/dev/i2c [netbsd-10]: i2c.c

Log Message:
Pull up following revision(s) (requested by brad in ticket #1044):

        sys/dev/i2c/i2c.c: revision 1.91

Fix a likely bug in iic_ioctl.

The error variable was being over written by the copyout call.  The
effect here is that the I2C transaction could have errored, but then
the copyout is performed in the read case and if that worked, error
would end up 0.  Just don't do the copyout if the I2C transaction
errored.

Also, don't return twice.  Once is enough.

With this, "i2cscan -r ..." on a RPI will work as expected.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.90.2.1 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.90 src/sys/dev/i2c/i2c.c:1.90.2.1
--- src/sys/dev/i2c/i2c.c:1.90	Mon Oct 24 10:17:40 2022
+++ src/sys/dev/i2c/i2c.c	Sun Feb  2 15:01:35 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.90 2022/10/24 10:17:40 riastradh Exp $	*/
+/*	$NetBSD: i2c.c,v 1.90.2.1 2025/02/02 15:01:35 martin Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -53,7 +53,7 @@
 #endif /* _KERNEL_OPT */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.90 2022/10/24 10:17:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.90.2.1 2025/02/02 15:01:35 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -685,7 +685,7 @@ iic_ioctl_exec(struct iic_softc *sc, i2c
 	i2c_tag_t ic = sc->sc_tag;
 	uint8_t *buf = NULL;
 	void *cmd = NULL;
-	int error;
+	int error=0;
 
 	/* Validate parameters */
 	if (iie->iie_addr > I2C_MAX_ADDR)
@@ -734,7 +734,7 @@ iic_ioctl_exec(struct iic_softc *sc, i2c
 		error = EIO;
 
 out:
-	if (iie->iie_buf != NULL && I2C_OP_READ_P(iie->iie_op))
+	if (!error && iie->iie_buf != NULL && I2C_OP_READ_P(iie->iie_op))
 		error = copyout(buf, iie->iie_buf, iie->iie_buflen);
 
 	if (buf)
@@ -743,9 +743,6 @@ out:
 	if (cmd)
 		kmem_free(cmd, iie->iie_cmdlen);
 
-	if (error)
-		return error;
-
 	return error;
 }
 

Reply via email to