diff options
| author | mlelstv <mlelstv@NetBSD.org> | 2022-06-29 15:33:45 +0000 |
|---|---|---|
| committer | mlelstv <mlelstv@NetBSD.org> | 2022-06-29 15:33:45 +0000 |
| commit | a37afe8e4fce3d7a94f1fe2fc68fd91518dcee9c (patch) | |
| tree | 5fc3976b3411fa1b3f545bd8139fe09a85155e62 /sys/dev | |
| parent | d8b90f072bdf08491facb4bcfdf6b4e728ab3fa3 (diff) | |
Allocate data buffer instead of using the stack.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/i2c/i2c.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/sys/dev/i2c/i2c.c b/sys/dev/i2c/i2c.c index 16bc8cec6c6..6ff6e2cd912 100644 --- a/sys/dev/i2c/i2c.c +++ b/sys/dev/i2c/i2c.c @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.86 2022/04/01 15:49:12 pgoyette Exp $ */ +/* $NetBSD: i2c.c,v 1.87 2022/06/29 15:33:45 mlelstv 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.86 2022/04/01 15:49:12 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.87 2022/06/29 15:33:45 mlelstv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -819,7 +819,7 @@ static int iic_ioctl_exec(struct iic_softc *sc, i2c_ioctl_exec_t *iie, int flag) { i2c_tag_t ic = sc->sc_tag; - uint8_t buf[I2C_EXEC_MAX_BUFLEN]; + uint8_t *buf = NULL; void *cmd = NULL; int error; @@ -849,10 +849,13 @@ iic_ioctl_exec(struct iic_softc *sc, i2c_ioctl_exec_t *iie, int flag) goto out; } - if (iie->iie_buf != NULL && I2C_OP_WRITE_P(iie->iie_op)) { - error = copyin(iie->iie_buf, buf, iie->iie_buflen); - if (error) - goto out; + if (iie->iie_buf != NULL) { + buf = kmem_alloc(iie->iie_buflen, KM_SLEEP); + if (I2C_OP_WRITE_P(iie->iie_op)) { + error = copyin(iie->iie_buf, buf, iie->iie_buflen); + if (error) + goto out; + } } iic_acquire_bus(ic, 0); @@ -867,15 +870,18 @@ iic_ioctl_exec(struct iic_softc *sc, i2c_ioctl_exec_t *iie, int flag) error = EIO; out: + if (iie->iie_buf != NULL && I2C_OP_READ_P(iie->iie_op)) + error = copyout(buf, iie->iie_buf, iie->iie_buflen); + + if (buf) + kmem_free(buf, iie->iie_buflen); + if (cmd) kmem_free(cmd, iie->iie_cmdlen); if (error) return error; - if (iie->iie_buf != NULL && I2C_OP_READ_P(iie->iie_op)) - error = copyout(buf, iie->iie_buf, iie->iie_buflen); - return error; } |
