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

+25 -1
+25 -1
drivers/hwmon/coretemp.c
··· 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); ··· 419 415 int err; 420 416 struct platform_device *pdev; 421 417 struct pdev_entry *pdev_entry; 418 + #ifdef CONFIG_SMP 419 + struct cpuinfo_x86 *c = &cpu_data(cpu); 420 + #endif 421 + 422 + mutex_lock(&pdev_list_mutex); 423 + 424 + #ifdef CONFIG_SMP 425 + /* Skip second HT entry of each core */ 426 + list_for_each_entry(pdev_entry, &pdev_list, list) { 427 + if (c->phys_proc_id == pdev_entry->phys_proc_id && 428 + c->cpu_core_id == pdev_entry->cpu_core_id) { 429 + err = 0; /* Not an error */ 430 + goto exit; 431 + } 432 + } 433 + #endif 422 434 423 435 pdev = platform_device_alloc(DRVNAME, cpu); 424 436 if (!pdev) { ··· 458 438 459 439 pdev_entry->pdev = pdev; 460 440 pdev_entry->cpu = cpu; 461 - mutex_lock(&pdev_list_mutex); 441 + #ifdef CONFIG_SMP 442 + pdev_entry->phys_proc_id = c->phys_proc_id; 443 + pdev_entry->cpu_core_id = c->cpu_core_id; 444 + #endif 462 445 list_add_tail(&pdev_entry->list, &pdev_list); 463 446 mutex_unlock(&pdev_list_mutex); 464 447 ··· 472 449 exit_device_put: 473 450 platform_device_put(pdev); 474 451 exit: 452 + mutex_unlock(&pdev_list_mutex); 475 453 return err; 476 454 } 477 455