Commit d883b9f0977269d519469da72faec6a7f72cb489

Authored by Jean Delvare
1 parent 436cad2a41

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

Showing 1 changed file with 25 additions and 1 deletions Side-by-side Diff

drivers/hwmon/coretemp.c
... ... @@ -405,6 +405,10 @@
405 405 struct list_head list;
406 406 struct platform_device *pdev;
407 407 unsigned int cpu;
  408 +#ifdef CONFIG_SMP
  409 + u16 phys_proc_id;
  410 + u16 cpu_core_id;
  411 +#endif
408 412 };
409 413  
410 414 static LIST_HEAD(pdev_list);
411 415  
... ... @@ -415,7 +419,23 @@
415 419 int err;
416 420 struct platform_device *pdev;
417 421 struct pdev_entry *pdev_entry;
  422 +#ifdef CONFIG_SMP
  423 + struct cpuinfo_x86 *c = &cpu_data(cpu);
  424 +#endif
418 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
  438 +
419 439 pdev = platform_device_alloc(DRVNAME, cpu);
420 440 if (!pdev) {
421 441 err = -ENOMEM;
... ... @@ -438,7 +458,10 @@
438 458  
439 459 pdev_entry->pdev = pdev;
440 460 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
442 465 list_add_tail(&pdev_entry->list, &pdev_list);
443 466 mutex_unlock(&pdev_list_mutex);
444 467  
... ... @@ -449,6 +472,7 @@
449 472 exit_device_put:
450 473 platform_device_put(pdev);
451 474 exit:
  475 + mutex_unlock(&pdev_list_mutex);
452 476 return err;
453 477 }
454 478