Skip to content

Commit

Permalink
net: hinic: fix memory leak when reading function table
Browse files Browse the repository at this point in the history
[ Upstream commit 4c1f602 ]

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

Fixes: 5215e16 ("hinic: add support to query function table")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
zhengchaoshao authored and gregkh committed Nov 3, 2022
1 parent 62aa78a commit e6765fe
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions drivers/net/ethernet/huawei/hinic/hinic_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 hinic_cmd_lt_rd *read_data;
u16 out_size = sizeof(*read_data);
int ret = ~0;
int err;

read_data = kzalloc(sizeof(*read_data), GFP_KERNEL);
Expand All @@ -111,20 +112,25 @@ static int hinic_dbg_get_func_table(struct hinic_dev *nic_dev, int idx)

switch (idx) {
case VALID:
return funcfg_table_elem->dw0.bs.valid;
ret = funcfg_table_elem->dw0.bs.valid;
break;
case RX_MODE:
return funcfg_table_elem->dw0.bs.nic_rx_mode;
ret = funcfg_table_elem->dw0.bs.nic_rx_mode;
break;
case MTU:
return funcfg_table_elem->dw1.bs.mtu;
ret = funcfg_table_elem->dw1.bs.mtu;
break;
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:
return funcfg_table_elem->dw13.bs.cfg_q_num;
ret = funcfg_table_elem->dw13.bs.cfg_q_num;
break;
}

kfree(read_data);

return ~0;
return ret;
}

static ssize_t hinic_dbg_cmd_read(struct file *filp, char __user *buffer, size_t count,
Expand Down

0 comments on commit e6765fe

Please sign in to comment.