2013-08-20 03:44:34

by Chen Gang

[permalink] [raw]
Subject: [PATCH] kernel/padata.c: always check the return value of __padata_remove_cpu() and __padata_add_cpu()

When failure occures, __padata_add_cpu() and __padata_remove_cpu() will
return -ENOMEM, which need be noticed in any cases (even in cleaning up
cases).

Signed-off-by: Chen Gang <[email protected]>
---
kernel/padata.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/padata.c b/kernel/padata.c
index 072f4ee..6a124cd 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -871,16 +871,20 @@ static int padata_cpu_callback(struct notifier_block *nfb,
if (!pinst_has_cpu(pinst, cpu))
break;
mutex_lock(&pinst->lock);
- __padata_remove_cpu(pinst, cpu);
+ err = __padata_remove_cpu(pinst, cpu);
mutex_unlock(&pinst->lock);
+ if (err)
+ return notifier_from_errno(err);

case CPU_DOWN_FAILED:
case CPU_DOWN_FAILED_FROZEN:
if (!pinst_has_cpu(pinst, cpu))
break;
mutex_lock(&pinst->lock);
- __padata_add_cpu(pinst, cpu);
+ err = __padata_add_cpu(pinst, cpu);
mutex_unlock(&pinst->lock);
+ if (err)
+ return notifier_from_errno(err);
}

return NOTIFY_OK;
--
1.7.7.6


2013-08-20 03:45:35

by Chen Gang

[permalink] [raw]
Subject: Re: [PATCH] kernel/padata.c: always check the return value of __padata_remove_cpu() and __padata_add_cpu()


If this patch is correct, better to let CPU_ONLINE and CPU_DOWN_FAILED
share the same code.

And do we need a comment "/* fall through */" between CPU_UP_CANCELED
and CPU_DOWN_FAILED (or it is another bug, need a 'break' statement) ?

At last, also better to let CPU_DOWN_PREPARE and CPU_UP_CANCELED share
the same code (if need a 'break'), or share the most of code (if "fall
through").

Thanks.

On 08/20/2013 11:43 AM, Chen Gang wrote:
> When failure occures, __padata_add_cpu() and __padata_remove_cpu() will
> return -ENOMEM, which need be noticed in any cases (even in cleaning up
> cases).
>
> Signed-off-by: Chen Gang <[email protected]>
> ---
> kernel/padata.c | 8 ++++++--
> 1 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/padata.c b/kernel/padata.c
> index 072f4ee..6a124cd 100644
> --- a/kernel/padata.c
> +++ b/kernel/padata.c
> @@ -871,16 +871,20 @@ static int padata_cpu_callback(struct notifier_block *nfb,
> if (!pinst_has_cpu(pinst, cpu))
> break;
> mutex_lock(&pinst->lock);
> - __padata_remove_cpu(pinst, cpu);
> + err = __padata_remove_cpu(pinst, cpu);
> mutex_unlock(&pinst->lock);
> + if (err)
> + return notifier_from_errno(err);
>
> case CPU_DOWN_FAILED:
> case CPU_DOWN_FAILED_FROZEN:
> if (!pinst_has_cpu(pinst, cpu))
> break;
> mutex_lock(&pinst->lock);
> - __padata_add_cpu(pinst, cpu);
> + err = __padata_add_cpu(pinst, cpu);
> mutex_unlock(&pinst->lock);
> + if (err)
> + return notifier_from_errno(err);
> }
>
> return NOTIFY_OK;
>


--
Chen Gang

2013-08-22 05:28:21

by Chen Gang

[permalink] [raw]
Subject: Re: [PATCH] kernel/padata.c: always check the return value of __padata_remove_cpu() and __padata_add_cpu()

On 08/22/2013 01:11 PM, Steffen Klassert wrote:
> On Tue, Aug 20, 2013 at 11:44:31AM +0800, Chen Gang wrote:
>>
>> If this patch is correct, better to let CPU_ONLINE and CPU_DOWN_FAILED
>> share the same code.
>>
>> And do we need a comment "/* fall through */" between CPU_UP_CANCELED
>> and CPU_DOWN_FAILED (or it is another bug, need a 'break' statement) ?
>>
>> At last, also better to let CPU_DOWN_PREPARE and CPU_UP_CANCELED share
>> the same code (if need a 'break'), or share the most of code (if "fall
>> through").
>>
>
> CPU_ONLINE and CPU_DOWN_FAILED can share the code. Same is true for
> CPU_DOWN_PREPARE and CPU_UP_CANCELED.
>
> Thanks!
>
>

Thank you too.

And need I send another patch for it ?

Or just make by yourself (and better to mark me as Reported-by). :-)


Thanks.
--
Chen Gang

2013-08-22 05:42:51

by Steffen Klassert

[permalink] [raw]
Subject: Re: [PATCH] kernel/padata.c: always check the return value of __padata_remove_cpu() and __padata_add_cpu()

On Tue, Aug 20, 2013 at 11:44:31AM +0800, Chen Gang wrote:
>
> If this patch is correct, better to let CPU_ONLINE and CPU_DOWN_FAILED
> share the same code.
>
> And do we need a comment "/* fall through */" between CPU_UP_CANCELED
> and CPU_DOWN_FAILED (or it is another bug, need a 'break' statement) ?
>
> At last, also better to let CPU_DOWN_PREPARE and CPU_UP_CANCELED share
> the same code (if need a 'break'), or share the most of code (if "fall
> through").
>

CPU_ONLINE and CPU_DOWN_FAILED can share the code. Same is true for
CPU_DOWN_PREPARE and CPU_UP_CANCELED.

Thanks!

2013-08-22 06:05:08

by Steffen Klassert

[permalink] [raw]
Subject: Re: [PATCH] kernel/padata.c: always check the return value of __padata_remove_cpu() and __padata_add_cpu()

On Thu, Aug 22, 2013 at 01:27:16PM +0800, Chen Gang wrote:
> On 08/22/2013 01:11 PM, Steffen Klassert wrote:
> > On Tue, Aug 20, 2013 at 11:44:31AM +0800, Chen Gang wrote:
> >>
> >> If this patch is correct, better to let CPU_ONLINE and CPU_DOWN_FAILED
> >> share the same code.
> >>
> >> And do we need a comment "/* fall through */" between CPU_UP_CANCELED
> >> and CPU_DOWN_FAILED (or it is another bug, need a 'break' statement) ?
> >>
> >> At last, also better to let CPU_DOWN_PREPARE and CPU_UP_CANCELED share
> >> the same code (if need a 'break'), or share the most of code (if "fall
> >> through").
> >>
> >
> > CPU_ONLINE and CPU_DOWN_FAILED can share the code. Same is true for
> > CPU_DOWN_PREPARE and CPU_UP_CANCELED.
> >
> > Thanks!
> >
> >
>
> Thank you too.
>
> And need I send another patch for it ?
>
> Or just make by yourself (and better to mark me as Reported-by). :-)
>

You found the problem, feel free to send a patch.

2013-08-22 07:18:40

by Chen Gang

[permalink] [raw]
Subject: Re: [PATCH] kernel/padata.c: always check the return value of __padata_remove_cpu() and __padata_add_cpu()

On 08/22/2013 02:05 PM, Steffen Klassert wrote:
> On Thu, Aug 22, 2013 at 01:27:16PM +0800, Chen Gang wrote:
>> On 08/22/2013 01:11 PM, Steffen Klassert wrote:
>>> On Tue, Aug 20, 2013 at 11:44:31AM +0800, Chen Gang wrote:
>>>>
>>>> If this patch is correct, better to let CPU_ONLINE and CPU_DOWN_FAILED
>>>> share the same code.
>>>>
>>>> And do we need a comment "/* fall through */" between CPU_UP_CANCELED
>>>> and CPU_DOWN_FAILED (or it is another bug, need a 'break' statement) ?
>>>>
>>>> At last, also better to let CPU_DOWN_PREPARE and CPU_UP_CANCELED share
>>>> the same code (if need a 'break'), or share the most of code (if "fall
>>>> through").
>>>>
>>>
>>> CPU_ONLINE and CPU_DOWN_FAILED can share the code. Same is true for
>>> CPU_DOWN_PREPARE and CPU_UP_CANCELED.
>>>
>>> Thanks!
>>>
>>>
>>
>> Thank you too.
>>
>> And need I send another patch for it ?
>>
>> Or just make by yourself (and better to mark me as Reported-by). :-)
>>
>
> You found the problem, feel free to send a patch.
>
>

Thanks, I will send patch v2 for it.

--
Chen Gang

2013-08-22 07:19:06

by Chen Gang

[permalink] [raw]
Subject: [PATCH v2] kernel/padata.c: share code between CPU_ONLINE and CPU_DOWN_FAILED, same to CPU_DOWN_PREPARE and CPU_UP_CANCELED

Share code between CPU_ONLINE and CPU_DOWN_FAILED, same to
CPU_DOWN_PREPARE and CPU_UP_CANCELED.

It will fix 2 bugs:

"not check the return value of __padata_remove_cpu() and __padata_add_cpu()".
"need add 'break' between CPU_UP_CANCELED and CPU_DOWN_FAILED".


Signed-off-by: Chen Gang <[email protected]>
---
kernel/padata.c | 20 ++++----------------
1 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/kernel/padata.c b/kernel/padata.c
index 072f4ee..2f0037a 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -846,6 +846,8 @@ static int padata_cpu_callback(struct notifier_block *nfb,
switch (action) {
case CPU_ONLINE:
case CPU_ONLINE_FROZEN:
+ case CPU_DOWN_FAILED:
+ case CPU_DOWN_FAILED_FROZEN:
if (!pinst_has_cpu(pinst, cpu))
break;
mutex_lock(&pinst->lock);
@@ -857,6 +859,8 @@ static int padata_cpu_callback(struct notifier_block *nfb,

case CPU_DOWN_PREPARE:
case CPU_DOWN_PREPARE_FROZEN:
+ case CPU_UP_CANCELED:
+ case CPU_UP_CANCELED_FROZEN:
if (!pinst_has_cpu(pinst, cpu))
break;
mutex_lock(&pinst->lock);
@@ -865,22 +869,6 @@ static int padata_cpu_callback(struct notifier_block *nfb,
if (err)
return notifier_from_errno(err);
break;
-
- case CPU_UP_CANCELED:
- case CPU_UP_CANCELED_FROZEN:
- if (!pinst_has_cpu(pinst, cpu))
- break;
- mutex_lock(&pinst->lock);
- __padata_remove_cpu(pinst, cpu);
- mutex_unlock(&pinst->lock);
-
- case CPU_DOWN_FAILED:
- case CPU_DOWN_FAILED_FROZEN:
- if (!pinst_has_cpu(pinst, cpu))
- break;
- mutex_lock(&pinst->lock);
- __padata_add_cpu(pinst, cpu);
- mutex_unlock(&pinst->lock);
}

return NOTIFY_OK;
--
1.7.7.6

2013-08-23 03:48:03

by Chen Gang

[permalink] [raw]
Subject: Re: [PATCH v2] kernel/padata.c: share code between CPU_ONLINE and CPU_DOWN_FAILED, same to CPU_DOWN_PREPARE and CPU_UP_CANCELED

On 08/22/2013 02:43 PM, Chen Gang wrote:
> Share code between CPU_ONLINE and CPU_DOWN_FAILED, same to
> CPU_DOWN_PREPARE and CPU_UP_CANCELED.
>
> It will fix 2 bugs:
>
> "not check the return value of __padata_remove_cpu() and __padata_add_cpu()".
> "need add 'break' between CPU_UP_CANCELED and CPU_DOWN_FAILED".
>

Do we need more details descriptions ?

If so, could Steffen give more expert details information ?

Thanks.

>
> Signed-off-by: Chen Gang <[email protected]>
> ---
> kernel/padata.c | 20 ++++----------------
> 1 files changed, 4 insertions(+), 16 deletions(-)
>
> diff --git a/kernel/padata.c b/kernel/padata.c
> index 072f4ee..2f0037a 100644
> --- a/kernel/padata.c
> +++ b/kernel/padata.c
> @@ -846,6 +846,8 @@ static int padata_cpu_callback(struct notifier_block *nfb,
> switch (action) {
> case CPU_ONLINE:
> case CPU_ONLINE_FROZEN:
> + case CPU_DOWN_FAILED:
> + case CPU_DOWN_FAILED_FROZEN:
> if (!pinst_has_cpu(pinst, cpu))
> break;
> mutex_lock(&pinst->lock);
> @@ -857,6 +859,8 @@ static int padata_cpu_callback(struct notifier_block *nfb,
>
> case CPU_DOWN_PREPARE:
> case CPU_DOWN_PREPARE_FROZEN:
> + case CPU_UP_CANCELED:
> + case CPU_UP_CANCELED_FROZEN:
> if (!pinst_has_cpu(pinst, cpu))
> break;
> mutex_lock(&pinst->lock);
> @@ -865,22 +869,6 @@ static int padata_cpu_callback(struct notifier_block *nfb,
> if (err)
> return notifier_from_errno(err);
> break;
> -
> - case CPU_UP_CANCELED:
> - case CPU_UP_CANCELED_FROZEN:
> - if (!pinst_has_cpu(pinst, cpu))
> - break;
> - mutex_lock(&pinst->lock);
> - __padata_remove_cpu(pinst, cpu);
> - mutex_unlock(&pinst->lock);
> -
> - case CPU_DOWN_FAILED:
> - case CPU_DOWN_FAILED_FROZEN:
> - if (!pinst_has_cpu(pinst, cpu))
> - break;
> - mutex_lock(&pinst->lock);
> - __padata_add_cpu(pinst, cpu);
> - mutex_unlock(&pinst->lock);
> }
>
> return NOTIFY_OK;
>


--
Chen Gang

2013-08-23 10:44:53

by Steffen Klassert

[permalink] [raw]
Subject: Re: [PATCH v2] kernel/padata.c: share code between CPU_ONLINE and CPU_DOWN_FAILED, same to CPU_DOWN_PREPARE and CPU_UP_CANCELED

On Thu, Aug 22, 2013 at 02:43:37PM +0800, Chen Gang wrote:
> Share code between CPU_ONLINE and CPU_DOWN_FAILED, same to
> CPU_DOWN_PREPARE and CPU_UP_CANCELED.
>
> It will fix 2 bugs:
>
> "not check the return value of __padata_remove_cpu() and __padata_add_cpu()".
> "need add 'break' between CPU_UP_CANCELED and CPU_DOWN_FAILED".
>
>
> Signed-off-by: Chen Gang <[email protected]>

This looks ok to me, Herbert can you take this one?

Acked-by: Steffen Klassert <[email protected]>

2013-08-23 10:47:42

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v2] kernel/padata.c: share code between CPU_ONLINE and CPU_DOWN_FAILED, same to CPU_DOWN_PREPARE and CPU_UP_CANCELED

On Fri, Aug 23, 2013 at 12:44:48PM +0200, Steffen Klassert wrote:
> On Thu, Aug 22, 2013 at 02:43:37PM +0800, Chen Gang wrote:
> > Share code between CPU_ONLINE and CPU_DOWN_FAILED, same to
> > CPU_DOWN_PREPARE and CPU_UP_CANCELED.
> >
> > It will fix 2 bugs:
> >
> > "not check the return value of __padata_remove_cpu() and __padata_add_cpu()".
> > "need add 'break' between CPU_UP_CANCELED and CPU_DOWN_FAILED".
> >
> >
> > Signed-off-by: Chen Gang <[email protected]>
>
> This looks ok to me, Herbert can you take this one?

Sure.

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2013-08-26 01:12:39

by Chen Gang

[permalink] [raw]
Subject: Re: [PATCH v2] kernel/padata.c: share code between CPU_ONLINE and CPU_DOWN_FAILED, same to CPU_DOWN_PREPARE and CPU_UP_CANCELED

On 08/23/2013 06:47 PM, Herbert Xu wrote:
> On Fri, Aug 23, 2013 at 12:44:48PM +0200, Steffen Klassert wrote:
>> On Thu, Aug 22, 2013 at 02:43:37PM +0800, Chen Gang wrote:
>>> Share code between CPU_ONLINE and CPU_DOWN_FAILED, same to
>>> CPU_DOWN_PREPARE and CPU_UP_CANCELED.
>>>
>>> It will fix 2 bugs:
>>>
>>> "not check the return value of __padata_remove_cpu() and __padata_add_cpu()".
>>> "need add 'break' between CPU_UP_CANCELED and CPU_DOWN_FAILED".
>>>
>>>
>>> Signed-off-by: Chen Gang <[email protected]>
>>
>> This looks ok to me, Herbert can you take this one?
>
> Sure.
>

Thank you all.

> Thanks,
>

Thanks.
--
Chen Gang

2013-08-29 04:43:38

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v2] kernel/padata.c: share code between CPU_ONLINE and CPU_DOWN_FAILED, same to CPU_DOWN_PREPARE and CPU_UP_CANCELED

On Fri, Aug 23, 2013 at 12:44:48PM +0200, Steffen Klassert wrote:
> On Thu, Aug 22, 2013 at 02:43:37PM +0800, Chen Gang wrote:
> > Share code between CPU_ONLINE and CPU_DOWN_FAILED, same to
> > CPU_DOWN_PREPARE and CPU_UP_CANCELED.
> >
> > It will fix 2 bugs:
> >
> > "not check the return value of __padata_remove_cpu() and __padata_add_cpu()".
> > "need add 'break' between CPU_UP_CANCELED and CPU_DOWN_FAILED".
> >
> >
> > Signed-off-by: Chen Gang <[email protected]>
>
> This looks ok to me, Herbert can you take this one?
>
> Acked-by: Steffen Klassert <[email protected]>

Patch applied. Thanks!
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2013-08-29 05:23:56

by Chen Gang

[permalink] [raw]
Subject: Re: [PATCH v2] kernel/padata.c: share code between CPU_ONLINE and CPU_DOWN_FAILED, same to CPU_DOWN_PREPARE and CPU_UP_CANCELED

On 08/29/2013 12:42 PM, Herbert Xu wrote:
> On Fri, Aug 23, 2013 at 12:44:48PM +0200, Steffen Klassert wrote:
>> On Thu, Aug 22, 2013 at 02:43:37PM +0800, Chen Gang wrote:
>>> Share code between CPU_ONLINE and CPU_DOWN_FAILED, same to
>>> CPU_DOWN_PREPARE and CPU_UP_CANCELED.
>>>
>>> It will fix 2 bugs:
>>>
>>> "not check the return value of __padata_remove_cpu() and __padata_add_cpu()".
>>> "need add 'break' between CPU_UP_CANCELED and CPU_DOWN_FAILED".
>>>
>>>
>>> Signed-off-by: Chen Gang <[email protected]>
>>
>> This looks ok to me, Herbert can you take this one?
>>
>> Acked-by: Steffen Klassert <[email protected]>
>
> Patch applied. Thanks!
>

Thank you too.

--
Chen Gang