From patchwork Tue Nov 22 17:42:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 9441729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C102860237 for ; Tue, 22 Nov 2016 17:44:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7BDF1FF0B for ; Tue, 22 Nov 2016 17:44:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC43128593; Tue, 22 Nov 2016 17:44:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39B311FF0B for ; Tue, 22 Nov 2016 17:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755820AbcKVRow (ORCPT ); Tue, 22 Nov 2016 12:44:52 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:60370 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755568AbcKVRov (ORCPT ); Tue, 22 Nov 2016 12:44:51 -0500 Received: from localhost ([127.0.0.1] helo=[127.0.1.1]) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1c9F53-0000Ft-J9; Tue, 22 Nov 2016 18:42:05 +0100 Message-Id: <20161122173731.839189942@linutronix.de> User-Agent: quilt/0.63-1 Date: Tue, 22 Nov 2016 17:42:05 -0000 From: Thomas Gleixner To: LKML Cc: Fenghua Yu , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, Sebastian Siewior , Peter Zijlstra , x86@kernel.org Subject: [patch 5/6] hwmon/coretemp: Use proper error codes in cpu online callback References: <20161122173622.771252945@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline; filename=hwmon-coretemp--Use-proper-error-codes-in-cpu-online-callback.patch Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The cpu online callback returns success unconditionally even when the device has no support, micro code mismatches or device allocation fails. Only if CPU_HOTPLUG is disabled, the init function checks whether the device list is empty and removes the driver. This does not make sense. If CPU HOTPLUG is enabled then there is no point to keep the driver around when it failed to initialize on the already online cpus. The chance that not yet online CPUs will provide a functional interface later is very close to zero. Add proper error return codes, so the setup of the cpu hotplug states fails when the device cannot be initialized and remove all the magic cruft. Signed-off-by: Thomas Gleixner --- drivers/hwmon/coretemp.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -662,12 +662,12 @@ static int coretemp_cpu_online(unsigned * without thermal sensors will be filtered out. */ if (!cpu_has(c, X86_FEATURE_DTHERM)) - return 0; + return -ENODEV; if (!pdev) { /* Check the microcode version of the CPU */ if (chk_ucode_version(cpu)) - return 0; + return -EINVAL; /* * Alright, we have DTS support. @@ -677,7 +677,7 @@ static int coretemp_cpu_online(unsigned */ err = coretemp_device_add(cpu); if (err) - return 0; + return err; pdev = coretemp_get_pdev(cpu); /* @@ -782,28 +782,14 @@ static int __init coretemp_init(void) if (err) return err; - get_online_cpus(); err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online", coretemp_cpu_online, coretemp_cpu_offline); if (err < 0) - goto exit_driver_unreg; + goto outdrv; coretemp_hp_online = err; - -#ifndef CONFIG_HOTPLUG_CPU - if (list_empty(&pdev_list)) { - err = -ENODEV; - goto exit_hp_unreg; - } -#endif - put_online_cpus(); return 0; -#ifndef CONFIG_HOTPLUG_CPU -exit_hp_unreg: - cpuhp_remove_state(coretemp_hp_online); - put_online_cpus(); -#endif -exit_driver_unreg: +outdrv: platform_driver_unregister(&coretemp_driver); return err; }