Skip to contentSkip to conversation

sctp: cleanup: remove unneeded null check

PATCH In review Dan Carpenter 3 participants 6 messages Apr 23, 2010 – Apr 27, 2010

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

PATCH 1/1 sctp: cleanup: remove unneeded null check

"chunk" can never be null here. We dereferenced it earlier in the function and also at the start of the function we passed it to sctp_pack_cookie() which dereferences it.

This code has been around since the dawn of git history so if "chunk" were ever null someone would have complained about it.

net/sctp/sm_make_chunk.c +1 -2
index 17cb400..52352fc 100644
@@ -470,8 +470,7 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
 	 *
 	 * [INIT ACK back to where the INIT came from.]
 	 */
-	if (chunk)
-		retval->transport = chunk->transport;
+	retval->transport = chunk->transport;
 
 nomem_chunk:
 	kfree(cookie);
#1 lore raw
Quoted 14 lines · Dan Carpenter

"chunk" can never be null here. We dereferenced it earlier in the function and also at the start of the function we passed it to sctp_pack_cookie() which dereferences it.

This code has been around since the dawn of git history so if "chunk" were ever null someone would have complained about it.

net/sctp/sm_make_chunk.c +0 -0
index 17cb400..52352fc 100644

net/sctp/sm_make_chunk.c struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc, · line 474

Quoted 7 lines
net/sctp/sm_make_chunk.c +1 -2
@@ -470,8 +470,7 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
 	 *
 	 * [INIT ACK back to where the INIT came from.]
 	 */
-	if (chunk)
-		retval->transport = chunk->transport;
+	retval->transport = chunk->transport;
 

Actually, this code can be completely removed as we already make this assignment earlier:

        /* Per the advice in RFC 2960 6.4, send this reply to
         * the source of the INIT packet.
         */
        retval->transport = chunk->transport;
        retval->subh.init_hdr                 sctp_addto_chunk(retval, sizeof(initack), &initack);

-vlad

Quoted 7 lines
net/sctp/sm_make_chunk.c +0 -1
 nomem_chunk:
 	kfree(cookie);
--

To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

PATCH v2 1/1 sctp: cleanup: remove duplicate assignment

This assignment isn't needed because we did it earlier already.

Also another reason to delete the assignment is because it triggers a Smatch warning about checking for NULL pointers after a dereference.

---
Thanks Vlad. I came so close to seeing that myself if only I had openned my eyes a tiny bit more. :P

net/sctp/sm_make_chunk.c +9 -14
index 17cb400..33aed1c 100644
@@ -419,10 +419,17 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
 	if (!retval)
 		goto nomem_chunk;
 
-	/* Per the advice in RFC 2960 6.4, send this reply to
-	 * the source of the INIT packet.
+	/* RFC 2960 6.4 Multi-homed SCTP Endpoints
+	 *
+	 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
+	 * HEARTBEAT ACK, * etc.) to the same destination transport
+	 * address from which it received the DATA or control chunk
+	 * to which it is replying.
+	 *
+	 * [INIT ACK back to where the INIT came from.]
 	 */
 	retval->transport = chunk->transport;
+
 	retval->subh.init_hdr  		sctp_addto_chunk(retval, sizeof(initack), &initack);
 	retval->param_hdr.v = sctp_addto_chunk(retval, addrs_len, addrs.v);
@@ -461,18 +468,6 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
 	/* We need to remove the const qualifier at this point.  */
 	retval->asoc = (struct sctp_association *) asoc;
 
-	/* RFC 2960 6.4 Multi-homed SCTP Endpoints
-	 *
-	 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
-	 * HEARTBEAT ACK, * etc.) to the same destination transport
-	 * address from which it received the DATA or control chunk
-	 * to which it is replying.
-	 *
-	 * [INIT ACK back to where the INIT came from.]
-	 */
-	if (chunk)
-		retval->transport = chunk->transport;
-
 nomem_chunk:
 	kfree(cookie);
 nomem_cookie:
#3 lore raw

Re: [patch v2] sctp: cleanup: remove duplicate assignment

Quoted 7 lines · Dan Carpenter

This assignment isn't needed because we did it earlier already.

Also another reason to delete the assignment is because it triggers a Smatch warning about checking for NULL pointers after a dereference.

Thanks. I'll take this one.

-vlad

Quoted 51 lines

---
Thanks Vlad. I came so close to seeing that myself if only I had openned my eyes a tiny bit more. :P

net/sctp/sm_make_chunk.c +9 -15
index 17cb400..33aed1c 100644
@@ -419,10 +419,17 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
 	if (!retval)
 		goto nomem_chunk;
 
-	/* Per the advice in RFC 2960 6.4, send this reply to
-	 * the source of the INIT packet.
+	/* RFC 2960 6.4 Multi-homed SCTP Endpoints
+	 *
+	 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
+	 * HEARTBEAT ACK, * etc.) to the same destination transport
+	 * address from which it received the DATA or control chunk
+	 * to which it is replying.
+	 *
+	 * [INIT ACK back to where the INIT came from.]
 	 */
 	retval->transport = chunk->transport;
+
 	retval->subh.init_hdr >  		sctp_addto_chunk(retval, sizeof(initack), &initack);
 	retval->param_hdr.v = sctp_addto_chunk(retval, addrs_len, addrs.v);
@@ -461,18 +468,6 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
 	/* We need to remove the const qualifier at this point.  */
 	retval->asoc = (struct sctp_association *) asoc;
 
-	/* RFC 2960 6.4 Multi-homed SCTP Endpoints
-	 *
-	 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
-	 * HEARTBEAT ACK, * etc.) to the same destination transport
-	 * address from which it received the DATA or control chunk
-	 * to which it is replying.
-	 *
-	 * [INIT ACK back to where the INIT came from.]
-	 */
-	if (chunk)
-		retval->transport = chunk->transport;
-
 nomem_chunk:
 	kfree(cookie);
 nomem_cookie:
--

To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw

Re: [patch v2] sctp: cleanup: remove duplicate assignment

From: Vlad Yasevich <[email protected]>
Date: Tue, 27 Apr 2010 10:32:34 -0400

Quoted 5 lines
Quoted 2 lines · Dan Carpenter

This assignment isn't needed because we did it earlier already.

Quoted 7 lines
Quoted 5 lines

Also another reason to delete the assignment is because it triggers a Smatch warning about checking for NULL pointers after a dereference.

Thanks. I'll take this one.

And when will I get this from you? :-)

#5 lore raw

Re: [patch v2] sctp: cleanup: remove duplicate assignment

Quoted 7 lines · David Miller

From: Vlad Yasevich <[email protected]>
Date: Tue, 27 Apr 2010 10:32:34 -0400

Quoted 4 lines
Quoted 2 lines · Dan Carpenter

This assignment isn't needed because we did it earlier already.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Also another reason to delete the assignment is because it triggers a Smatch warning about checking for NULL pointers after a dereference.

Thanks. I'll take this one.

And when will I get this from you? :-)

By the end of the week. I am trying to get all the testing finished. :)

-vlad

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html