x86 therm_throttle: handle sysfs errors
PATCH 1/1 x86 therm_throttle: handle sysfs errors
Signed-off-by Jeff Garzik <[email protected]>
---
Not sure if NOTIFY_BAD is the correct way to handle the error. Please review.
arch/i386/kernel/cpu/mcheck/therm_throt.c | 31 +++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-)
arch/i386/kernel/cpu/mcheck/therm_throt.c +22 -9
@@ -112,15 +112,13 @@ #ifdef CONFIG_SYSFS/* Add/Remove thermal_throttle interface for CPU device */ static __cpuinit int thermal_throttle_add_dev (struct sys_device * sys_dev) { -sysfs_create_group (&sys_dev->kobj, &thermal_throttle_attr_group); -return 0 ; +return sysfs_create_group (&sys_dev->kobj, &thermal_throttle_attr_group); }#ifdef CONFIG_HOTPLUG_CPU -static __cpuinit int thermal_throttle_remove_dev (struct sys_device * sys_dev) +static __cpuinit void thermal_throttle_remove_dev (struct sys_device * sys_dev) {sysfs_remove_group (&sys_dev->kobj, &thermal_throttle_attr_group); -return 0 ; }/* Mutex protecting device creation against CPU hotplug */
@@ -133,19 +131,21 @@ static __cpuinit int thermal_throttle_cp {unsigned int cpu = (unsigned long )hcpu;struct sys_device *sys_dev; +int rc =0 ; sys_dev =get_cpu_sysdev (cpu);mutex_lock (&therm_cpu_lock);switch (action) {case CPU_ONLINE : -thermal_throttle_add_dev (sys_dev); + rc =thermal_throttle_add_dev (sys_dev);break ;case CPU_DEAD :thermal_throttle_remove_dev (sys_dev);break ; }mutex_unlock (&therm_cpu_lock); -return NOTIFY_OK ; + +return rc ?NOTIFY_BAD :NOTIFY_OK ; } static struct notifier_block thermal_throttle_cpu_notifier =
@@ -156,7 +156,8 @@ #endif /* CONFIG_HOTPLUG_CPU */static __init int thermal_throttle_init_device (void ) { -unsigned int cpu =0 ; +unsigned int cpu =0 , cpu_err; +int err =0 ;if (!atomic_read (&therm_throt_en))return 0 ;
@@ -167,13 +168,25 @@ #ifdef CONFIG_HOTPLUG_CPUmutex_lock (&therm_cpu_lock);#endif /* connect live CPUs to sysfs */ -for_each_online_cpu (cpu) -thermal_throttle_add_dev (get_cpu_sysdev (cpu)); +for_each_online_cpu (cpu) { +if (!err) + err =thermal_throttle_add_dev (get_cpu_sysdev (cpu)); + } +if (err) + goto err_out; +#ifdef CONFIG_HOTPLUG_CPU mutex_unlock (&therm_cpu_lock);#endif return 0 ; + +err_out: +for_each_online_cpu (cpu_err) { +if (cpu_err < cpu) +thermal_throttle_remove_dev (get_cpu_sysdev (cpu_err)); + } +return err; }device_initcall (thermal_throttle_init_device);
Quoted 7 lines · Jeff Garzik
Signed-off-by Jeff Garzik <[email protected]>---
Not sure if
NOTIFY_BADis the correct way to handle the error. Please review.
Best you cc the patch author.
(full quote)
-Andi
Quoted 89 lines
arch/i386/kernel/cpu/mcheck/therm_throt.c | 31 +++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-)arch/i386/kernel/cpu/mcheck/therm_throt.c +22
-9@@ -112,15 +112,13 @@ #ifdef CONFIG_SYSFS/* Add/Remove thermal_throttle interface for CPU device */ [email protected] __cpuinit int thermal_throttle_add_dev(struct sys_device * sys_dev) { -sysfs_create_group (&sys_dev->kobj, &thermal_throttle_attr_group); -return 0 ; +return sysfs_create_group (&sys_dev->kobj, &thermal_throttle_attr_group); }#ifdef CONFIG_HOTPLUG_CPU -static __cpuinit int thermal_throttle_remove_dev (struct sys_device * sys_dev) +static __cpuinit void thermal_throttle_remove_dev (struct sys_device * sys_dev) {sysfs_remove_group (&sys_dev->kobj, &thermal_throttle_attr_group); -return 0 ; }/* Mutex protecting device creation against CPU hotplug */ @@ -133,19 +131,21 @@ static __cpuinit int thermal_throttle_cp {unsigned int cpu = (unsigned long )hcpu;struct sys_device *sys_dev; +int rc =0 ; sys_dev =get_cpu_sysdev (cpu);mutex_lock (&therm_cpu_lock);switch (action) {case CPU_ONLINE : -thermal_throttle_add_dev (sys_dev); + rc =thermal_throttle_add_dev (sys_dev);break ;case CPU_DEAD :thermal_throttle_remove_dev (sys_dev);break ; }mutex_unlock (&therm_cpu_lock); -return NOTIFY_OK ; + +return rc ?NOTIFY_BAD :NOTIFY_OK ; } static struct notifier_block thermal_throttle_cpu_notifier =@@ -156,7 +156,8 @@ #endif /* CONFIG_HOTPLUG_CPU */static __init int thermal_throttle_init_device (void ) { -unsigned int cpu =0 ; +unsigned int cpu =0 , cpu_err; +int err =0 ;if (!atomic_read (&therm_throt_en))return 0 ;@@ -167,13 +168,25 @@ #ifdef CONFIG_HOTPLUG_CPUmutex_lock (&therm_cpu_lock);#endif /* connect live CPUs to sysfs */ -for_each_online_cpu (cpu) -thermal_throttle_add_dev (get_cpu_sysdev (cpu)); +for_each_online_cpu (cpu) { +if (!err) + err =thermal_throttle_add_dev (get_cpu_sysdev (cpu)); + } +if (err) + goto err_out; +#ifdef CONFIG_HOTPLUG_CPU mutex_unlock (&therm_cpu_lock);#endif return 0 ; + +err_out: +for_each_online_cpu (cpu_err) { +if (cpu_err < cpu) +thermal_throttle_remove_dev (get_cpu_sysdev (cpu_err)); + } +return err; }device_initcall (thermal_throttle_init_device);