Commit 4c1f602d authored by Zhengchao Shao's avatar Zhengchao Shao Committed by Jakub Kicinski

net: hinic: fix memory leak when reading function table

When the input parameter idx meets the expected case option in
hinic_dbg_get_func_table(), read_data is not released. Fix it.

Fixes: 5215e162 ("hinic: add support to query function table")
Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c0605cd6
...@@ -85,6 +85,7 @@ static int hinic_dbg_get_func_table(struct hinic_dev *nic_dev, int idx) ...@@ -85,6 +85,7 @@ static int hinic_dbg_get_func_table(struct hinic_dev *nic_dev, int idx)
struct tag_sml_funcfg_tbl *funcfg_table_elem; struct tag_sml_funcfg_tbl *funcfg_table_elem;
struct hinic_cmd_lt_rd *read_data; struct hinic_cmd_lt_rd *read_data;
u16 out_size = sizeof(*read_data); u16 out_size = sizeof(*read_data);
int ret = ~0;
int err; int err;
read_data = kzalloc(sizeof(*read_data), GFP_KERNEL); read_data = kzalloc(sizeof(*read_data), GFP_KERNEL);
...@@ -111,20 +112,25 @@ static int hinic_dbg_get_func_table(struct hinic_dev *nic_dev, int idx) ...@@ -111,20 +112,25 @@ static int hinic_dbg_get_func_table(struct hinic_dev *nic_dev, int idx)
switch (idx) { switch (idx) {
case VALID: case VALID:
return funcfg_table_elem->dw0.bs.valid; ret = funcfg_table_elem->dw0.bs.valid;
break;
case RX_MODE: case RX_MODE:
return funcfg_table_elem->dw0.bs.nic_rx_mode; ret = funcfg_table_elem->dw0.bs.nic_rx_mode;
break;
case MTU: case MTU:
return funcfg_table_elem->dw1.bs.mtu; ret = funcfg_table_elem->dw1.bs.mtu;
break;
case RQ_DEPTH: case RQ_DEPTH:
return funcfg_table_elem->dw13.bs.cfg_rq_depth; ret = funcfg_table_elem->dw13.bs.cfg_rq_depth;
break;
case QUEUE_NUM: case QUEUE_NUM:
return funcfg_table_elem->dw13.bs.cfg_q_num; ret = funcfg_table_elem->dw13.bs.cfg_q_num;
break;
} }
kfree(read_data); kfree(read_data);
return ~0; return ret;
} }
static ssize_t hinic_dbg_cmd_read(struct file *filp, char __user *buffer, size_t count, static ssize_t hinic_dbg_cmd_read(struct file *filp, char __user *buffer, size_t count,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment