Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sctp: remove unnecessary NULL check in sctp_association_init()

'&asoc->ulpq' passed to sctp_ulpq_init() as the first argument,
then sctp_qlpq_init() initializes it and eventually returns the
address of the struct member back. Therefore, in this case, the
return pointer cannot be NULL.

Moreover, it seems sctp_ulpq_init() has always been used only in
sctp_association_init(), so there's really no need to return ulpq
anymore.

Detected using the static analysis tool - Svace.
Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
Reviewed-by: Xin Long <lucien.xin@gmail.com>
Link: https://lore.kernel.org/r/20221019180735.161388-1-aleksei.kodanev@bell-sw.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Alexey Kodanev and committed by
Jakub Kicinski
6fdfdef7 94adb5e2

+3 -9
+1 -2
include/net/sctp/ulpqueue.h
··· 35 35 }; 36 36 37 37 /* Prototypes. */ 38 - struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *, 39 - struct sctp_association *); 38 + void sctp_ulpq_init(struct sctp_ulpq *ulpq, struct sctp_association *asoc); 40 39 void sctp_ulpq_flush(struct sctp_ulpq *ulpq); 41 40 void sctp_ulpq_free(struct sctp_ulpq *); 42 41
+1 -3
net/sctp/associola.c
··· 226 226 /* Create an output queue. */ 227 227 sctp_outq_init(asoc, &asoc->outqueue); 228 228 229 - if (!sctp_ulpq_init(&asoc->ulpq, asoc)) 230 - goto fail_init; 229 + sctp_ulpq_init(&asoc->ulpq, asoc); 231 230 232 231 if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams, 0, gfp)) 233 232 goto stream_free; ··· 276 277 277 278 stream_free: 278 279 sctp_stream_free(&asoc->stream); 279 - fail_init: 280 280 sock_put(asoc->base.sk); 281 281 sctp_endpoint_put(asoc->ep); 282 282 return NULL;
+1 -4
net/sctp/ulpqueue.c
··· 38 38 /* 1st Level Abstractions */ 39 39 40 40 /* Initialize a ULP queue from a block of memory. */ 41 - struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *ulpq, 42 - struct sctp_association *asoc) 41 + void sctp_ulpq_init(struct sctp_ulpq *ulpq, struct sctp_association *asoc) 43 42 { 44 43 memset(ulpq, 0, sizeof(struct sctp_ulpq)); 45 44 ··· 47 48 skb_queue_head_init(&ulpq->reasm_uo); 48 49 skb_queue_head_init(&ulpq->lobby); 49 50 ulpq->pd_mode = 0; 50 - 51 - return ulpq; 52 51 } 53 52 54 53