Skip to contentSkip to conversation

Suppress the sparse warning ./include/linux/slab.h:332:43: warning: dubious: x & !y

PATCH In review Darryl T. Agostinelli 2 participants 2 messages Nov 9, 2018 – Nov 14, 2018

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

PATCH 1/1 Suppress the sparse warning ./include/linux/slab.h:332:43: warning: dubious: x & !y

---
 include/linux/slab.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/slab.h +5 -1
index 918f374e7156..883b7f56bf35 100644
@@ -317,6 +317,7 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
 	int is_dma = 0;
 	int type_dma = 0;
 	int is_reclaimable;
+	int y;
 
 #ifdef CONFIG_ZONE_DMA
 	is_dma = !!(flags & __GFP_DMA);
@@ -329,7 +330,10 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
 	 * If an allocation is both __GFP_DMA and __GFP_RECLAIMABLE, return
 	 * KMALLOC_DMA and effectively ignore __GFP_RECLAIMABLE
 	 */
-	return type_dma + (is_reclaimable & !is_dma) * KMALLOC_RECLAIM;
+
+	y = (is_reclaimable & (is_dma == 0 ? 1 : 0));
+
+	return type_dma + y * KMALLOC_RECLAIM;
 }
 
 /*
Signature · 1 line
2.17.1
#1 lore raw
Quoted 19 lines · Darryl T. Agostinelli
---
 include/linux/slab.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/slab.h +1 -0
index 918f374e7156..883b7f56bf35 100644
@@ -317,6 +317,7 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
 	int is_dma = 0;
 	int type_dma = 0;
 	int is_reclaimable;
+	int y;
 
 #ifdef CONFIG_ZONE_DMA
 	is_dma = !!(flags & __GFP_DMA);
@@ -329,7 +330,10 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
 	 * If an allocation is both __GFP_DMA and __GFP_RECLAIMABLE, return

include/linux/slab.h static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags) · line 339

Quoted 10 lines
include/linux/slab.h +4 -1
 	 * KMALLOC_DMA and effectively ignore __GFP_RECLAIMABLE
 	 */
-	return type_dma + (is_reclaimable & !is_dma) * KMALLOC_RECLAIM;
+
+	y = (is_reclaimable & (is_dma == 0 ? 1 : 0));
+
+	return type_dma + y * KMALLOC_RECLAIM;
 }
 
 /*

I agree with you that the function as written is less than pretty :) How does the assembly change as a result of this code change, however? This will be in the kmalloc() path so impacting the assembly to fix a sparse warning may not be warranted.