提交 9e6fd874 编写于 作者: J Jiasheng Jiang 提交者: David S. Miller

net: prestera: acl: Add check for kmemdup

As the kemdup could return NULL, it should be better to check the return
value and return error if fails.
Moreover, the return value of prestera_acl_ruleset_keymask_set() should
be checked by cascade.

Fixes: 604ba230 ("net: prestera: flower template support")
Signed-off-by: NJiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Taras Chornyi<tchornyi@marvell.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 73ea7350
......@@ -178,10 +178,14 @@ prestera_acl_ruleset_create(struct prestera_acl *acl,
return ERR_PTR(err);
}
void prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
void *keymask)
int prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
void *keymask)
{
ruleset->keymask = kmemdup(keymask, ACL_KEYMASK_SIZE, GFP_KERNEL);
if (!ruleset->keymask)
return -ENOMEM;
return 0;
}
int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset)
......
......@@ -185,8 +185,8 @@ struct prestera_acl_ruleset *
prestera_acl_ruleset_lookup(struct prestera_acl *acl,
struct prestera_flow_block *block,
u32 chain_index);
void prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
void *keymask);
int prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
void *keymask);
bool prestera_acl_ruleset_is_offload(struct prestera_acl_ruleset *ruleset);
int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset);
void prestera_acl_ruleset_put(struct prestera_acl_ruleset *ruleset);
......
......@@ -452,7 +452,9 @@ int prestera_flower_tmplt_create(struct prestera_flow_block *block,
}
/* preserve keymask/template to this ruleset */
prestera_acl_ruleset_keymask_set(ruleset, rule.re_key.match.mask);
err = prestera_acl_ruleset_keymask_set(ruleset, rule.re_key.match.mask);
if (err)
goto err_ruleset_keymask_set;
/* skip error, as it is not possible to reject template operation,
* so, keep the reference to the ruleset for rules to be added
......@@ -468,6 +470,8 @@ int prestera_flower_tmplt_create(struct prestera_flow_block *block,
list_add_rcu(&template->list, &block->template_list);
return 0;
err_ruleset_keymask_set:
prestera_acl_ruleset_put(ruleset);
err_ruleset_get:
kfree(template);
err_malloc:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册