Skip to content

Commit d883b9f

Browse files
author
Jean Delvare
committed
hwmon: (coretemp) Skip duplicate CPU entries
On hyper-threaded CPUs, each core appears twice in the CPU list. Skip the second entry to avoid duplicate sensors. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Huaxu Wan <huaxu.wan@intel.com> Cc: stable@kernel.org
1 parent 436cad2 commit d883b9f

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎drivers/hwmon/coretemp.c‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ struct pdev_entry {
405405
struct list_head list;
406406
struct platform_device *pdev;
407407
unsigned int cpu;
408+
#ifdef CONFIG_SMP
409+
u16 phys_proc_id;
410+
u16 cpu_core_id;
411+
#endif
408412
};
409413

410414
static LIST_HEAD(pdev_list);
@@ -415,6 +419,22 @@ static int __cpuinit coretemp_device_add(unsigned int cpu)
415419
int err;
416420
struct platform_device *pdev;
417421
struct pdev_entry *pdev_entry;
422+
#ifdef CONFIG_SMP
423+
struct cpuinfo_x86 *c = &cpu_data(cpu);
424+
#endif
425+
426+
mutex_lock(&pdev_list_mutex);
427+
428+
#ifdef CONFIG_SMP
429+
/* Skip second HT entry of each core */
430+
list_for_each_entry(pdev_entry, &pdev_list, list) {
431+
if (c->phys_proc_id == pdev_entry->phys_proc_id &&
432+
c->cpu_core_id == pdev_entry->cpu_core_id) {
433+
err = 0; /* Not an error */
434+
goto exit;
435+
}
436+
}
437+
#endif
418438

419439
pdev = platform_device_alloc(DRVNAME, cpu);
420440
if (!pdev) {
@@ -438,7 +458,10 @@ static int __cpuinit coretemp_device_add(unsigned int cpu)
438458

439459
pdev_entry->pdev = pdev;
440460
pdev_entry->cpu = cpu;
441-
mutex_lock(&pdev_list_mutex);
461+
#ifdef CONFIG_SMP
462+
pdev_entry->phys_proc_id = c->phys_proc_id;
463+
pdev_entry->cpu_core_id = c->cpu_core_id;
464+
#endif
442465
list_add_tail(&pdev_entry->list, &pdev_list);
443466
mutex_unlock(&pdev_list_mutex);
444467

@@ -449,6 +472,7 @@ static int __cpuinit coretemp_device_add(unsigned int cpu)
449472
exit_device_put:
450473
platform_device_put(pdev);
451474
exit:
475+
mutex_unlock(&pdev_list_mutex);
452476
return err;
453477
}
454478

0 commit comments

Comments
 (0)