static int m88ts2022_wr_regs(struct m88ts2022_priv *priv,
u8 reg, const u8 *val, int len)
{
+#define MAX_WR_LEN 3
+#define MAX_WR_XFER_LEN (MAX_WR_LEN + 1)
int ret;
- u8 buf[1 + len];
+ u8 buf[MAX_WR_XFER_LEN];
struct i2c_msg msg[1] = {
{
.addr = priv->cfg->i2c_addr,
.flags = 0,
- .len = sizeof(buf),
+ .len = 1 + len,
.buf = buf,
}
};
+ if (WARN_ON(len > MAX_WR_LEN))
+ return -EINVAL;
+
buf[0] = reg;
memcpy(&buf[1], val, len);
static int m88ts2022_rd_regs(struct m88ts2022_priv *priv, u8 reg,
u8 *val, int len)
{
+#define MAX_RD_LEN 1
+#define MAX_RD_XFER_LEN (MAX_RD_LEN)
int ret;
- u8 buf[len];
+ u8 buf[MAX_RD_XFER_LEN];
struct i2c_msg msg[2] = {
{
.addr = priv->cfg->i2c_addr,
}, {
.addr = priv->cfg->i2c_addr,
.flags = I2C_M_RD,
- .len = sizeof(buf),
+ .len = len,
.buf = buf,
}
};
+ if (WARN_ON(len > MAX_RD_LEN))
+ return -EINVAL;
+
ret = i2c_transfer(priv->i2c, msg, 2);
if (ret == 2) {
memcpy(val, buf, len);