diff mbox series

[net-next,1/3] sctp: remove unnecessary NULL check in sctp_association_init()

Message ID 20221019180735.161388-1-aleksei.kodanev@bell-sw.com (mailing list archive)
State Accepted
Commit 6fdfdef7fdb57e6b9f768c9ca0718dcb5e727a85
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/3] sctp: remove unnecessary NULL check in sctp_association_init() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter warning Series does not have a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 54 this patch: 54
netdev/cc_maintainers warning 7 maintainers not CCed: kuba@kernel.org vyasevich@gmail.com nhorman@tuxdriver.com davem@davemloft.net marcelo.leitner@gmail.com edumazet@google.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 54 this patch: 54
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 42 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Alexey Kodanev Oct. 19, 2022, 6:07 p.m. UTC
'&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>
---
 include/net/sctp/ulpqueue.h | 3 +--
 net/sctp/associola.c        | 4 +---
 net/sctp/ulpqueue.c         | 5 +----
 3 files changed, 3 insertions(+), 9 deletions(-)

Comments

Xin Long Oct. 19, 2022, 9:25 p.m. UTC | #1
On Wed, Oct 19, 2022 at 2:29 PM Alexey Kodanev
<aleksei.kodanev@bell-sw.com> wrote:
>
> '&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>
> ---
>  include/net/sctp/ulpqueue.h | 3 +--
>  net/sctp/associola.c        | 4 +---
>  net/sctp/ulpqueue.c         | 5 +----
>  3 files changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/include/net/sctp/ulpqueue.h b/include/net/sctp/ulpqueue.h
> index 0eaf8650e3b2..60f6641290c3 100644
> --- a/include/net/sctp/ulpqueue.h
> +++ b/include/net/sctp/ulpqueue.h
> @@ -35,8 +35,7 @@ struct sctp_ulpq {
>  };
>
>  /* Prototypes. */
> -struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *,
> -                                struct sctp_association *);
> +void sctp_ulpq_init(struct sctp_ulpq *ulpq, struct sctp_association *asoc);
>  void sctp_ulpq_flush(struct sctp_ulpq *ulpq);
>  void sctp_ulpq_free(struct sctp_ulpq *);
>
> diff --git a/net/sctp/associola.c b/net/sctp/associola.c
> index 3460abceba44..63ba5551c13f 100644
> --- a/net/sctp/associola.c
> +++ b/net/sctp/associola.c
> @@ -226,8 +226,7 @@ static struct sctp_association *sctp_association_init(
>         /* Create an output queue.  */
>         sctp_outq_init(asoc, &asoc->outqueue);
>
> -       if (!sctp_ulpq_init(&asoc->ulpq, asoc))
> -               goto fail_init;
> +       sctp_ulpq_init(&asoc->ulpq, asoc);
>
>         if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams, 0, gfp))
>                 goto stream_free;
> @@ -277,7 +276,6 @@ static struct sctp_association *sctp_association_init(
>
>  stream_free:
>         sctp_stream_free(&asoc->stream);
> -fail_init:
>         sock_put(asoc->base.sk);
>         sctp_endpoint_put(asoc->ep);
>         return NULL;
> diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
> index 0a8510a0c5e6..24960dcb6a21 100644
> --- a/net/sctp/ulpqueue.c
> +++ b/net/sctp/ulpqueue.c
> @@ -38,8 +38,7 @@ static void sctp_ulpq_reasm_drain(struct sctp_ulpq *ulpq);
>  /* 1st Level Abstractions */
>
>  /* Initialize a ULP queue from a block of memory.  */
> -struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *ulpq,
> -                                struct sctp_association *asoc)
> +void sctp_ulpq_init(struct sctp_ulpq *ulpq, struct sctp_association *asoc)
>  {
>         memset(ulpq, 0, sizeof(struct sctp_ulpq));
>
> @@ -48,8 +47,6 @@ struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *ulpq,
>         skb_queue_head_init(&ulpq->reasm_uo);
>         skb_queue_head_init(&ulpq->lobby);
>         ulpq->pd_mode  = 0;
> -
> -       return ulpq;
>  }
>
>
> --
> 2.25.1
>
Reviewed-by: Xin Long <lucien.xin@gmail.com>
patchwork-bot+netdevbpf@kernel.org Oct. 21, 2022, 5:10 a.m. UTC | #2
Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 19 Oct 2022 21:07:33 +0300 you wrote:
> '&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.
> 
> [...]

Here is the summary with links:
  - [net-next,1/3] sctp: remove unnecessary NULL check in sctp_association_init()
    https://git.kernel.org/netdev/net-next/c/6fdfdef7fdb5
  - [net-next,2/3] sctp: remove unnecessary NULL check in sctp_ulpq_tail_event()
    https://git.kernel.org/netdev/net-next/c/b66aeddbe30c
  - [net-next,3/3] sctp: remove unnecessary NULL checks in sctp_enqueue_event()
    https://git.kernel.org/netdev/net-next/c/377eb9aab084

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/sctp/ulpqueue.h b/include/net/sctp/ulpqueue.h
index 0eaf8650e3b2..60f6641290c3 100644
--- a/include/net/sctp/ulpqueue.h
+++ b/include/net/sctp/ulpqueue.h
@@ -35,8 +35,7 @@  struct sctp_ulpq {
 };
 
 /* Prototypes. */
-struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *,
-				 struct sctp_association *);
+void sctp_ulpq_init(struct sctp_ulpq *ulpq, struct sctp_association *asoc);
 void sctp_ulpq_flush(struct sctp_ulpq *ulpq);
 void sctp_ulpq_free(struct sctp_ulpq *);
 
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 3460abceba44..63ba5551c13f 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -226,8 +226,7 @@  static struct sctp_association *sctp_association_init(
 	/* Create an output queue.  */
 	sctp_outq_init(asoc, &asoc->outqueue);
 
-	if (!sctp_ulpq_init(&asoc->ulpq, asoc))
-		goto fail_init;
+	sctp_ulpq_init(&asoc->ulpq, asoc);
 
 	if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams, 0, gfp))
 		goto stream_free;
@@ -277,7 +276,6 @@  static struct sctp_association *sctp_association_init(
 
 stream_free:
 	sctp_stream_free(&asoc->stream);
-fail_init:
 	sock_put(asoc->base.sk);
 	sctp_endpoint_put(asoc->ep);
 	return NULL;
diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
index 0a8510a0c5e6..24960dcb6a21 100644
--- a/net/sctp/ulpqueue.c
+++ b/net/sctp/ulpqueue.c
@@ -38,8 +38,7 @@  static void sctp_ulpq_reasm_drain(struct sctp_ulpq *ulpq);
 /* 1st Level Abstractions */
 
 /* Initialize a ULP queue from a block of memory.  */
-struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *ulpq,
-				 struct sctp_association *asoc)
+void sctp_ulpq_init(struct sctp_ulpq *ulpq, struct sctp_association *asoc)
 {
 	memset(ulpq, 0, sizeof(struct sctp_ulpq));
 
@@ -48,8 +47,6 @@  struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *ulpq,
 	skb_queue_head_init(&ulpq->reasm_uo);
 	skb_queue_head_init(&ulpq->lobby);
 	ulpq->pd_mode  = 0;
-
-	return ulpq;
 }