linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/slab: One function call less in verify_redzone_free()
@ 2019-07-05 14:50 Markus Elfring
  2019-07-05 18:13 ` Christopher Lameter
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2019-07-05 14:50 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, Christoph Lameter, David Rientjes,
	Joonsoo Kim, Pekka Enberg
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 5 Jul 2019 16:40:09 +0200

Avoid an extra function call by using a ternary operator instead of
a conditional statement for a string literal selection.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 mm/slab.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 9df370558e5d..849b5c276588 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2701,10 +2701,10 @@ static inline void verify_redzone_free(struct kmem_cache *cache, void *obj)
 	if (redzone1 == RED_ACTIVE && redzone2 == RED_ACTIVE)
 		return;

-	if (redzone1 == RED_INACTIVE && redzone2 == RED_INACTIVE)
-		slab_error(cache, "double free detected");
-	else
-		slab_error(cache, "memory outside object was overwritten");
+	slab_error(cache,
+		   redzone1 == RED_INACTIVE && redzone2 == RED_INACTIVE
+		   ? "double free detected"
+		   : "memory outside object was overwritten");

 	pr_err("%px: redzone 1:0x%llx, redzone 2:0x%llx\n",
 	       obj, redzone1, redzone2);
--
2.22.0


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

* Re: [PATCH] mm/slab: One function call less in verify_redzone_free()
  2019-07-05 14:50 [PATCH] mm/slab: One function call less in verify_redzone_free() Markus Elfring
@ 2019-07-05 18:13 ` Christopher Lameter
  2019-07-06 22:45   ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: Christopher Lameter @ 2019-07-05 18:13 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-mm, Andrew Morton, David Rientjes, Joonsoo Kim,
	Pekka Enberg, LKML, kernel-janitors

On Fri, 5 Jul 2019, Markus Elfring wrote:

> Avoid an extra function call by using a ternary operator instead of
> a conditional statement for a string literal selection.

Well. I thought the compiler does that on its own? And the tenary operator
makes the code difficult to read.


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

* Re: [PATCH] mm/slab: One function call less in verify_redzone_free()
  2019-07-05 18:13 ` Christopher Lameter
@ 2019-07-06 22:45   ` David Rientjes
  0 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2019-07-06 22:45 UTC (permalink / raw)
  To: Christopher Lameter
  Cc: Markus Elfring, linux-mm, Andrew Morton, Joonsoo Kim,
	Pekka Enberg, LKML, kernel-janitors

On Fri, 5 Jul 2019, Christopher Lameter wrote:

> On Fri, 5 Jul 2019, Markus Elfring wrote:
> 
> > Avoid an extra function call by using a ternary operator instead of
> > a conditional statement for a string literal selection.
> 
> Well. I thought the compiler does that on its own? And the tenary operator
> makes the code difficult to read.
> 

Right, and I don't understand the changelog: yes, there's one less 
function call in the source but functionally there's still a conditional; 
this isn't even optimizing DEBUG builds.

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

* [PATCH] mm/slab: One function call less in verify_redzone_free()
@ 2019-07-05 14:50 Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-07-05 14:50 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, Christoph Lameter, David Rientjes,
	Joonsoo Kim, Pekka Enberg
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 5 Jul 2019 16:40:09 +0200

Avoid an extra function call by using a ternary operator instead of
a conditional statement for a string literal selection.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 mm/slab.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 9df370558e5d..849b5c276588 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2701,10 +2701,10 @@ static inline void verify_redzone_free(struct kmem_cache *cache, void *obj)
 	if (redzone1 == RED_ACTIVE && redzone2 == RED_ACTIVE)
 		return;

-	if (redzone1 == RED_INACTIVE && redzone2 == RED_INACTIVE)
-		slab_error(cache, "double free detected");
-	else
-		slab_error(cache, "memory outside object was overwritten");
+	slab_error(cache,
+		   redzone1 == RED_INACTIVE && redzone2 == RED_INACTIVE
+		   ? "double free detected"
+		   : "memory outside object was overwritten");

 	pr_err("%px: redzone 1:0x%llx, redzone 2:0x%llx\n",
 	       obj, redzone1, redzone2);
--
2.22.0


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

end of thread, other threads:[~2019-07-06 22:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-05 14:50 [PATCH] mm/slab: One function call less in verify_redzone_free() Markus Elfring
2019-07-05 18:13 ` Christopher Lameter
2019-07-06 22:45   ` David Rientjes
2019-07-05 14:50 Markus Elfring

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