Skip to content

Commit 9e6fd87

Browse files
JiangJiasdavem330
authored andcommitted
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: 604ba23 ("net: prestera: flower template support") Signed-off-by: Jiasheng Jiang <[email protected]> Reviewed-by: Taras Chornyi<[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 73ea735 commit 9e6fd87

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

drivers/net/ethernet/marvell/prestera/prestera_acl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,14 @@ prestera_acl_ruleset_create(struct prestera_acl *acl,
178178
return ERR_PTR(err);
179179
}
180180

181-
void prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
182-
void *keymask)
181+
int prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
182+
void *keymask)
183183
{
184184
ruleset->keymask = kmemdup(keymask, ACL_KEYMASK_SIZE, GFP_KERNEL);
185+
if (!ruleset->keymask)
186+
return -ENOMEM;
187+
188+
return 0;
185189
}
186190

187191
int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset)

drivers/net/ethernet/marvell/prestera/prestera_acl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ struct prestera_acl_ruleset *
185185
prestera_acl_ruleset_lookup(struct prestera_acl *acl,
186186
struct prestera_flow_block *block,
187187
u32 chain_index);
188-
void prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
189-
void *keymask);
188+
int prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
189+
void *keymask);
190190
bool prestera_acl_ruleset_is_offload(struct prestera_acl_ruleset *ruleset);
191191
int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset);
192192
void prestera_acl_ruleset_put(struct prestera_acl_ruleset *ruleset);

drivers/net/ethernet/marvell/prestera/prestera_flower.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ int prestera_flower_tmplt_create(struct prestera_flow_block *block,
452452
}
453453

454454
/* preserve keymask/template to this ruleset */
455-
prestera_acl_ruleset_keymask_set(ruleset, rule.re_key.match.mask);
455+
err = prestera_acl_ruleset_keymask_set(ruleset, rule.re_key.match.mask);
456+
if (err)
457+
goto err_ruleset_keymask_set;
456458

457459
/* skip error, as it is not possible to reject template operation,
458460
* 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,
468470
list_add_rcu(&template->list, &block->template_list);
469471
return 0;
470472

473+
err_ruleset_keymask_set:
474+
prestera_acl_ruleset_put(ruleset);
471475
err_ruleset_get:
472476
kfree(template);
473477
err_malloc:

0 commit comments

Comments
 (0)