diff mbox

[V2,13/16] cpuidle: free all state kobjects from cpuidle_free_state_kobj()

Message ID 61fdca8bd1502d7319bfaad29583013f0fbec6b4.1380815504.git.viresh.kumar@linaro.org
State New
Headers show

Commit Message

Viresh Kumar Oct. 3, 2013, 3:56 p.m. UTC
Loop for states is currently present on callers side and so is replicated at
several places. It would be better to move that inside cpuidle_free_state_kobj()
instead.

This patch does it.

Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpuidle/sysfs.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

Comments

Viresh Kumar Nov. 20, 2013, 8:03 a.m. UTC | #1
On 3 October 2013 21:26, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> Loop for states is currently present on callers side and so is replicated at
> several places. It would be better to move that inside cpuidle_free_state_kobj()
> instead.
>
> This patch does it.
>
> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/cpuidle/sysfs.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)

Hi Rafael,

You missed applying this one?

> diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
> index e918b6d..ade31a9 100644
> --- a/drivers/cpuidle/sysfs.c
> +++ b/drivers/cpuidle/sysfs.c
> @@ -378,12 +378,17 @@ static struct kobj_type ktype_state_cpuidle = {
>         .release = cpuidle_state_sysfs_release,
>  };
>
> -static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
> +static inline void cpuidle_free_state_kobj(struct cpuidle_device *device,
> +               int count)
>  {
> -       kobject_put(&device->kobjs[i]->kobj);
> -       wait_for_completion(&device->kobjs[i]->kobj_unregister);
> -       kfree(device->kobjs[i]);
> -       device->kobjs[i] = NULL;
> +       int i;
> +
> +       for (i = 0; i < count; i++) {
> +               kobject_put(&device->kobjs[i]->kobj);
> +               wait_for_completion(&device->kobjs[i]->kobj_unregister);
> +               kfree(device->kobjs[i]);
> +               device->kobjs[i] = NULL;
> +       }
>  }
>
>  /**
> @@ -419,8 +424,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
>         return 0;
>
>  error_state:
> -       for (i = i - 1; i >= 0; i--)
> -               cpuidle_free_state_kobj(device, i);
> +       cpuidle_free_state_kobj(device, i);
>         return ret;
>  }
>
> @@ -430,10 +434,7 @@ error_state:
>   */
>  static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
>  {
> -       int i;
> -
> -       for (i = 0; i < device->state_count; i++)
> -               cpuidle_free_state_kobj(device, i);
> +       cpuidle_free_state_kobj(device, device->state_count);
>  }
>
>  #ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
> --
> 1.7.12.rc2.18.g61b472e
>
Viresh Kumar Nov. 20, 2013, 8:03 a.m. UTC | #2
Fixing Rafael's email id..

On 20 November 2013 13:33, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 3 October 2013 21:26, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>> Loop for states is currently present on callers side and so is replicated at
>> several places. It would be better to move that inside cpuidle_free_state_kobj()
>> instead.
>>
>> This patch does it.
>>
>> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> ---
>>  drivers/cpuidle/sysfs.c | 23 ++++++++++++-----------
>>  1 file changed, 12 insertions(+), 11 deletions(-)
>
> Hi Rafael,
>
> You missed applying this one?
>
>> diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
>> index e918b6d..ade31a9 100644
>> --- a/drivers/cpuidle/sysfs.c
>> +++ b/drivers/cpuidle/sysfs.c
>> @@ -378,12 +378,17 @@ static struct kobj_type ktype_state_cpuidle = {
>>         .release = cpuidle_state_sysfs_release,
>>  };
>>
>> -static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
>> +static inline void cpuidle_free_state_kobj(struct cpuidle_device *device,
>> +               int count)
>>  {
>> -       kobject_put(&device->kobjs[i]->kobj);
>> -       wait_for_completion(&device->kobjs[i]->kobj_unregister);
>> -       kfree(device->kobjs[i]);
>> -       device->kobjs[i] = NULL;
>> +       int i;
>> +
>> +       for (i = 0; i < count; i++) {
>> +               kobject_put(&device->kobjs[i]->kobj);
>> +               wait_for_completion(&device->kobjs[i]->kobj_unregister);
>> +               kfree(device->kobjs[i]);
>> +               device->kobjs[i] = NULL;
>> +       }
>>  }
>>
>>  /**
>> @@ -419,8 +424,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
>>         return 0;
>>
>>  error_state:
>> -       for (i = i - 1; i >= 0; i--)
>> -               cpuidle_free_state_kobj(device, i);
>> +       cpuidle_free_state_kobj(device, i);
>>         return ret;
>>  }
>>
>> @@ -430,10 +434,7 @@ error_state:
>>   */
>>  static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
>>  {
>> -       int i;
>> -
>> -       for (i = 0; i < device->state_count; i++)
>> -               cpuidle_free_state_kobj(device, i);
>> +       cpuidle_free_state_kobj(device, device->state_count);
>>  }
>>
>>  #ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
>> --
>> 1.7.12.rc2.18.g61b472e
>>
Rafael J. Wysocki Nov. 21, 2013, 1:05 a.m. UTC | #3
On Wednesday, November 20, 2013 01:33:53 PM Viresh Kumar wrote:
> Fixing Rafael's email id..
> 
> On 20 November 2013 13:33, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > On 3 October 2013 21:26, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >> Loop for states is currently present on callers side and so is replicated at
> >> several places. It would be better to move that inside cpuidle_free_state_kobj()
> >> instead.
> >>
> >> This patch does it.
> >>
> >> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> >> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> >> ---
> >>  drivers/cpuidle/sysfs.c | 23 ++++++++++++-----------
> >>  1 file changed, 12 insertions(+), 11 deletions(-)
> >
> > Hi Rafael,
> >
> > You missed applying this one?

I might.  Care to resend?

> >> diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
> >> index e918b6d..ade31a9 100644
> >> --- a/drivers/cpuidle/sysfs.c
> >> +++ b/drivers/cpuidle/sysfs.c
> >> @@ -378,12 +378,17 @@ static struct kobj_type ktype_state_cpuidle = {
> >>         .release = cpuidle_state_sysfs_release,
> >>  };
> >>
> >> -static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
> >> +static inline void cpuidle_free_state_kobj(struct cpuidle_device *device,
> >> +               int count)
> >>  {
> >> -       kobject_put(&device->kobjs[i]->kobj);
> >> -       wait_for_completion(&device->kobjs[i]->kobj_unregister);
> >> -       kfree(device->kobjs[i]);
> >> -       device->kobjs[i] = NULL;
> >> +       int i;
> >> +
> >> +       for (i = 0; i < count; i++) {
> >> +               kobject_put(&device->kobjs[i]->kobj);
> >> +               wait_for_completion(&device->kobjs[i]->kobj_unregister);
> >> +               kfree(device->kobjs[i]);
> >> +               device->kobjs[i] = NULL;
> >> +       }
> >>  }
> >>
> >>  /**
> >> @@ -419,8 +424,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
> >>         return 0;
> >>
> >>  error_state:
> >> -       for (i = i - 1; i >= 0; i--)
> >> -               cpuidle_free_state_kobj(device, i);
> >> +       cpuidle_free_state_kobj(device, i);
> >>         return ret;
> >>  }
> >>
> >> @@ -430,10 +434,7 @@ error_state:
> >>   */
> >>  static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
> >>  {
> >> -       int i;
> >> -
> >> -       for (i = 0; i < device->state_count; i++)
> >> -               cpuidle_free_state_kobj(device, i);
> >> +       cpuidle_free_state_kobj(device, device->state_count);
> >>  }
> >>
> >>  #ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
> >> --
> >> 1.7.12.rc2.18.g61b472e
> >>
Viresh Kumar Nov. 21, 2013, 3:24 a.m. UTC | #4
On 21 November 2013 06:35, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Wednesday, November 20, 2013 01:33:53 PM Viresh Kumar wrote:
>> Fixing Rafael's email id..
>>
>> On 20 November 2013 13:33, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>> > On 3 October 2013 21:26, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>> >> Loop for states is currently present on callers side and so is replicated at
>> >> several places. It would be better to move that inside cpuidle_free_state_kobj()
>> >> instead.
>> >>
>> >> This patch does it.
>> >>
>> >> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>> >> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> >> ---
>> >>  drivers/cpuidle/sysfs.c | 23 ++++++++++++-----------
>> >>  1 file changed, 12 insertions(+), 11 deletions(-)
>> >
>> > Hi Rafael,
>> >
>> > You missed applying this one?
>
> I might.  Care to resend?

Sent..
diff mbox

Patch

diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index e918b6d..ade31a9 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -378,12 +378,17 @@  static struct kobj_type ktype_state_cpuidle = {
 	.release = cpuidle_state_sysfs_release,
 };
 
-static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device,
+		int count)
 {
-	kobject_put(&device->kobjs[i]->kobj);
-	wait_for_completion(&device->kobjs[i]->kobj_unregister);
-	kfree(device->kobjs[i]);
-	device->kobjs[i] = NULL;
+	int i;
+
+	for (i = 0; i < count; i++) {
+		kobject_put(&device->kobjs[i]->kobj);
+		wait_for_completion(&device->kobjs[i]->kobj_unregister);
+		kfree(device->kobjs[i]);
+		device->kobjs[i] = NULL;
+	}
 }
 
 /**
@@ -419,8 +424,7 @@  static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
 	return 0;
 
 error_state:
-	for (i = i - 1; i >= 0; i--)
-		cpuidle_free_state_kobj(device, i);
+	cpuidle_free_state_kobj(device, i);
 	return ret;
 }
 
@@ -430,10 +434,7 @@  error_state:
  */
 static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
 {
-	int i;
-
-	for (i = 0; i < device->state_count; i++)
-		cpuidle_free_state_kobj(device, i);
+	cpuidle_free_state_kobj(device, device->state_count);
 }
 
 #ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS