Skip to contentSkip to conversation

net-SCTP: Adjustments for three function implementations

PATCH In review SF Markus Elfring 4 participants 20 messages May 22, 2017 – May 23, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 989a900383b5..2b1a6215bd2f 100644
@@ -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
maintainer Acked-by on v1 1/5
#2 lore raw

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.

Quoted 24 lines
---
 net/sctp/protocol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/protocol.c +2 -1
index 989a900383b5..2b1a6215bd2f 100644
@@ -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
Acked-by on v1 1/5
#3 lore raw

Re: [PATCH 1/5] sctp: Use kmalloc_array() in sctp_init()

In reply to SF Markus Elfring
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.

-vlad

Quoted 17 lines
---
 net/sctp/protocol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/protocol.c +2 -1
index 989a900383b5..2b1a6215bd2f 100644
@@ -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) {
#4 lore raw

PATCH 2/5 sctp: Delete an error message for a failed memory allocation in sctp_init()

In reply to SF Markus Elfring

From: 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
index 2b1a6215bd2f..5e7c8a344770 100644
@@ -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
#5 lore raw

Re: [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 +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 -0
index 2b1a6215bd2f..5e7c8a344770 100644

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 -0
 		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
#6 lore raw

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.c

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:

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 -0
 		status = -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

#7 lore raw

Re: [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.c

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 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 -0
 		status = -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

maintainer Acked-by on v1 2/5
#8 lore raw

Re: [PATCH 2/5] sctp: Delete an error message for a failed memory allocation in sctp_init()

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: 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.

Quoted 22 lines
---
 net/sctp/protocol.c | 1 -
 1 file changed, 1 deletion(-)
net/sctp/protocol.c +0 -1
index 2b1a6215bd2f..5e7c8a344770 100644
@@ -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
Acked-by on v1 2/5
#9 lore raw

Re: [PATCH 2/5] sctp: Delete an error message for a failed memory allocation in sctp_init()

In reply to SF Markus Elfring
Quoted 19 lines · SF Markus Elfring

From: 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 -0
index 2b1a6215bd2f..5e7c8a344770 100644

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

#10 lore raw

PATCH 3/5 sctp: Fix a typo in a comment line in sctp_init()

In reply to SF Markus Elfring

From: 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
index 5e7c8a344770..64756c42cec9 100644
@@ -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
maintainer Acked-by on v1 3/5
#11 lore raw

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 +0200

Add a missing character in this description.

Quoted 25 lines
---
 net/sctp/protocol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/protocol.c +1 -1
index 5e7c8a344770..64756c42cec9 100644
@@ -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
Acked-by on v1 3/5
#12 lore raw

Re: [PATCH 3/5] sctp: Fix a typo in a comment line in sctp_init()

In reply to SF Markus Elfring
Quoted 16 lines · SF Markus Elfring

From: 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 +0 -0
index 5e7c8a344770..64756c42cec9 100644

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

#13 lore raw

PATCH 4/5 sctp: Improve a size determination in sctp_inetaddr_event()

In reply to SF Markus Elfring

From: 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
index 64756c42cec9..057479b7bd72 100644
@@ -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
maintainer Acked-by on v1 4/5
#14 lore raw

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 +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.

Quoted 25 lines
---
 net/sctp/protocol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/protocol.c +1 -1
index 64756c42cec9..057479b7bd72 100644
@@ -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
Acked-by on v1 4/5
#15 lore raw

Re: [PATCH 4/5] sctp: Improve a size determination in sctp_inetaddr_event()

In reply to SF Markus Elfring
Quoted 18 lines · SF Markus Elfring

From: 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 +0 -0
index 64756c42cec9..057479b7bd72 100644

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

#16 lore raw

PATCH 5/5 sctp: Adjust one function call together with a variable assignment

In reply to SF Markus Elfring

From: 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
index 057479b7bd72..be2fe3ebae78 100644
@@ -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
maintainer Acked-by on v1 5/5
#17 lore raw

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 +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.

Quoted 26 lines
---
 net/sctp/protocol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/sctp/protocol.c +2 -1
index 057479b7bd72..be2fe3ebae78 100644
@@ -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
Acked-by on v1 5/5
#18 lore raw

Re: [PATCH 5/5] sctp: Adjust one function call together with a variable assignment

In reply to SF Markus Elfring
Quoted 20 lines · SF Markus Elfring

From: 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 +0 -0
index 057479b7bd72..be2fe3ebae78 100644

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

maintainer
#19 lore raw
In reply to SF Markus Elfring
Quoted 13 lines · SF Markus Elfring

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

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