Skip to contentSkip to conversation

workqueue: fix cast warnings on i386

RFC PATCH In review Randy Dunlap 3 participants 5 messages Apr 29, 2023 – May 8, 2023 Workqueue

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 workqueue: fix cast warnings on i386

Add casts to avoid int-to-pointer-cast warings on i386 or UML for i386:

../kernel/workqueue.c: In function ‘get_work_pwq’:
../kernel/workqueue.c:713:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
713 | return (void *)(data & WORK_STRUCT_WQ_DATA_MASK);
| ^
../kernel/workqueue.c: In function ‘get_work_pool’:
../kernel/workqueue.c:741:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
741 | return ((struct pool_workqueue *)
| ^
../kernel/workqueue.c: In function ‘get_work_pool_id’:
../kernel/workqueue.c:763:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
763 | return ((struct pool_workqueue *)
| ^

Fixes e120153ddf86 ("workqueue: fix how cpu number is stored in work->data")
Fixes 112202d9098a ("workqueue: rename cpu_workqueue to pool_workqueue")
Cc Tejun Heo <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 kernel/workqueue.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/workqueue.c +3 -3
diff -- a/kernel/workqueue.c b/kernel/workqueue.c
@@ -710,7 +710,7 @@ static struct pool_workqueue *get_work_p
 	unsigned long data = atomic_long_read(&work->data);
 
 	if (data & WORK_STRUCT_PWQ)
-		return (void *)(data & WORK_STRUCT_WQ_DATA_MASK);
+		return (void *)(unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK);
 	else
 		return NULL;
 }
@@ -739,7 +739,7 @@ static struct worker_pool *get_work_pool
 
 	if (data & WORK_STRUCT_PWQ)
 		return ((struct pool_workqueue *)
-			(data & WORK_STRUCT_WQ_DATA_MASK))->pool;
+			(unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK))->pool;
 
 	pool_id = data >> WORK_OFFQ_POOL_SHIFT;
 	if (pool_id == WORK_OFFQ_POOL_NONE)
@@ -761,7 +761,7 @@ static int get_work_pool_id(struct work_
 
 	if (data & WORK_STRUCT_PWQ)
 		return ((struct pool_workqueue *)
-			(data & WORK_STRUCT_WQ_DATA_MASK))->pool->id;
+			(unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK))->pool->id;
 
 	return data >> WORK_OFFQ_POOL_SHIFT;
 }
reviewer
#1 lore raw
Quoted 16 lines · Randy Dunlap

Add casts to avoid int-to-pointer-cast warings on i386 or UML for i386:

../kernel/workqueue.c: In function ‘get_work_pwq’:
../kernel/workqueue.c:713:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
713 | return (void *)(data & WORK_STRUCT_WQ_DATA_MASK);
| ^
../kernel/workqueue.c: In function ‘get_work_pool’:
../kernel/workqueue.c:741:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
741 | return ((struct pool_workqueue *)
| ^
../kernel/workqueue.c: In function ‘get_work_pool_id’:
../kernel/workqueue.c:763:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
763 | return ((struct pool_workqueue *)
| ^

Hello, Randy

Both the type of the "data" and WORK_STRUCT_WQ_DATA_MASK are "unsigned long", so I don't think "(data & WORK_STRUCT_WQ_DATA_MASK)" needs to be converted to "unsigned long".

WORK_STRUCT_FLAG_MASK = (1UL << WORK_STRUCT_FLAG_BITS) - 1,
WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK,

This simple fix might hide the real problem.

Thanks
Lai.

Quoted 39 lines
Fixes e120153ddf86 ("workqueue: fix how cpu number is stored in work->data")
Fixes 112202d9098a ("workqueue: rename cpu_workqueue to pool_workqueue")
Cc Tejun Heo <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 kernel/workqueue.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff -- a/kernel/workqueue.c b/kernel/workqueue.c

kernel/workqueue.c +3 -3
@@ -710,7 +710,7 @@ static struct pool_workqueue *get_work_p
        unsigned long data = atomic_long_read(&work->data);
 
        if (data & WORK_STRUCT_PWQ)
-               return (void *)(data & WORK_STRUCT_WQ_DATA_MASK);
+               return (void *)(unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK);
        else
                return NULL;
 }
@@ -739,7 +739,7 @@ static struct worker_pool *get_work_pool
 
        if (data & WORK_STRUCT_PWQ)
                return ((struct pool_workqueue *)
-                       (data & WORK_STRUCT_WQ_DATA_MASK))->pool;
+                       (unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK))->pool;
 
        pool_id = data >> WORK_OFFQ_POOL_SHIFT;
        if (pool_id == WORK_OFFQ_POOL_NONE)
@@ -761,7 +761,7 @@ static int get_work_pool_id(struct work_
 
        if (data & WORK_STRUCT_PWQ)
                return ((struct pool_workqueue *)
-                       (data & WORK_STRUCT_WQ_DATA_MASK))->pool->id;
+                       (unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK))->pool->id;
 
        return data >> WORK_OFFQ_POOL_SHIFT;
 }
#2 lore raw

Hi Lai,

Quoted 20 lines · Lai Jiangshan
Quoted 16 lines · Randy Dunlap

Add casts to avoid int-to-pointer-cast warings on i386 or UML for i386:

../kernel/workqueue.c: In function ‘get_work_pwq’:
../kernel/workqueue.c:713:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
713 | return (void *)(data & WORK_STRUCT_WQ_DATA_MASK);
| ^
../kernel/workqueue.c: In function ‘get_work_pool’:
../kernel/workqueue.c:741:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
741 | return ((struct pool_workqueue *)
| ^
../kernel/workqueue.c: In function ‘get_work_pool_id’:
../kernel/workqueue.c:763:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
763 | return ((struct pool_workqueue *)
| ^

Hello, Randy

Quoted 8 lines

Both the type of the "data" and WORK_STRUCT_WQ_DATA_MASK are "unsigned long", so I don't think "(data & WORK_STRUCT_WQ_DATA_MASK)" needs to be converted to "unsigned long".

WORK_STRUCT_FLAG_MASK = (1UL << WORK_STRUCT_FLAG_BITS) - 1,
WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK,

This simple fix might hide the real problem.

Thanks for replying.

Do you have any suggestions for how to eliminate these warnings on i386 and ARCH=um SUBARCH=i386?

Quoted 42 lines

Thanks
Lai.

Quoted 39 lines
Fixes e120153ddf86 ("workqueue: fix how cpu number is stored in work->data")
Fixes 112202d9098a ("workqueue: rename cpu_workqueue to pool_workqueue")
Cc Tejun Heo <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 kernel/workqueue.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff -- a/kernel/workqueue.c b/kernel/workqueue.c

kernel/workqueue.c +3 -3
@@ -710,7 +710,7 @@ static struct pool_workqueue *get_work_p
        unsigned long data = atomic_long_read(&work->data);
 
        if (data & WORK_STRUCT_PWQ)
-               return (void *)(data & WORK_STRUCT_WQ_DATA_MASK);
+               return (void *)(unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK);
        else
                return NULL;
 }
@@ -739,7 +739,7 @@ static struct worker_pool *get_work_pool
 
        if (data & WORK_STRUCT_PWQ)
                return ((struct pool_workqueue *)
-                       (data & WORK_STRUCT_WQ_DATA_MASK))->pool;
+                       (unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK))->pool;
 
        pool_id = data >> WORK_OFFQ_POOL_SHIFT;
        if (pool_id == WORK_OFFQ_POOL_NONE)
@@ -761,7 +761,7 @@ static int get_work_pool_id(struct work_
 
        if (data & WORK_STRUCT_PWQ)
                return ((struct pool_workqueue *)
-                       (data & WORK_STRUCT_WQ_DATA_MASK))->pool->id;
+                       (unsigned long)(data & WORK_STRUCT_WQ_DATA_MASK))->pool->id;
 
        return data >> WORK_OFFQ_POOL_SHIFT;
 }
Signature · 1 line
~Randy
#3 lore raw
Quoted 8 lines · Randy Dunlap
Quoted 7 lines · Lai Jiangshan

Both the type of the "data" and WORK_STRUCT_WQ_DATA_MASK are "unsigned long", so I don't think "(data & WORK_STRUCT_WQ_DATA_MASK)" needs to be converted to "unsigned long".

WORK_STRUCT_FLAG_MASK = (1UL << WORK_STRUCT_FLAG_BITS) - 1,
WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK,

Quoted 6 lines
Quoted 1 line

This simple fix might hide the real problem.

Thanks for replying.

Do you have any suggestions for how to eliminate these warnings on i386 and ARCH=um SUBARCH=i386?

I'm pretty sure the patch I posted earlier is the correct one, see
https://lore.kernel.org/all/[email protected]/

Sorry I never followed up on this after the initial post, I have a backlog of patches that I sent out as build fixes but that for some reason have not made it in.

Arnd

#4 lore raw
Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Randy Dunlap
Quoted 8 lines · Lai Jiangshan

Both the type of the "data" and WORK_STRUCT_WQ_DATA_MASK are "unsigned long", so I don't think "(data & WORK_STRUCT_WQ_DATA_MASK)" needs to be converted to "unsigned long".

WORK_STRUCT_FLAG_MASK = (1UL << WORK_STRUCT_FLAG_BITS) - 1,
WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK,

This simple fix might hide the real problem.

Quoted 8 lines
Quoted 4 lines

Thanks for replying.

Do you have any suggestions for how to eliminate these warnings on i386 and ARCH=um SUBARCH=i386?

I'm pretty sure the patch I posted earlier is the correct one, see
https://lore.kernel.org/all/[email protected]/

Thanks for the reply. Your patch looks good. I appreciate the explanation.

Quoted 3 lines

Sorry I never followed up on this after the initial post, I have a backlog of patches that I sent out as build fixes but that for some reason have not made it in.

I know how that goes. I have quite a few as well.

Signature · 1 line
~Randy