Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753354Ab3IVBXS (ORCPT ); Sat, 21 Sep 2013 21:23:18 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:40492 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753304Ab3IVBXN (ORCPT ); Sat, 21 Sep 2013 21:23:13 -0400 From: Viresh Kumar To: rjw@sisk.pl, daniel.lezcano@linaro.org Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH 17/21] cpuidle: avoid unnecessary kzalloc/free of struct cpuidle_driver_kobj Date: Sun, 22 Sep 2013 06:51:09 +0530 Message-Id: X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3682 Lines: 118 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 --- 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/