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

net: hinic: fix null pointer dereference on pointer hwdev

Pointer hwdev is being dereferenced when declaring hwif , however, later
on hwdev is being null checked, hence we have dereference before null
check error. Fix this by assigning hwif and pdef only once hwdev has
been null checked.

Detected by CoverityScan, CID#1485581 ("Dereference before null check")

Fixes: 4a61abb100c8 ("net-next/hinic:add rx checksum offload for HiNIC")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Colin Ian King and committed by
David S. Miller
e159e592 b0c4b041

+4 -2
+4 -2
drivers/net/ethernet/huawei/hinic/hinic_port.c
··· 414 414 { 415 415 struct hinic_checksum_offload rx_csum_cfg = {0}; 416 416 struct hinic_hwdev *hwdev = nic_dev->hwdev; 417 - struct hinic_hwif *hwif = hwdev->hwif; 418 - struct pci_dev *pdev = hwif->pdev; 417 + struct hinic_hwif *hwif; 418 + struct pci_dev *pdev; 419 419 u16 out_size; 420 420 int err; 421 421 422 422 if (!hwdev) 423 423 return -EINVAL; 424 424 425 + hwif = hwdev->hwif; 426 + pdev = hwif->pdev; 425 427 rx_csum_cfg.func_id = HINIC_HWIF_FUNC_IDX(hwif); 426 428 rx_csum_cfg.rx_csum_offload = en; 427 429