diff mbox series

sch_gred: kzalloc needs null check

Message ID 20190719013026.24297-1-navid.emamdoost@gmail.com
State Rejected
Delegated to: David Miller
Headers show
Series sch_gred: kzalloc needs null check | expand

Commit Message

Navid Emamdoost July 19, 2019, 1:30 a.m. UTC
call to kzalloc may fail and return null. So the result should be checked
against null. Added the check to cover kzalloc failure case.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 net/sched/sch_gred.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Eric Dumazet July 19, 2019, 1:42 a.m. UTC | #1
On 7/19/19 3:30 AM, Navid Emamdoost wrote:
> call to kzalloc may fail and return null. So the result should be checked
> against null. Added the check to cover kzalloc failure case.
> 
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  net/sched/sch_gred.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
> index 8599c6f31b05..5cd0859f0274 100644
> --- a/net/sched/sch_gred.c
> +++ b/net/sched/sch_gred.c
> @@ -697,6 +697,9 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt,
>  	}
>  
>  	prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL);
> +	if (!prealloc)
> +		return -ENOMEM;
> +
>  	sch_tree_lock(sch);
>  
>  	err = gred_change_vq(sch, ctl->DP, ctl, prio, stab, max_P, &prealloc,
> 

This seems not needed.

The case is handled later in gred_change_vq()
diff mbox series

Patch

diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index 8599c6f31b05..5cd0859f0274 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -697,6 +697,9 @@  static int gred_change(struct Qdisc *sch, struct nlattr *opt,
 	}
 
 	prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL);
+	if (!prealloc)
+		return -ENOMEM;
+
 	sch_tree_lock(sch);
 
 	err = gred_change_vq(sch, ctl->DP, ctl, prio, stab, max_P, &prealloc,