lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <524360D9.3000706@linaro.org>
Date:	Thu, 26 Sep 2013 00:16:57 +0200
From:	Daniel Lezcano <daniel.lezcano@...aro.org>
To:	Viresh Kumar <viresh.kumar@...aro.org>, rjw@...k.pl
CC:	linaro-kernel@...ts.linaro.org, patches@...aro.org,
	linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 17/21] cpuidle: avoid unnecessary kzalloc/free of struct
 cpuidle_driver_kobj

On 09/22/2013 03:21 AM, Viresh Kumar wrote:
> For CONFIG_CPU_IDLE_MULTIPLE_DRIVERS, struct cpuidle_device always needs to
> allocate struct cpuidle_driver_kobj for all CPUs and so there is no real need to
> have a pointer to it inside struct cpuidle_device.
> 
> This patch makes a object instance of struct cpuidle_driver_kobj inside struct
> cpuidle_device instead of a pointer.
> 
> It also makes kobj_driver dependent on CONFIG_CPU_IDLE_MULTIPLE_DRIVERS.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@...aro.org>

Comment similar to patch 16/21. If you try to offline/online a cpu, that
should lead to a kernel warning.

> ---
>  drivers/cpuidle/sysfs.c | 20 +++-----------------
>  include/linux/cpuidle.h | 11 +++++++++--
>  2 files changed, 12 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
> index db0aac3..3386d64 100644
> --- a/drivers/cpuidle/sysfs.c
> +++ b/drivers/cpuidle/sysfs.c
> @@ -439,12 +439,6 @@ static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
>  	static struct cpuidle_driver_attr attr_driver_##_name = \
>  		__ATTR(_name, 0644, show, NULL)
>  
> -struct cpuidle_driver_kobj {
> -	struct cpuidle_driver *drv;
> -	struct completion kobj_unregister;
> -	struct kobject kobj;
> -};
> -
>  struct cpuidle_driver_attr {
>  	struct attribute attr;
>  	ssize_t (*show)(struct cpuidle_driver *, char *);
> @@ -518,27 +512,20 @@ static struct kobj_type ktype_driver_cpuidle = {
>   */
>  static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
>  {
> -	struct cpuidle_driver_kobj *kdrv;
> +	struct cpuidle_driver_kobj *kdrv = &dev->kobj_driver;
>  	struct cpuidle_device_kobj *kdev = &dev->kobj_dev;
>  	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
>  	int ret;
>  
> -	kdrv = kzalloc(sizeof(*kdrv), GFP_KERNEL);
> -	if (!kdrv)
> -		return -ENOMEM;
> -
>  	kdrv->drv = drv;
>  	init_completion(&kdrv->kobj_unregister);
>  
>  	ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle,
>  				   &kdev->kobj, "driver");
> -	if (ret) {
> -		kfree(kdrv);
> +	if (ret)
>  		return ret;
> -	}
>  
>  	kobject_uevent(&kdrv->kobj, KOBJ_ADD);
> -	dev->kobj_driver = kdrv;
>  
>  	return ret;
>  }
> @@ -549,10 +536,9 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
>   */
>  static void cpuidle_remove_driver_sysfs(struct cpuidle_device *dev)
>  {
> -	struct cpuidle_driver_kobj *kdrv = dev->kobj_driver;
> +	struct cpuidle_driver_kobj *kdrv = &dev->kobj_driver;
>  	kobject_put(&kdrv->kobj);
>  	wait_for_completion(&kdrv->kobj_unregister);
> -	kfree(kdrv);
>  }
>  #else
>  static inline int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
> diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
> index 1fc5cb5..0f0da17 100644
> --- a/include/linux/cpuidle.h
> +++ b/include/linux/cpuidle.h
> @@ -62,7 +62,6 @@ struct cpuidle_state {
>  #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
>  
>  struct cpuidle_state_kobj;
> -struct cpuidle_driver_kobj;
>  
>  struct cpuidle_device_kobj {
>  	struct cpuidle_device *dev;
> @@ -70,6 +69,12 @@ struct cpuidle_device_kobj {
>  	struct kobject kobj;
>  };
>  
> +struct cpuidle_driver_kobj {
> +	struct cpuidle_driver *drv;
> +	struct completion kobj_unregister;
> +	struct kobject kobj;
> +};
> +
>  struct cpuidle_device {
>  	unsigned int		registered:1;
>  	unsigned int		enabled:1;
> @@ -79,7 +84,9 @@ struct cpuidle_device {
>  	int			state_count;
>  	struct cpuidle_state_usage	states_usage[CPUIDLE_STATE_MAX];
>  	struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
> -	struct cpuidle_driver_kobj *kobj_driver;
> +#ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
> +	struct cpuidle_driver_kobj kobj_driver;
> +#endif
>  	struct cpuidle_device_kobj kobj_dev;
>  	struct list_head 	device_list;
>  
> 


-- 
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ