net-SCTP: Adjustments for three function implementations
Subsystems (4)
cover net-SCTP: Adjustments for three function implementations
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:30:45 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Use kmalloc_array() in sctp_init()
Delete an error message for a failed memory allocation in sctp_init() Fix a typo in a comment line in sctp_init()
Improve a size determination in sctp_inetaddr_event() Adjust one function call together with a variable assignment
net/sctp/protocol.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.13.0
PATCH 1/5 sctp: Use kmalloc_array() in sctp_init()
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:20:11 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- net/sctp/protocol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/protocol.c +2 -1
@@ -1442,6 +1442,6 @@ static __init int sctp_init(void)/* Allocate and initialize the endpoint hash table. */ sctp_ep_hashsize =64 ; - sctp_ep_hashtable -kmalloc (64 *sizeof (struct sctp_hashbucket ),GFP_KERNEL ); + sctp_ep_hashtable =kmalloc_array (64 ,sizeof (*sctp_ep_hashtable), +GFP_KERNEL );if (!sctp_ep_hashtable) {
Signature · 1 line
2.13.0
Re: [PATCH 1/5] sctp: Use kmalloc_array() in sctp_init()
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:20:11 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 7 lines
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>
Quoted 24 lines
--- net/sctp/protocol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/sctp/protocol.c +2
-1@@ -1442,6 +1442,6 @@ static __init int sctp_init(void)/* Allocate and initialize the endpoint hash table. */ sctp_ep_hashsize =64 ; - sctp_ep_hashtable > -kmalloc (64 *sizeof (struct sctp_hashbucket ),GFP_KERNEL ); + sctp_ep_hashtable =kmalloc_array (64 ,sizeof (*sctp_ep_hashtable), +GFP_KERNEL );if (!sctp_ep_hashtable) {Signature · 6 lines
2.13.0 -- 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
Re: [PATCH 1/5] sctp: Use kmalloc_array() in sctp_init()
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:20:11 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 7 lines
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>
-vlad
Quoted 17 lines
--- net/sctp/protocol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/sctp/protocol.c +2
-1@@ -1442,6 +1442,6 @@ static __init int sctp_init(void)/* Allocate and initialize the endpoint hash table. */ sctp_ep_hashsize =64 ; - sctp_ep_hashtable > -kmalloc (64 *sizeof (struct sctp_hashbucket ),GFP_KERNEL ); + sctp_ep_hashtable =kmalloc_array (64 ,sizeof (*sctp_ep_hashtable), +GFP_KERNEL );if (!sctp_ep_hashtable) {
PATCH 2/5 sctp: Delete an error message for a failed memory allocation in sctp_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:28:14 +0200
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- net/sctp/protocol.c | 1 - 1 file changed, 1 deletion(-)
net/sctp/protocol.c +0 -1
@@ -1447,5 +1447,4 @@ static __init int sctp_init(void)if (!sctp_ep_hashtable) { -pr_err ("Failed endpoint_hash alloc\n" ); status = -ENOMEM ; goto err_ehash_alloc; }
Signature · 1 line
2.13.0
Marcelo Ricardo Leitner
maintainerRe: [PATCH 2/5] sctp: Delete an error message for a failed memory allocation in sctp_init()
Quoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:28:14 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- net/sctp/protocol.c | 1 - 1 file changed, 1 deletion(-)net/sctp/protocol.c +0
-0
net/sctp/protocol.c static __init int sctp_init(void) · line 1448
Quoted 2 lines
net/sctp/protocol.c +0
-1@@ -1447,5 +1447,4 @@ static __init int sctp_init(void)if (!sctp_ep_hashtable) { -pr_err ("Failed endpoint_hash alloc\n" );
Okay but then why not also delete the one a few lines below this one:
if (!sctp_port_hashtable) {
pr_err("Failed bind hash alloc\n");
status = -ENOMEM;
goto err_bhash_alloc;
}Seems the same pattern to me.
Quoted 11 lines
net/sctp/protocol.c +0
-0status = -ENOMEM ; goto err_ehash_alloc; }Signature · 6 lines
2.13.0 -- 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
Re: [PATCH 2/5] sctp: Delete an error message for a failed memory allocation in sctp_init()
Quoted 6 lines
net/sctp/protocol.c static __init int sctp_init(void) · line 1448
Quoted 4 lines
+++
b/net/sctp/protocol.cnet/sctp/protocol.c +0
-1@@ -1447,5 +1447,4 @@ static __init int sctp_init(void)if (!sctp_ep_hashtable) { -pr_err ("Failed endpoint_hash alloc\n" );Okay but then why not also delete the one a few lines below this one:
Quoted 10 lines
if (!sctp_port_hashtable) { pr_err("Failed bind hash alloc\n"); status = -ENOMEM; goto err_bhash_alloc; }Seems the same pattern to me.
Quoted 3 lines
net/sctp/protocol.c +0
-0status = -ENOMEM ; goto err_ehash_alloc; }
How do you think about to remove the other error message in another update step if a consensus would be achieved in such a direction for this software module?
Regards,
Markus
Marcelo Ricardo Leitner
maintainerRe: [PATCH 2/5] sctp: Delete an error message for a failed memory allocation in sctp_init()
Quoted 13 lines · SF Markus Elfring
Quoted 13 lines
net/sctp/protocol.c static __init int sctp_init(void) · line 1448
Quoted 4 lines
+++
b/net/sctp/protocol.cnet/sctp/protocol.c +0
-1@@ -1447,5 +1447,4 @@ static __init int sctp_init(void)if (!sctp_ep_hashtable) { -pr_err ("Failed endpoint_hash alloc\n" );Okay but then why not also delete the one a few lines below this one:
if (!sctp_port_hashtable) { pr_err("Failed bind hash alloc\n"); status = -ENOMEM; goto err_bhash_alloc; }Seems the same pattern to me.
Quoted 7 lines
Quoted 3 lines
net/sctp/protocol.c static __init int sctp_init(void) · line 1450
Quoted 3 lines
net/sctp/protocol.c +0
-0status = -ENOMEM ; goto err_ehash_alloc; }How do you think about to remove the other error message in another update step if a consensus would be achieved in such a direction for this software module?
Fine by me.
Regards,
Marcelo
Re: [PATCH 2/5] sctp: Delete an error message for a failed memory allocation in sctp_init()
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:28:14 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Quoted 22 lines
--- net/sctp/protocol.c | 1 - 1 file changed, 1 deletion(-)net/sctp/protocol.c +0
-1@@ -1447,5 +1447,4 @@ static __init int sctp_init(void)if (!sctp_ep_hashtable) { -pr_err ("Failed endpoint_hash alloc\n" ); status = -ENOMEM ; goto err_ehash_alloc; }Signature · 6 lines
2.13.0 -- 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
Re: [PATCH 2/5] sctp: Delete an error message for a failed memory allocation in sctp_init()
In reply to SF Markus ElfringQuoted 19 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:28:14 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- net/sctp/protocol.c | 1 - 1 file changed, 1 deletion(-)net/sctp/protocol.c +0
-0
net/sctp/protocol.c static __init int sctp_init(void) · line 1450
Quoted 5 lines
net/sctp/protocol.c +0
-1@@ -1447,5 +1447,4 @@ static __init int sctp_init(void)if (!sctp_ep_hashtable) { -pr_err ("Failed endpoint_hash alloc\n" ); status = -ENOMEM ; goto err_ehash_alloc; }
At the time this was written, it was patterned after TCP. Since then TCP changed significantly. We can surely clean-up the pr_err() here and possibly update the code as well later.
-vlad
PATCH 3/5 sctp: Fix a typo in a comment line in sctp_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:43:44 +0200
Add a missing character in this description.
--- net/sctp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/protocol.c +1 -1
@@ -1454,7 +1454,7 @@ static __init int sctp_init(void) }/* Allocate and initialize the SCTP port hash table. -* Note that order is initalized to start at the max sized +* Note that order is initialized to start at the max sized * table we want to support. If we can't get that many pages * reduce the order and try again */
Signature · 1 line
2.13.0
Re: [PATCH 3/5] sctp: Fix a typo in a comment line in sctp_init()
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:43:44 +0200Add a missing character in this description.
Signed-off-by Markus Elfring <[email protected]>
Quoted 25 lines
--- net/sctp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sctp/protocol.c +1
-1@@ -1454,7 +1454,7 @@ static __init int sctp_init(void) }/* Allocate and initialize the SCTP port hash table. -* Note that order is initalized to start at the max sized +* Note that order is initialized to start at the max sized * table we want to support. If we can't get that many pages * reduce the order and try again */ Signature · 6 lines
2.13.0 -- 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
Re: [PATCH 3/5] sctp: Fix a typo in a comment line in sctp_init()
In reply to SF Markus ElfringQuoted 16 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 17:43:44 +0200Add a missing character in this description.
Signed-off-by Markus Elfring <[email protected]>--- net/sctp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sctp/protocol.c +0
-0
net/sctp/protocol.c static __init int sctp_init(void) · line 1460
Quoted 8 lines
net/sctp/protocol.c +1
-1@@ -1454,7 +1454,7 @@ static __init int sctp_init(void) }/* Allocate and initialize the SCTP port hash table. -* Note that order is initalized to start at the max sized +* Note that order is initialized to start at the max sized * table we want to support. If we can't get that many pages * reduce the order and try again */
-vlad
PATCH 4/5 sctp: Improve a size determination in sctp_inetaddr_event()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:08:24 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- net/sctp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/protocol.c +1 -1
@@ -784,7 +784,7 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,switch (ev) {case NETDEV_UP : - addr =kmalloc (sizeof (struct sctp_sockaddr_entry ),GFP_ATOMIC ); + addr =kmalloc (sizeof (*addr),GFP_ATOMIC );if (addr) { addr->a.v4.sin_family =AF_INET ; addr->a.v4.sin_port =0 ;
Signature · 1 line
2.13.0
Re: [PATCH 4/5] sctp: Improve a size determination in sctp_inetaddr_event()
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:08:24 +0200Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>
Quoted 25 lines
--- net/sctp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sctp/protocol.c +1
-1@@ -784,7 +784,7 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,switch (ev) {case NETDEV_UP : - addr =kmalloc (sizeof (struct sctp_sockaddr_entry ),GFP_ATOMIC ); + addr =kmalloc (sizeof (*addr),GFP_ATOMIC );if (addr) { addr->a.v4.sin_family =AF_INET ; addr->a.v4.sin_port =0 ;Signature · 6 lines
2.13.0 -- 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
Re: [PATCH 4/5] sctp: Improve a size determination in sctp_inetaddr_event()
In reply to SF Markus ElfringQuoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:08:24 +0200Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- net/sctp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sctp/protocol.c +0
-0
net/sctp/protocol.c static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev, · line 790
Quoted 8 lines
net/sctp/protocol.c +1
-1@@ -784,7 +784,7 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,switch (ev) {case NETDEV_UP : - addr =kmalloc (sizeof (struct sctp_sockaddr_entry ),GFP_ATOMIC ); + addr =kmalloc (sizeof (*addr),GFP_ATOMIC );if (addr) { addr->a.v4.sin_family =AF_INET ; addr->a.v4.sin_port =0 ;
-vlad
PATCH 5/5 sctp: Adjust one function call together with a variable assignment
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:15:12 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code place.
--- net/sctp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sctp/protocol.c +2 -1
@@ -141,7 +141,8 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist,struct sctp_sockaddr_entry *addr;rcu_read_lock (); -if ((in_dev =__in_dev_get_rcu (dev)) =NULL ) { + in_dev =__in_dev_get_rcu (dev); +if (!in_dev) {rcu_read_unlock ();return ; }
Signature · 1 line
2.13.0
Re: [PATCH 5/5] sctp: Adjust one function call together with a variable assignment
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:15:12 +0200The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code place.
Signed-off-by Markus Elfring <[email protected]>
Quoted 26 lines
--- net/sctp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/sctp/protocol.c +2
-1@@ -141,7 +141,8 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist,struct sctp_sockaddr_entry *addr;rcu_read_lock (); -if ((in_dev =__in_dev_get_rcu (dev)) =NULL ) { + in_dev =__in_dev_get_rcu (dev); +if (!in_dev) {rcu_read_unlock ();return ; }Signature · 6 lines
2.13.0 -- 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
Re: [PATCH 5/5] sctp: Adjust one function call together with a variable assignment
In reply to SF Markus ElfringQuoted 20 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:15:12 +0200The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code place.
Signed-off-by Markus Elfring <[email protected]>--- net/sctp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/sctp/protocol.c +0
-0
net/sctp/protocol.c static void sctp_v4_copy_addrlist(struct list_head *addrlist, · line 148
Quoted 9 lines
net/sctp/protocol.c +2
-1@@ -141,7 +141,8 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist,struct sctp_sockaddr_entry *addr;rcu_read_lock (); -if ((in_dev =__in_dev_get_rcu (dev)) =NULL ) { + in_dev =__in_dev_get_rcu (dev); +if (!in_dev) {rcu_read_unlock ();return ; }
-vlad
Xin Long
maintainerQuoted 13 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 18:30:45 +0200A few update suggestions were taken into account
from static source code analysis.Markus Elfring (5):
Usekmalloc_array()insctp_init()
Delete an error message for a failed memory allocation insctp_init()Fix a typo in a comment line insctp_init()
Improve a size determination insctp_inetaddr_event()Adjust one function call together with a variable assignment
Quoted 2 lines
net/sctp/protocol.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
I guess these patches are for net-next.git
Series Reviewed-by: Xin Long <[email protected]>
Quoted 8 lines
--
2.13.0--
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