2011-02-24 06:57:21

by Li Zefan

[permalink] [raw]
Subject: [PATCH] cpuset: Add a missing unlock in cpuset_write_resmask()

Don't forget to release cgroup_mutex if alloc_trial_cpuset() fails.

Signed-off-by: Li Zefan <[email protected]>
---
kernel/cpuset.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 1ca786a..6272503 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1561,8 +1561,10 @@ static int cpuset_write_resmask(struct cgroup *cgrp, struct cftype *cft,
return -ENODEV;

trialcs = alloc_trial_cpuset(cs);
- if (!trialcs)
+ if (!trialcs) {
+ cgroup_unlock();
return -ENOMEM;
+ }

switch (cft->private) {
case FILE_CPULIST:
--
1.7.3.1


2011-02-24 07:06:07

by David Rientjes

[permalink] [raw]
Subject: Re: [PATCH] cpuset: Add a missing unlock in cpuset_write_resmask()

On Thu, 24 Feb 2011, Li Zefan wrote:

> Don't forget to release cgroup_mutex if alloc_trial_cpuset() fails.
>
> Signed-off-by: Li Zefan <[email protected]>

Acked-by: David Rientjes <[email protected]>

2011-02-28 23:56:03

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] cpuset: Add a missing unlock in cpuset_write_resmask()

On Thu, 24 Feb 2011 14:58:58 +0800
Li Zefan <[email protected]> wrote:

> Don't forget to release cgroup_mutex if alloc_trial_cpuset() fails.
>
> Signed-off-by: Li Zefan <[email protected]>
> ---
> kernel/cpuset.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/cpuset.c b/kernel/cpuset.c
> index 1ca786a..6272503 100644
> --- a/kernel/cpuset.c
> +++ b/kernel/cpuset.c
> @@ -1561,8 +1561,10 @@ static int cpuset_write_resmask(struct cgroup *cgrp, struct cftype *cft,
> return -ENODEV;
>
> trialcs = alloc_trial_cpuset(cs);
> - if (!trialcs)
> + if (!trialcs) {
> + cgroup_unlock();
> return -ENOMEM;
> + }
>
> switch (cft->private) {
> case FILE_CPULIST:

It would be better to avoid multiple returns - it leads to more
maintainable code and often shorter code:

--- a/kernel/cpuset.c~cpuset-add-a-missing-unlock-in-cpuset_write_resmask-fix
+++ a/kernel/cpuset.c
@@ -1562,8 +1562,8 @@ static int cpuset_write_resmask(struct c

trialcs = alloc_trial_cpuset(cs);
if (!trialcs) {
- cgroup_unlock();
- return -ENOMEM;
+ retval = -ENOMEM;
+ goto out;
}

switch (cft->private) {
@@ -1579,6 +1579,7 @@ static int cpuset_write_resmask(struct c
}

free_trial_cpuset(trialcs);
+out:
cgroup_unlock();
return retval;
}
_

also, alloc_trial_cpuset() is a fairly slow-looking function.
cpuset_write_resmask() could run alloc_trial_cpuset() before running
cgroup_lock_live_group(), thereby reducing lock hold times.

2011-03-01 01:03:38

by Li Zefan

[permalink] [raw]
Subject: Re: [PATCH] cpuset: Add a missing unlock in cpuset_write_resmask()

>> @@ -1561,8 +1561,10 @@ static int cpuset_write_resmask(struct cgroup *cgrp, struct cftype *cft,
>> return -ENODEV;
>>
>> trialcs = alloc_trial_cpuset(cs);
>> - if (!trialcs)
>> + if (!trialcs) {
>> + cgroup_unlock();
>> return -ENOMEM;
>> + }
>>
>> switch (cft->private) {
>> case FILE_CPULIST:
>
> It would be better to avoid multiple returns - it leads to more
> maintainable code and often shorter code:
>

I have no strong opinion on this.

> --- a/kernel/cpuset.c~cpuset-add-a-missing-unlock-in-cpuset_write_resmask-fix
> +++ a/kernel/cpuset.c
> @@ -1562,8 +1562,8 @@ static int cpuset_write_resmask(struct c
>
> trialcs = alloc_trial_cpuset(cs);
> if (!trialcs) {
> - cgroup_unlock();
> - return -ENOMEM;
> + retval = -ENOMEM;
> + goto out;
> }
>
> switch (cft->private) {
> @@ -1579,6 +1579,7 @@ static int cpuset_write_resmask(struct c
> }
>
> free_trial_cpuset(trialcs);
> +out:
> cgroup_unlock();
> return retval;
> }
> _
>
> also, alloc_trial_cpuset() is a fairly slow-looking function.
> cpuset_write_resmask() could run alloc_trial_cpuset() before running
> cgroup_lock_live_group(), thereby reducing lock hold times.
>

Nope. alloc_trial_cpuset() will read 'cs', so it must be protected by
the lock.