Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1648006 > unrolled thread

[PATCH] tipc: Delete error messages for failed memory allocations in three functions

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2017-05-23 15:10 +0200
Last post2017-05-23 18:40 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] tipc: Delete error messages for failed memory allocations in  three functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-05-23 15:10 +0200
    Re: [PATCH] tipc: Delete error messages for failed memory  allocations in three functions Joe Perches <joe@perches.com> - 2017-05-23 16:10 +0200
      Re: tipc: Delete error messages for failed memory allocations in  three functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-05-23 18:30 +0200
        Re: tipc: Delete error messages for failed memory allocations in  three functions Joe Perches <joe@perches.com> - 2017-05-23 18:40 +0200

#1648006 — [PATCH] tipc: Delete error messages for failed memory allocations in three functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-05-23 15:10 +0200
Subject[PATCH] tipc: Delete error messages for failed memory allocations in three functions
Message-ID<tKhJv-3D6-11@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1648091 — Re: [PATCH] tipc: Delete error messages for failed memory allocations in three functions

FromJoe Perches <joe@perches.com>
Date2017-05-23 16:10 +0200
SubjectRe: [PATCH] tipc: Delete error messages for failed memory allocations in three functions
Message-ID<tKiFA-4he-11@gated-at.bofh.it>
In reply to#1648006
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.

[toc] | [prev] | [next] | [standalone]


#1648247 — Re: tipc: Delete error messages for failed memory allocations in three functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-05-23 18:30 +0200
SubjectRe: tipc: Delete error messages for failed memory allocations in three functions
Message-ID<tKkR4-5Bx-9@gated-at.bofh.it>
In reply to#1648091
> 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

[toc] | [prev] | [next] | [standalone]


#1648259 — Re: tipc: Delete error messages for failed memory allocations in three functions

FromJoe Perches <joe@perches.com>
Date2017-05-23 18:40 +0200
SubjectRe: tipc: Delete error messages for failed memory allocations in three functions
Message-ID<tKl0L-5Ft-33@gated-at.bofh.it>
In reply to#1648247
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.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web