Skip to contentSkip to conversation

IPv6: only set err in rawv6_bind() when necessary

PATCH In review Brian Haley 2 participants 3 messages Aug 1, 2006 – Aug 2, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IPv6: only set err in rawv6_bind() when necessary

The variable 'err' is set in rawv6_bind() before the address check fails instead of after, moved inside if() statement.

net/ipv6/raw.c +1 -1
index 8a30cd8..072b28b 100644
@@ -240,10 +240,10 @@ static int rawv6_bind(struct sock *sk, s
 		 */
 		v4addr = LOOPBACK4_IPV6;
 		if (!(addr_type & IPV6_ADDR_MULTICAST))	{
-			err = -EADDRNOTAVAIL;
 			if (!ipv6_chk_addr(&addr->sin6_addr, dev, 0)) {
 				if (dev)
 					dev_put(dev);
+				err = -EADDRNOTAVAIL;
 				goto out;
 			}
 		}
maintainer
#1 lore raw

From: Brian Haley <[email protected]>
Date: Tue, 01 Aug 2006 13:06:03 -0400

Quoted 4 lines

The variable 'err' is set in rawv6_bind() before the address check fails instead of after, moved inside if() statement.

This is a common C idiom in the kernel:

	err = -EWHATEVER;
	if (error_condition)
		goto out;

	err = 0;
out:
	unlock_stuff();
	return err;

Every other path going from this location in rawv6_bind() will clear err to zero, so your patch also doesn't fix any bug.

#2 lore raw
Quoted 4 lines

Every other path going from this location in rawv6_bind() will clear err to zero, so your patch also doesn't fix any bug.

I knew it didn't fix a bug, I just hadn't noticed the C idiom you pointed-out until I knew to look for it. rawv6_bind() even does this, duh.

-Brian