Skip to contentSkip to conversation

sch_gred: kzalloc needs null check

PATCH In review Navid Emamdoost 2 participants 2 messages Jul 19, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sch_gred: kzalloc needs null check

call to kzalloc may fail and return null. So the result should be checked against null. Added the check to cover kzalloc failure case.

---
 net/sched/sch_gred.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/sch_gred.c +3 -0
index 8599c6f31b05..5cd0859f0274 100644
@@ -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,
Signature · 1 line
2.17.1
#1 lore raw
Quoted 14 lines · Navid Emamdoost

call to kzalloc may fail and return null. So the result should be checked against null. Added the check to cover kzalloc failure case.

---
 net/sched/sch_gred.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/sch_gred.c +0 -0
index 8599c6f31b05..5cd0859f0274 100644

net/sched/sch_gred.c static int gred_change(struct Qdisc *sch, struct nlattr *opt, · line 705

Quoted 9 lines
net/sched/sch_gred.c +3 -0
@@ -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()