net: sctp: remove sctp_ep_common struct member 'malloced'
Subsystems (3)
PATCH 1/2 net: sctp: remove sctp_ep_common struct member 'malloced'
There is actually no need to keep this member in the structure, because after init it's always 1 anyway, thus always kfree called. This seems to be an ancient leftover from the very initial implementation from 2.5 times. Only in case the initialization of an association fails, we leave base.malloced as 0, but we nevertheless kfree it in the error path in sctp_association_new().
---
Likely, there are also other such candidates in SCTP. Will have a look for some follow-ups.
include/net/sctp/structs.h | 2 -- net/sctp/associola.c | 8 ++------ net/sctp/endpointola.c | 10 +++------- 3 files changed, 5 insertions(+), 15 deletions(-)
include/net/sctp/structs.h +0 -2
@@ -1174,11 +1174,9 @@ struct sctp_ep_common {/* Some fields to help us manage this object. * refcnt - Reference count access to this object. * dead - Do not attempt to use this object. -* malloced - Do we need to kfree this object? */ atomic_t refcnt;char dead; -char malloced;/* What socket does this endpoint belong to? */ struct sock *sk;
net/sctp/associola.c +2 -6
@@ -105,7 +105,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a/* Initialize the object handling fields. */ atomic_set (&asoc->base.refcnt,1 ); asoc->base.dead =0 ; - asoc->base.malloced =0 ;/* Initialize the bind addr area. */ sctp_bind_addr_init (&asoc->base.bind_addr, ep->base.bind_addr.port);
@@ -371,7 +370,6 @@ struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep,if (!sctp_association_init (asoc, ep, sk, scope, gfp)) goto fail_init; - asoc->base.malloced =1 ;SCTP_DBG_OBJCNT_INC (assoc);SCTP_DEBUG_PRINTK ("Created asoc %p\n" , asoc);
@@ -484,10 +482,8 @@ static void sctp_association_destroy(struct sctp_association *asoc)WARN_ON (atomic_read (&asoc->rmem_alloc)); -if (asoc->base.malloced) { -kfree (asoc); -SCTP_DBG_OBJCNT_DEC (assoc); - } +kfree (asoc); +SCTP_DBG_OBJCNT_DEC (assoc); }/* Change the primary destination address for the peer. */
net/sctp/endpointola.c +3 -7
@@ -122,7 +122,6 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,/* Initialize the basic object fields. */ atomic_set (&ep->base.refcnt,1 ); ep->base.dead =0 ; - ep->base.malloced =1 ;/* Create an input queue. */ sctp_inq_init (&ep->base.inqueue);
@@ -198,7 +197,7 @@ struct sctp_endpoint *sctp_endpoint_new(struct sock *sk, gfp_t gfp) goto fail;if (!sctp_endpoint_init (ep, sk, gfp)) goto fail_init; - ep->base.malloced =1 ; +SCTP_DBG_OBJCNT_INC (ep);return ep;
@@ -279,11 +278,8 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)if (ep->base.sk)sock_put (ep->base.sk); -/* Finally, free up our memory. */ -if (ep->base.malloced) { -kfree (ep); -SCTP_DBG_OBJCNT_DEC (ep); - } +kfree (ep); +SCTP_DBG_OBJCNT_DEC (ep); }/* Hold a reference to an endpoint. */
Signature · 1 line
1.7.11.7
PATCH 2/2 net: sctp: minor: make sctp_ep_common's member 'dead' a bool
Since dead only holds two states (0,1), make it a bool instead of a 'char', which is more appropriate for its purpose.
--- include/net/sctp/structs.h | 2 +- net/sctp/associola.c | 4 ++-- net/sctp/endpointola.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
include/net/sctp/structs.h +1 -1
@@ -1176,7 +1176,7 @@ struct sctp_ep_common {* dead - Do not attempt to use this object. */ atomic_t refcnt; -char dead; +bool dead;/* What socket does this endpoint belong to? */ struct sock *sk;
net/sctp/associola.c +2 -2
@@ -104,7 +104,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a/* Initialize the object handling fields. */ atomic_set (&asoc->base.refcnt,1 ); - asoc->base.dead =0 ; + asoc->base.dead = false;/* Initialize the bind addr area. */ sctp_bind_addr_init (&asoc->base.bind_addr, ep->base.bind_addr.port);
@@ -407,7 +407,7 @@ void sctp_association_free(struct sctp_association *asoc)/* Mark as dead, so other users can know this structure is * going away. */ - asoc->base.dead =1 ; + asoc->base.dead = true;/* Dispose of any data lying around in the outqueue. */ sctp_outq_free (&asoc->outqueue);
net/sctp/endpointola.c +2 -2
@@ -121,7 +121,7 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,/* Initialize the basic object fields. */ atomic_set (&ep->base.refcnt,1 ); - ep->base.dead =0 ; + ep->base.dead = false;/* Create an input queue. */ sctp_inq_init (&ep->base.inqueue);
@@ -233,7 +233,7 @@ void sctp_endpoint_add_asoc(struct sctp_endpoint *ep,*/ void sctp_endpoint_free (struct sctp_endpoint *ep) { - ep->base.dead =1 ; + ep->base.dead = true; ep->base.sk->sk_state =SCTP_SS_CLOSED ;
Signature · 1 line
1.7.11.7
Re: [PATCH net-next 2/2] net: sctp: minor: make sctp_ep_common's member 'dead' a bool
Quoted 4 lines · Daniel Borkmann
Since dead only holds two states (0,1), make it a bool instead of a 'char', which is more appropriate for its purpose.
Signed-off-by Daniel Borkmann <[email protected]>
Quoted 64 lines
--- include/net/sctp/structs.h | 2 +- net/sctp/associola.c | 4 ++-- net/sctp/endpointola.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)include/net/sctp/structs.h +1
-1@@ -1176,7 +1176,7 @@ struct sctp_ep_common {* dead - Do not attempt to use this object. */ atomic_t refcnt; -char dead; +bool dead;/* What socket does this endpoint belong to? */ struct sock *sk;net/sctp/associola.c +2
-2@@ -104,7 +104,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a/* Initialize the object handling fields. */ atomic_set (&asoc->base.refcnt,1 ); - asoc->base.dead =0 ; + asoc->base.dead = false;/* Initialize the bind addr area. */ sctp_bind_addr_init (&asoc->base.bind_addr, ep->base.bind_addr.port);@@ -407,7 +407,7 @@ void sctp_association_free(struct sctp_association *asoc)/* Mark as dead, so other users can know this structure is * going away. */ - asoc->base.dead =1 ; + asoc->base.dead = true;/* Dispose of any data lying around in the outqueue. */ sctp_outq_free (&asoc->outqueue);net/sctp/endpointola.c +2
-2@@ -121,7 +121,7 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,/* Initialize the basic object fields. */ atomic_set (&ep->base.refcnt,1 ); - ep->base.dead =0 ; + ep->base.dead = false;/* Create an input queue. */ sctp_inq_init (&ep->base.inqueue);@@ -233,7 +233,7 @@ void sctp_endpoint_add_asoc(struct sctp_endpoint *ep,*/ void sctp_endpoint_free (struct sctp_endpoint *ep) { - ep->base.dead =1 ; + ep->base.dead = true; ep->base.sk->sk_state =SCTP_SS_CLOSED ;
Re: [PATCH net-next 2/2] net: sctp: minor: make sctp_ep_common's member 'dead' a bool
In reply to Daniel BorkmannFrom: Daniel Borkmann <[email protected]>
Date: Mon, 15 Apr 2013 15:27:18 +0200
Quoted 4 lines
Since dead only holds two states (0,1), make it a bool instead of a 'char', which is more appropriate for its purpose.
Signed-off-by Daniel Borkmann <[email protected]>
Applied.
Quoted 8 lines · Daniel Borkmann
There is actually no need to keep this member in the structure, because after init it's always 1 anyway, thus always kfree called. This seems to be an ancient leftover from the very initial implementation from 2.5 times. Only in case the initialization of an association fails, we leave base.malloced as 0, but we nevertheless kfree it in the error path in
sctp_association_new().Signed-off-by Daniel Borkmann <[email protected]>
-vlad
Quoted 94 lines
---
Likely, there are also other such candidates in SCTP. Will have a look for some follow-ups.include/net/sctp/structs.h | 2 -- net/sctp/associola.c | 8 ++------ net/sctp/endpointola.c | 10 +++------- 3 files changed, 5 insertions(+), 15 deletions(-)include/net/sctp/structs.h +0
-2@@ -1174,11 +1174,9 @@ struct sctp_ep_common {/* Some fields to help us manage this object. * refcnt - Reference count access to this object. * dead - Do not attempt to use this object. -* malloced - Do we need to kfree this object? */ atomic_t refcnt;char dead; -char malloced;/* What socket does this endpoint belong to? */ struct sock *sk;net/sctp/associola.c +2
-6@@ -105,7 +105,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a/* Initialize the object handling fields. */ atomic_set (&asoc->base.refcnt,1 ); asoc->base.dead =0 ; - asoc->base.malloced =0 ;/* Initialize the bind addr area. */ sctp_bind_addr_init (&asoc->base.bind_addr, ep->base.bind_addr.port);@@ -371,7 +370,6 @@ struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep,if (!sctp_association_init (asoc, ep, sk, scope, gfp)) goto fail_init; - asoc->base.malloced =1 ;SCTP_DBG_OBJCNT_INC (assoc);SCTP_DEBUG_PRINTK ("Created asoc %p\n" , asoc);@@ -484,10 +482,8 @@ static void sctp_association_destroy(struct sctp_association *asoc)WARN_ON (atomic_read (&asoc->rmem_alloc)); -if (asoc->base.malloced) { -kfree (asoc); -SCTP_DBG_OBJCNT_DEC (assoc); - } +kfree (asoc); +SCTP_DBG_OBJCNT_DEC (assoc); }/* Change the primary destination address for the peer. */ net/sctp/endpointola.c +3
-7@@ -122,7 +122,6 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,/* Initialize the basic object fields. */ atomic_set (&ep->base.refcnt,1 ); ep->base.dead =0 ; - ep->base.malloced =1 ;/* Create an input queue. */ sctp_inq_init (&ep->base.inqueue);@@ -198,7 +197,7 @@ struct sctp_endpoint *sctp_endpoint_new(struct sock *sk, gfp_t gfp) goto fail;if (!sctp_endpoint_init (ep, sk, gfp)) goto fail_init; - ep->base.malloced =1 ; +SCTP_DBG_OBJCNT_INC (ep);return ep;@@ -279,11 +278,8 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)if (ep->base.sk)sock_put (ep->base.sk); -/* Finally, free up our memory. */ -if (ep->base.malloced) { -kfree (ep); -SCTP_DBG_OBJCNT_DEC (ep); - } +kfree (ep); +SCTP_DBG_OBJCNT_DEC (ep); }/* Hold a reference to an endpoint. */
From: Daniel Borkmann <[email protected]>
Date: Mon, 15 Apr 2013 15:27:17 +0200
Quoted 8 lines
There is actually no need to keep this member in the structure, because after init it's always 1 anyway, thus always kfree called. This seems to be an ancient leftover from the very initial implementation from 2.5 times. Only in case the initialization of an association fails, we leave base.malloced as 0, but we nevertheless kfree it in the error path in
sctp_association_new().Signed-off-by Daniel Borkmann <[email protected]>
Applied.