summaryrefslogtreecommitdiffstats
path: root/drivers/net/dsa/ocelot
diff options
context:
space:
mode:
authorZheng Yongjun <zhengyongjun3@huawei.com>2022-03-29 11:08:00 +0200
committerJakub Kicinski <kuba@kernel.org>2022-03-30 21:07:38 +0200
commit866b7a278cdb51eb158cd8513bc7438fc857804a (patch)
tree72908ac61131087d8ca82603ab1a4de659863ea9 /drivers/net/dsa/ocelot
parentMerge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf (diff)
downloadlinux-866b7a278cdb51eb158cd8513bc7438fc857804a.tar.xz
linux-866b7a278cdb51eb158cd8513bc7438fc857804a.zip
net: dsa: felix: fix possible NULL pointer dereference
As the possible failure of the allocation, kzalloc() may return NULL pointer. Therefore, it should be better to check the 'sgi' in order to prevent the dereference of NULL pointer. Fixes: 23ae3a7877718 ("net: dsa: felix: add stream gate settings for psfp"). Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Link: https://lore.kernel.org/r/20220329090800.130106-1-zhengyongjun3@huawei.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'drivers/net/dsa/ocelot')
-rw-r--r--drivers/net/dsa/ocelot/felix_vsc9959.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 62d52e0874e9..8d382b27e625 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -1928,6 +1928,10 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, int port,
case FLOW_ACTION_GATE:
size = struct_size(sgi, entries, a->gate.num_entries);
sgi = kzalloc(size, GFP_KERNEL);
+ if (!sgi) {
+ ret = -ENOMEM;
+ goto err;
+ }
vsc9959_psfp_parse_gate(a, sgi);
ret = vsc9959_psfp_sgi_table_add(ocelot, sgi);
if (ret) {