netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tipc: Delete error messages for failed memory allocations in three functions
@ 2017-05-23 13:07 SF Markus Elfring
  2017-05-23 14:02 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: SF Markus Elfring @ 2017-05-23 13:07 UTC (permalink / raw)
  To: tipc-discussion, netdev, David S. Miller, Jon Maloy, Ying Xue
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2017 14:45:25 +0200

Omit four extra messages for memory allocation failures in these functions.

This issue was detected by using the Coccinelle software.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/tipc/name_table.c | 15 ++++-----------
 net/tipc/node.c       |  5 ++---
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index bd0aac87b41a..7e731af8a1a7 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -117,10 +117,8 @@ static struct publication *publ_create(u32 type, u32 lower, u32 upper,
 				       u32 key)
 {
 	struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC);
-	if (publ == NULL) {
-		pr_warn("Publication creation failure, no memory\n");
+	if (!publ)
 		return NULL;
-	}
 
 	publ->type = type;
 	publ->lower = lower;
@@ -270,11 +268,9 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net,
 		if (nseq->first_free == nseq->alloc) {
 			struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2);
 
-			if (!sseqs) {
-				pr_warn("Cannot publish {%u,%u,%u}, no memory\n",
-					type, lower, upper);
+			if (!sseqs)
 				return NULL;
-			}
+
 			memcpy(sseqs, nseq->sseqs,
 			       nseq->alloc * sizeof(struct sub_seq));
 			kfree(nseq->sseqs);
@@ -283,11 +279,8 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net,
 		}
 
 		info = kzalloc(sizeof(*info), GFP_ATOMIC);
-		if (!info) {
-			pr_warn("Cannot publish {%u,%u,%u}, no memory\n",
-				type, lower, upper);
+		if (!info)
 			return NULL;
-		}
 
 		INIT_LIST_HEAD(&info->node_list);
 		INIT_LIST_HEAD(&info->cluster_list);
diff --git a/net/tipc/node.c b/net/tipc/node.c
index aeef8011ac7d..0c7f5f755a28 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -324,10 +324,9 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u16 capabilities)
 		goto exit;
 	}
 	n = kzalloc(sizeof(*n), GFP_ATOMIC);
-	if (!n) {
-		pr_warn("Node creation failed, no memory\n");
+	if (!n)
 		goto exit;
-	}
+
 	n->addr = addr;
 	n->net = net;
 	n->capabilities = capabilities;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tipc: Delete error messages for failed memory allocations in three functions
  2017-05-23 13:07 [PATCH] tipc: Delete error messages for failed memory allocations in three functions SF Markus Elfring
@ 2017-05-23 14:02 ` Joe Perches
  2017-05-23 16:23   ` SF Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2017-05-23 14:02 UTC (permalink / raw)
  To: SF Markus Elfring, tipc-discussion, netdev, David S. Miller,
	Jon Maloy, Ying Xue
  Cc: LKML, kernel-janitors

On Tue, 2017-05-23 at 15:07 +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 23 May 2017 14:45:25 +0200
> 
> Omit four extra messages for memory allocation failures in these functions.

This is fine but you should look to optimize or figure out
whether optimization is desirable for the effective realloc.

> diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
[]
> @@ -270,11 +268,9 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net,
>  		if (nseq->first_free == nseq->alloc) {
>  			struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2);
>  
> -			if (!sseqs) {
> -				pr_warn("Cannot publish {%u,%u,%u}, no memory\n",
> -					type, lower, upper);
> +			if (!sseqs)
>  				return NULL;
> -			}
> +
>  			memcpy(sseqs, nseq->sseqs,
>  			       nseq->alloc * sizeof(struct sub_seq));

tipc_subseq_alloc does a kcalloc (memset to 0),
half of which is immediately overwritten.

In other words, don't just blindly remove stuff,
understand what it does and improve it.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tipc: Delete error messages for failed memory allocations in three functions
  2017-05-23 14:02 ` Joe Perches
@ 2017-05-23 16:23   ` SF Markus Elfring
  2017-05-23 16:39     ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: SF Markus Elfring @ 2017-05-23 16:23 UTC (permalink / raw)
  To: Joe Perches, tipc-discussion, netdev
  Cc: David S. Miller, Jon Maloy, Ying Xue, LKML, kernel-janitors

> tipc_subseq_alloc does a kcalloc (memset to 0),
> half of which is immediately overwritten.
> 
> In other words, don't just blindly remove stuff,
> understand what it does and improve it.

Do you suggest another specific source code transformation pattern here?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tipc: Delete error messages for failed memory allocations in three functions
  2017-05-23 16:23   ` SF Markus Elfring
@ 2017-05-23 16:39     ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2017-05-23 16:39 UTC (permalink / raw)
  To: SF Markus Elfring, tipc-discussion, netdev
  Cc: David S. Miller, Jon Maloy, Ying Xue, LKML, kernel-janitors

On Tue, 2017-05-23 at 18:23 +0200, SF Markus Elfring wrote:
> > tipc_subseq_alloc does a kcalloc (memset to 0),
> > half of which is immediately overwritten.
> > 
> > In other words, don't just blindly remove stuff,
> > understand what it does and improve it.
> 
> Do you suggest another specific source code transformation pattern here?

For the somewhat hard-of-thinking,
something like krealloc would do nicely.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-23 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23 13:07 [PATCH] tipc: Delete error messages for failed memory allocations in three functions SF Markus Elfring
2017-05-23 14:02 ` Joe Perches
2017-05-23 16:23   ` SF Markus Elfring
2017-05-23 16:39     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).