Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Zheng Yongjun and committed by
Jakub Kicinski
866b7a27 77c9387c

+4
+4
drivers/net/dsa/ocelot/felix_vsc9959.c
··· 1928 1928 case FLOW_ACTION_GATE: 1929 1929 size = struct_size(sgi, entries, a->gate.num_entries); 1930 1930 sgi = kzalloc(size, GFP_KERNEL); 1931 + if (!sgi) { 1932 + ret = -ENOMEM; 1933 + goto err; 1934 + } 1931 1935 vsc9959_psfp_parse_gate(a, sgi); 1932 1936 ret = vsc9959_psfp_sgi_table_add(ocelot, sgi); 1933 1937 if (ret) {