[PATCH] sctp: make sctp_transport_init() void

Huiwen He posted 1 patch 3 months, 1 week ago
There is a newer version of this series
net/sctp/transport.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
[PATCH] sctp: make sctp_transport_init() void
Posted by Huiwen He 3 months, 1 week ago
sctp_transport_init() is static and never returns NULL. It is only
called by sctp_transport_new(), so change it to void and remove the
redundant return value check.

Signed-off-by: Huiwen He <hehuiwen@kylinos.cn>
---
 net/sctp/transport.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index 4d258a6e8033..97da92390aa7 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -37,10 +37,10 @@
 /* 1st Level Abstractions.  */
 
 /* Initialize a new transport from provided memory.  */
-static struct sctp_transport *sctp_transport_init(struct net *net,
-						  struct sctp_transport *peer,
-						  const union sctp_addr *addr,
-						  gfp_t gfp)
+static void sctp_transport_init(struct net *net,
+				struct sctp_transport *peer,
+				const union sctp_addr *addr,
+				gfp_t gfp)
 {
 	/* Copy in the address.  */
 	peer->af_specific = sctp_get_af_specific(addr->sa.sa_family);
@@ -83,8 +83,6 @@ static struct sctp_transport *sctp_transport_init(struct net *net,
 	get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce));
 
 	refcount_set(&peer->refcnt, 1);
-
-	return peer;
 }
 
 /* Allocate and initialize a new transport.  */
@@ -98,16 +96,12 @@ struct sctp_transport *sctp_transport_new(struct net *net,
 	if (!transport)
 		goto fail;
 
-	if (!sctp_transport_init(net, transport, addr, gfp))
-		goto fail_init;
+	sctp_transport_init(net, transport, addr, gfp);
 
 	SCTP_DBG_OBJCNT_INC(transport);
 
 	return transport;
 
-fail_init:
-	kfree(transport);
-
 fail:
 	return NULL;
 }
-- 
2.25.1
Re: [PATCH] sctp: make sctp_transport_init() void
Posted by Xin Long 3 months, 1 week ago
On Sat, Nov 1, 2025 at 12:37 PM Huiwen He <hehuiwen@kylinos.cn> wrote:
>
> sctp_transport_init() is static and never returns NULL. It is only
> called by sctp_transport_new(), so change it to void and remove the
> redundant return value check.
>
> Signed-off-by: Huiwen He <hehuiwen@kylinos.cn>
> ---
>  net/sctp/transport.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/net/sctp/transport.c b/net/sctp/transport.c
> index 4d258a6e8033..97da92390aa7 100644
> --- a/net/sctp/transport.c
> +++ b/net/sctp/transport.c
> @@ -37,10 +37,10 @@
>  /* 1st Level Abstractions.  */
>
>  /* Initialize a new transport from provided memory.  */
> -static struct sctp_transport *sctp_transport_init(struct net *net,
> -                                                 struct sctp_transport *peer,
> -                                                 const union sctp_addr *addr,
> -                                                 gfp_t gfp)
> +static void sctp_transport_init(struct net *net,
> +                               struct sctp_transport *peer,
> +                               const union sctp_addr *addr,
> +                               gfp_t gfp)
>  {
>         /* Copy in the address.  */
>         peer->af_specific = sctp_get_af_specific(addr->sa.sa_family);
> @@ -83,8 +83,6 @@ static struct sctp_transport *sctp_transport_init(struct net *net,
>         get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce));
>
>         refcount_set(&peer->refcnt, 1);
> -
> -       return peer;
>  }
>
>  /* Allocate and initialize a new transport.  */
> @@ -98,16 +96,12 @@ struct sctp_transport *sctp_transport_new(struct net *net,
>         if (!transport)
>                 goto fail;
I think you can return NULL; here, and delete the 'fail:' path below now.

Thanks.
>
> -       if (!sctp_transport_init(net, transport, addr, gfp))
> -               goto fail_init;
> +       sctp_transport_init(net, transport, addr, gfp);
>
>         SCTP_DBG_OBJCNT_INC(transport);
>
>         return transport;
>
> -fail_init:
> -       kfree(transport);
> -
>  fail:
>         return NULL;
>  }
> --
> 2.25.1
>