public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked
@ 2025-03-24  9:07 Ye Liu
  2025-03-24 16:10 ` Markus Elfring
  2025-03-25  5:24 ` Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Ye Liu @ 2025-03-24  9:07 UTC (permalink / raw)
  To: tj; +Cc: jiangshanlai, linux-kernel, Ye Liu

From: Ye Liu <liuye@kylinos.cn>

Commit 84193c07105c ("workqueue: Generalize unbound CPU pods") introduced
a change that caused apply_workqueue_attrs_locked() to return error
pointers using PTR_ERR() on failure instead of a negative error code.
This caused unexpected behavior in functions that rely on the return value
of apply_workqueue_attrs_locked, such as alloc_and_link_pwqs().

Specifically, alloc_and_link_pwqs() expects apply_workqueue_attrs_locked()
to return 0 on success and a negative error code on failure. However,
returning PTR_ERR(ctx) instead of -ENOMEM led to incorrect error handling
in __alloc_workqueue, potentially causing system instability or crashes.

This patch ensures apply_workqueue_attrs_locked() returns a proper negative
error code (-ENOMEM) in case of failure, restoring expected behavior.

Fixes: 84193c07105c ("workqueue: Generalize unbound CPU pods")
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 kernel/workqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index bfe030b443e2..8ba679d9b566 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5363,7 +5363,7 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,
 
 	ctx = apply_wqattrs_prepare(wq, attrs, wq_unbound_cpumask);
 	if (IS_ERR(ctx))
-		return PTR_ERR(ctx);
+		return -ENOMEM;
 
 	/* the ctx has been prepared successfully, let's commit it */
 	apply_wqattrs_commit(ctx);
-- 
2.25.1


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

* Re: [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked
  2025-03-24  9:07 [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked Ye Liu
@ 2025-03-24 16:10 ` Markus Elfring
  2025-03-25  1:33   ` Ye Liu
  2025-03-25  5:24 ` Dan Carpenter
  1 sibling, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2025-03-24 16:10 UTC (permalink / raw)
  To: Ye Liu, kernel-janitors, Tejun Heo; +Cc: Ye Liu, LKML, Lai Jiangshan

…
> This patch ensures …

See also:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14#n94

Regards,
Markus

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

* Re: [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked
  2025-03-24 16:10 ` Markus Elfring
@ 2025-03-25  1:33   ` Ye Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Ye Liu @ 2025-03-25  1:33 UTC (permalink / raw)
  To: Markus Elfring, Ye Liu, kernel-janitors, Tejun Heo; +Cc: LKML, Lai Jiangshan


在 2025/3/25 00:10, Markus Elfring 写道:
> …
>> This patch ensures …
> See also:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14#n94

Thanks for your feedback. I'll update the description accordingly and submit
a revised patch. Do you have any other suggestions for this patch?
Is it worth submitting?                                                     

Thanks,
Ye Liu


> Regards,
> Markus

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

* Re: [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked
  2025-03-24  9:07 [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked Ye Liu
  2025-03-24 16:10 ` Markus Elfring
@ 2025-03-25  5:24 ` Dan Carpenter
  2025-03-25  5:53   ` Ye Liu
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2025-03-25  5:24 UTC (permalink / raw)
  To: Ye Liu; +Cc: tj, jiangshanlai, linux-kernel, Ye Liu

On Mon, Mar 24, 2025 at 05:07:48PM +0800, Ye Liu wrote:
v> From: Ye Liu <liuye@kylinos.cn>
> 
> Commit 84193c07105c ("workqueue: Generalize unbound CPU pods") introduced
> a change that caused apply_workqueue_attrs_locked() to return error
> pointers using PTR_ERR() on failure instead of a negative error code.

PTR_ERR() does return negative error codes.  Unless you pass it a NULL
pointer, then it returns success.  Or if you pass it a valid pointer it
returns garbage.

> This caused unexpected behavior in functions that rely on the return value
> of apply_workqueue_attrs_locked, such as alloc_and_link_pwqs().
> 
> Specifically, alloc_and_link_pwqs() expects apply_workqueue_attrs_locked()
> to return 0 on success and a negative error code on failure. However,
> returning PTR_ERR(ctx) instead of -ENOMEM led to incorrect error handling
> in __alloc_workqueue, potentially causing system instability or crashes.
> 
> This patch ensures apply_workqueue_attrs_locked() returns a proper negative
> error code (-ENOMEM) in case of failure, restoring expected behavior.
> 
> Fixes: 84193c07105c ("workqueue: Generalize unbound CPU pods")
> Signed-off-by: Ye Liu <liuye@kylinos.cn>
> ---
>  kernel/workqueue.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index bfe030b443e2..8ba679d9b566 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -5363,7 +5363,7 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,
>  
>  	ctx = apply_wqattrs_prepare(wq, attrs, wq_unbound_cpumask);
>  	if (IS_ERR(ctx))
> -		return PTR_ERR(ctx);
> +		return -ENOMEM;
>  

The original code was correct and the patch is wrong.

regards,
dan carpenter


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

* Re: [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked
  2025-03-25  5:24 ` Dan Carpenter
@ 2025-03-25  5:53   ` Ye Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Ye Liu @ 2025-03-25  5:53 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: tj, jiangshanlai, linux-kernel, Ye Liu


在 2025/3/25 13:24, Dan Carpenter 写道:
> On Mon, Mar 24, 2025 at 05:07:48PM +0800, Ye Liu wrote:
> v> From: Ye Liu <liuye@kylinos.cn>
>> Commit 84193c07105c ("workqueue: Generalize unbound CPU pods") introduced
>> a change that caused apply_workqueue_attrs_locked() to return error
>> pointers using PTR_ERR() on failure instead of a negative error code.
> PTR_ERR() does return negative error codes.  Unless you pass it a NULL
> pointer, then it returns success.  Or if you pass it a valid pointer it
> returns garbage.
I misunderstood PTR_ERR(). Thanks for pointing it out.
>> This caused unexpected behavior in functions that rely on the return value
>> of apply_workqueue_attrs_locked, such as alloc_and_link_pwqs().
>>
>> Specifically, alloc_and_link_pwqs() expects apply_workqueue_attrs_locked()
>> to return 0 on success and a negative error code on failure. However,
>> returning PTR_ERR(ctx) instead of -ENOMEM led to incorrect error handling
>> in __alloc_workqueue, potentially causing system instability or crashes.
>>
>> This patch ensures apply_workqueue_attrs_locked() returns a proper negative
>> error code (-ENOMEM) in case of failure, restoring expected behavior.
>>
>> Fixes: 84193c07105c ("workqueue: Generalize unbound CPU pods")
>> Signed-off-by: Ye Liu <liuye@kylinos.cn>
>> ---
>>  kernel/workqueue.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
>> index bfe030b443e2..8ba679d9b566 100644
>> --- a/kernel/workqueue.c
>> +++ b/kernel/workqueue.c
>> @@ -5363,7 +5363,7 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,
>>  
>>  	ctx = apply_wqattrs_prepare(wq, attrs, wq_unbound_cpumask);
>>  	if (IS_ERR(ctx))
>> -		return PTR_ERR(ctx);
>> +		return -ENOMEM;
>>  
> The original code was correct and the patch is wrong.
Drop it.
> regards,
> dan carpenter
>

Thanks,

Ye Liu


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

end of thread, other threads:[~2025-03-25  5:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-24  9:07 [PATCH] workqueue: Fix incorrect error return value in apply_workqueue_attrs_locked Ye Liu
2025-03-24 16:10 ` Markus Elfring
2025-03-25  1:33   ` Ye Liu
2025-03-25  5:24 ` Dan Carpenter
2025-03-25  5:53   ` Ye Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox