powerpc/powernv/sriov: perform null check on iov before dereferencing iov
Subsystems (2)
PATCH 1/1 powerpc/powernv/sriov: perform null check on iov before dereferencing iov
Currently pointer iov is being dereferenced before the null check of iov which can lead to null pointer dereference errors. Fix this by moving the iov null check before the dereferencing.
Detected using cppcheck static analysis:linux/arch/powerpc/platforms/powernv/pci-sriov.c:597:12: warning: Either the condition '!iov' is redundant or there is possible null pointer
dereference: iov. [nullPointerRedundantCheck]
num_vfs = iov->num_vfs;
^--- arch/powerpc/platforms/powernv/pci-sriov.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/platforms/powernv/pci-sriov.c +2 -3
@@ -594,11 +594,10 @@ static void pnv_pci_sriov_disable(struct pci_dev *pdev)struct pnv_iov_data *iov; iov =pnv_iov_get (pdev); - num_vfs = iov->num_vfs; - base_pe = iov->vf_pe_arr[0 ].pe_number; -if (WARN_ON (!iov))return ; + num_vfs = iov->num_vfs; + base_pe = iov->vf_pe_arr[0 ].pe_number;/* Release VF PEs */ pnv_ioda_release_vf_PE (pdev);
Signature · 1 line
2.30.2
Michael Ellerman
AppliedQuoted 4 lines · Colin Ian King
Currently pointer iov is being dereferenced before the null check of iov which can lead to null pointer dereference errors. Fix this by moving the iov null check before the dereferencing.
Quoted 8 lines
Detected using cppcheck static analysis:
linux/arch/powerpc/platforms/powernv/pci-sriov.c:597:12: warning: Either the condition '!iov' is redundant or there is possible null pointer
dereference: iov. [nullPointerRedundantCheck]num_vfs = iov->num_vfs; ^[...]
Applied to powerpc/next.
[1/1] powerpc/powernv/sriov: perform null check on iov before dereferencing iov
https://git.kernel.org/powerpc/c/f4f913c980bc6abe0ccfe88fe3909c125afe4a2d
cheers