diff mbox series

[net,v2,1/7] octeontx2-af: Fix klockwork issue in cgx.c

Message ID 20240625173350.1181194-2-sumang@marvell.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series octeontx2-af: Fix klockwork issues in AF driver | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 12 maintainers
netdev/build_clang success Errors and warnings before: 863 this patch: 863
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 864 this patch: 864
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-06-26--00-00 (tests: 664)

Commit Message

Suman Ghosh June 25, 2024, 5:33 p.m. UTC
Variable "cgx_dev" and "lmac" was getting accessed without NULL checks
which can lead to pointer exception in some erroneous scenarios.
This patch fixes the same by adding the required NULL checks.

Fixes: 96be2e0da85e ("octeontx2-af: Support for MAC address filters in CGX")
Signed-off-by: Suman Ghosh <sumang@marvell.com>
---
 drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Jakub Kicinski June 26, 2024, 1:04 a.m. UTC | #1
On Tue, 25 Jun 2024 23:03:43 +0530 Suman Ghosh wrote:
> Variable "cgx_dev" and "lmac" was getting accessed without NULL checks
> which can lead to pointer exception in some erroneous scenarios.
> This patch fixes the same by adding the required NULL checks.

Please remove the name of the tool from the subject, too.

You can add something like:

Addresses klockwork warning ${the warning generated or such}

at the end of the commit message.

If there's a path which can lead to a crash please describe it.
If there's no real issue, it's not a fix (no Fixes and net-next).

But really, we tend to avoid addressing issues just to please
overzealous static code analysis tools. And we advise against
defensive programming, so please make sure the patches actually 
make sense. I don't think patch 6 does, picking a random one to check..
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
index 27935c54b91b..e5e266608cfc 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
@@ -465,6 +465,13 @@  u64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id)
 	u64 cfg;
 	int id;
 
+	if (!cgx_dev)
+		return 0;
+
+	lmac = lmac_pdata(lmac_id, cgx_dev);
+	if (!lmac)
+		return 0;
+
 	mac_ops = cgx_dev->mac_ops;
 
 	id = get_sequence_id_of_lmac(cgx_dev, lmac_id);