asoc: Avoid usage of variable length array

chmap in msm_lsm_check_and_set_lab_controls, data in
wcd9xxx_i2c_write_device and irq_level in wcd9xxx_irq_init
are Variable Length Array (VLA). VLAs are considered unfit
when it comes to security, performance, code quality and so
on. Hence, allocate the memory dynamically.

Change-Id: I52f33e61f857a00774eb26dc1d6372f2ed3d425c
Signed-off-by: Meng Wang <mengw@codeaurora.org>
此提交包含在:
Meng Wang
2018-11-13 09:28:48 +08:00
提交者 Gerrit - the friendly Code Review server
父節點 61af6849e9
當前提交 c7b180ec7c
共有 3 個檔案被更改,包括 30 行新增13 行删除

查看文件

@@ -844,7 +844,7 @@ static int wcd9xxx_i2c_write_device(struct wcd9xxx *wcd9xxx, u16 reg, u8 *value,
struct i2c_msg *msg;
int ret = 0;
u8 reg_addr = 0;
u8 data[bytes + 1];
u8 *data = NULL;
struct wcd9xxx_i2c *wcd9xxx_i2c;
wcd9xxx_i2c = wcd9xxx_i2c_get_device_info(wcd9xxx, reg);
@@ -852,6 +852,11 @@ static int wcd9xxx_i2c_write_device(struct wcd9xxx *wcd9xxx, u16 reg, u8 *value,
pr_err("failed to get device info\n");
return -ENODEV;
}
data = kzalloc(bytes + 1, GFP_KERNEL);
if (!data)
return -ENOMEM;
reg_addr = (u8)reg;
msg = &wcd9xxx_i2c->xfer_msg[0];
msg->addr = wcd9xxx_i2c->client->addr;
@@ -868,11 +873,13 @@ static int wcd9xxx_i2c_write_device(struct wcd9xxx *wcd9xxx, u16 reg, u8 *value,
wcd9xxx_i2c->xfer_msg, 1);
if (ret != 1) {
pr_err("failed to write the device\n");
return ret;
goto fail;
}
}
pr_debug("write success register = %x val = %x\n", reg, data[1]);
return 0;
fail:
kfree(data);
return ret;
}