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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 22 Sep 2013 06:51:09 +0530
From:	Viresh Kumar <viresh.kumar@...aro.org>
To:	rjw@...k.pl, daniel.lezcano@...aro.org
Cc:	linaro-kernel@...ts.linaro.org, patches@...aro.org,
	linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
	Viresh Kumar <viresh.kumar@...aro.org>
Subject: [PATCH 17/21] cpuidle: avoid unnecessary kzalloc/free of struct cpuidle_driver_kobj

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>
---
 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;
 
-- 
1.7.12.rc2.18.g61b472e

--
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