Skip to content

Commit

Permalink
Use old limit of 32 + 32 bytes to keep combining buffer on stack.
Browse files Browse the repository at this point in the history
There are no devices on this platform that need more and for larger
values, the driver should be better rewritten.
  • Loading branch information
mlelstv authored and mlelstv committed Jun 29, 2022
1 parent 9db9d32 commit b169b89
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sys/arch/macppc/dev/ki2c.c
@@ -1,4 +1,4 @@
/* $NetBSD: ki2c.c,v 1.32 2021/08/07 16:18:57 thorpej Exp $ */
/* $NetBSD: ki2c.c,v 1.33 2022/06/29 17:59:40 mlelstv Exp $ */
/* Id: ki2c.c,v 1.7 2002/10/05 09:56:05 tsubai Exp */

/*-
Expand Down Expand Up @@ -44,6 +44,9 @@
#define DPRINTF while (0) printf
#endif

#define KI2C_EXEC_MAX_CMDLEN 32
#define KI2C_EXEC_MAX_BUFLEN 32

int ki2c_match(device_t, cfdata_t, void *);
void ki2c_attach(device_t, device_t, void *);
inline uint8_t ki2c_readreg(struct ki2c_softc *, int);
Expand Down Expand Up @@ -393,7 +396,7 @@ ki2c_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *vcmd,
int i;
size_t w_len;
uint8_t *wp;
uint8_t wrbuf[I2C_EXEC_MAX_CMDLEN + I2C_EXEC_MAX_CMDLEN];
uint8_t wrbuf[KI2C_EXEC_MAX_CMDLEN + KI2C_EXEC_MAX_CMDLEN];
uint8_t channel;

/*
Expand All @@ -404,6 +407,13 @@ ki2c_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *vcmd,
if (cmdlen == 0 && buflen == 0)
return -1;

/*
* Transaction could be much larger now. Bail if it exceeds our
* small combining buffer, we don't expect such devices.
*/
if (cmdlen + buflen > sizeof(wrbuf))
return -1;

channel = (addr & 0xf80) ? 0x10 : 0x00;
addr &= 0x7f;

Expand Down

0 comments on commit b169b89

Please sign in to comment.