diff mbox series

[net-next] net: ipv4: Fix the warning for dereference

Message ID 20210830091640.14739-1-yajun.deng@linux.dev (mailing list archive)
State Accepted
Commit 1b9fbe813016b08e08b22ddba4ddbf9cb1b04b00
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: ipv4: Fix the warning for dereference | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/header_inline success Link

Commit Message

Yajun Deng Aug. 30, 2021, 9:16 a.m. UTC
Add a if statements to avoid the warning.

Dan Carpenter report:
The patch faf482ca196a: "net: ipv4: Move ip_options_fragment() out of
loop" from Aug 23, 2021, leads to the following Smatch complaint:

    net/ipv4/ip_output.c:833 ip_do_fragment()
    warn: variable dereferenced before check 'iter.frag' (see line 828)

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: faf482ca196a ("net: ipv4: Move ip_options_fragment() out of loop")
Link: https://lore.kernel.org/netdev/20210830073802.GR7722@kadam/T/#t
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 net/ipv4/ip_output.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

patchwork-bot+netdevbpf@kernel.org Aug. 30, 2021, 11:50 a.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Mon, 30 Aug 2021 17:16:40 +0800 you wrote:
> Add a if statements to avoid the warning.
> 
> Dan Carpenter report:
> The patch faf482ca196a: "net: ipv4: Move ip_options_fragment() out of
> loop" from Aug 23, 2021, leads to the following Smatch complaint:
> 
>     net/ipv4/ip_output.c:833 ip_do_fragment()
>     warn: variable dereferenced before check 'iter.frag' (see line 828)
> 
> [...]

Here is the summary with links:
  - [net-next] net: ipv4: Fix the warning for dereference
    https://git.kernel.org/netdev/net-next/c/1b9fbe813016

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 9a8f05d5476e..9bca57ef8b83 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -825,7 +825,9 @@  int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
 
 		/* Everything is OK. Generate! */
 		ip_fraglist_init(skb, iph, hlen, &iter);
-		ip_options_fragment(iter.frag);
+
+		if (iter.frag)
+			ip_options_fragment(iter.frag);
 
 		for (;;) {
 			/* Prepare header of the next frame,