From d9bca4358286584cc22f4261ee3a60cad01aa4d4 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 13 Sep 2010 10:11:05 +0000 Subject: x86/hwmon: avoid deadlock on CPU removal in pkgtemp pkgtemp_device_remove(), holding the list protecting mutex, calls pkgtemp_device_add(), which itself wants to acquire the same mutex. Holding the mutex over the entire loop body in pkgtemp_device_remove() isn't really necessary, as long as the loop gets exited after processing the matched CPU. Once exiting the loop after removing an eventual match, there's no need for using the "safe" list iterator anymore. Signed-off-by: Jan Beulich Cc: Fenghua Yu Signed-off-by: Guenter Roeck --- drivers/hwmon/pkgtemp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers/hwmon/pkgtemp.c') diff --git a/drivers/hwmon/pkgtemp.c b/drivers/hwmon/pkgtemp.c index 74157fcda6ed..844957333fe5 100644 --- a/drivers/hwmon/pkgtemp.c +++ b/drivers/hwmon/pkgtemp.c @@ -339,17 +339,18 @@ exit: #ifdef CONFIG_HOTPLUG_CPU static void pkgtemp_device_remove(unsigned int cpu) { - struct pdev_entry *p, *n; + struct pdev_entry *p; unsigned int i; int err; mutex_lock(&pdev_list_mutex); - list_for_each_entry_safe(p, n, &pdev_list, list) { + list_for_each_entry(p, &pdev_list, list) { if (p->cpu != cpu) continue; platform_device_unregister(p->pdev); list_del(&p->list); + mutex_unlock(&pdev_list_mutex); kfree(p); for_each_cpu(i, cpu_core_mask(cpu)) { if (i != cpu) { @@ -358,7 +359,7 @@ static void pkgtemp_device_remove(unsigned int cpu) break; } } - break; + return; } mutex_unlock(&pdev_list_mutex); } -- cgit v1.2.1 From d172132f358552eabd7a7410e478ffeead445243 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 13 Sep 2010 10:14:43 +0000 Subject: x86/hwmon: don't leak device attribute file from pkgtemp_probe() and pkgtemp_remove() While apparently inherited from coretemp source, this particular error handling cleanup and exit path wasn't copied properly (or perhaps got discarded intermediately and not re-added properly later). Signed-off-by: Jan Beulich Cc: Fenghua Yu Signed-off-by: Guenter Roeck (added device file removal in pkgtemp_remove) --- drivers/hwmon/pkgtemp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/hwmon/pkgtemp.c') diff --git a/drivers/hwmon/pkgtemp.c b/drivers/hwmon/pkgtemp.c index 844957333fe5..f7ddee5fe9d5 100644 --- a/drivers/hwmon/pkgtemp.c +++ b/drivers/hwmon/pkgtemp.c @@ -224,7 +224,7 @@ static int __devinit pkgtemp_probe(struct platform_device *pdev) err = sysfs_create_group(&pdev->dev.kobj, &pkgtemp_group); if (err) - goto exit_free; + goto exit_dev; data->hwmon_dev = hwmon_device_register(&pdev->dev); if (IS_ERR(data->hwmon_dev)) { @@ -238,6 +238,8 @@ static int __devinit pkgtemp_probe(struct platform_device *pdev) exit_class: sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group); +exit_dev: + device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); exit_free: kfree(data); exit: @@ -250,6 +252,7 @@ static int __devexit pkgtemp_remove(struct platform_device *pdev) hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group); + device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); platform_set_drvdata(pdev, NULL); kfree(data); return 0; -- cgit v1.2.1 From f6aeccdb96fc0555e939dd507702922f07dcbcbb Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 13 Sep 2010 10:18:54 +0000 Subject: x86/hwmon: fix initialization of pkgtemp Feature availability should also be checked in the hotplug code path. Signed-off-by: Jan Beulich Cc: Fenghua Yu Signed-off-by: Guenter Roeck --- drivers/hwmon/pkgtemp.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers/hwmon/pkgtemp.c') diff --git a/drivers/hwmon/pkgtemp.c b/drivers/hwmon/pkgtemp.c index f7ddee5fe9d5..ab89f23eebdf 100644 --- a/drivers/hwmon/pkgtemp.c +++ b/drivers/hwmon/pkgtemp.c @@ -284,9 +284,10 @@ static int __cpuinit pkgtemp_device_add(unsigned int cpu) int err; struct platform_device *pdev; struct pdev_entry *pdev_entry; -#ifdef CONFIG_SMP struct cpuinfo_x86 *c = &cpu_data(cpu); -#endif + + if (!cpu_has(c, X86_FEATURE_PTS)) + return 0; mutex_lock(&pdev_list_mutex); @@ -403,11 +404,6 @@ static int __init pkgtemp_init(void) goto exit; for_each_online_cpu(i) { - struct cpuinfo_x86 *c = &cpu_data(i); - - if (!cpu_has(c, X86_FEATURE_PTS)) - continue; - err = pkgtemp_device_add(i); if (err) goto exit_devices_unreg; -- cgit v1.2.1 From 0eae7799000cdf0c2ed596c39bfb71030809fc71 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 13 Sep 2010 10:24:47 +0000 Subject: x86/hwmon: pkgtemp has no dependency on PCI Other than coretemp, from which this code was apparently derived, there is no PCI specific code in this driver. Signed-off-by: Jan Beulich Cc: Fenghua Yu Signed-off-by: Guenter Roeck --- drivers/hwmon/pkgtemp.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/hwmon/pkgtemp.c') diff --git a/drivers/hwmon/pkgtemp.c b/drivers/hwmon/pkgtemp.c index ab89f23eebdf..f11903936c8b 100644 --- a/drivers/hwmon/pkgtemp.c +++ b/drivers/hwmon/pkgtemp.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include -- cgit v1.2.1