From patchwork Tue Dec 5 08:36:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10092463 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 DF94460327 for ; Tue, 5 Dec 2017 08:38:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDE2F294F5 for ; Tue, 5 Dec 2017 08:38:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C24A929536; Tue, 5 Dec 2017 08:38:21 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 19D1D294F5 for ; Tue, 5 Dec 2017 08:38:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751269AbdLEIiU (ORCPT ); Tue, 5 Dec 2017 03:38:20 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:36597 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750810AbdLEIiU (ORCPT ); Tue, 5 Dec 2017 03:38:20 -0500 Received: by mail-lf0-f67.google.com with SMTP id f20so22277742lfe.3 for ; Tue, 05 Dec 2017 00:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=tntfJSNcLoVQitkByu98njf6/uiY1ZCGk7i40DbEMA8=; b=U26yD5LYBtJzX6pENOz8x14dEldx9NkGRSaeq3UxUcuZHzxzgaWOZ2EKkSkiDQT8IC aFHdZG/453LLfwca2yflkL9JwiZWmVHKT5u9R39UxAJCBoxDYAXIur+IOVi9PUBu5pYd 73CGCNx+ubPcT0bu/B/Awit15Rt+ni3ogtVqg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tntfJSNcLoVQitkByu98njf6/uiY1ZCGk7i40DbEMA8=; b=dsa0gNBDk5cYb1Q+uF0grn/8KihhC3sd6DP2qjPIT0IuubPb5TUz+1RaNzVun0x+rR 9e2WElelPNCj1/HyzqdPwvKeBcNhD+7q/un2x7X5faea2uRbYsCRsfd/2K2n/N7/f/g8 VcljuTFODq717KgstPsxVM6H+j2Z8pZMawZzkD9ICEyEibgwDuCFxJb/q1O+F+8W1gXp eiamHMfmNwrwlvpL/mUDUaiY8d5Icvs51PnQ4CRhKdC9Ka1UkgcHfTJcjZJ+6FchfkWs eX58It9LSDMyuD4dDgo3bdDWT6Kl5n5tso5UXdxIzV5fdDQfBk4DUSP1cNhi4eH6AKf+ 7+jA== X-Gm-Message-State: AJaThX790yRoZayjZPwilCR7waPsKzWjgnEJ7AuNBaVjHq9ymYl1PTgr fUcrbrQh2TgYEKT38JHrgSHfwg== X-Google-Smtp-Source: AGs4zMYUXQ7g/IZPnWpLY5hlpNEFgwQEDxwWSUyVe8yuIVG2ZdFDdIofEs2D6lGjN/DxF4dgBrU/pw== X-Received: by 10.25.87.147 with SMTP id l141mr9515348lfb.111.1512463098944; Tue, 05 Dec 2017 00:38:18 -0800 (PST) Received: from localhost.localdomain (c-567171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.86]) by smtp.gmail.com with ESMTPSA id y1sm3296289lje.64.2017.12.05.00.38.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Dec 2017 00:38:18 -0800 (PST) From: Linus Walleij To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Linus Walleij Subject: [PATCH v2] hwmon: Deal with errors from the thermal subsystem Date: Tue, 5 Dec 2017 09:36:14 +0100 Message-Id: <20171205083614.32537-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 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 If the thermal subsystem returne -EPROBE_DEFER or any other error when hwmon calls devm_thermal_zone_of_sensor_register(), this is silently ignored. I ran into this with an incorrectly defined thermal zone, making it non-existing and thus this call failed with -EPROBE_DEFER assuming it would appear later. The sensor was still added which is incorrect: sensors must strictly be added after the thermal zones, so deferred probe must be respected. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Explicitly discard -ENODEV as this is OK, forward any other errors. --- drivers/hwmon/hwmon.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index c9790e2c3440..af5123042990 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -143,6 +143,7 @@ static int hwmon_thermal_add_sensor(struct device *dev, struct hwmon_device *hwdev, int index) { struct hwmon_thermal_data *tdata; + struct thermal_zone_device *tzd; tdata = devm_kzalloc(dev, sizeof(*tdata), GFP_KERNEL); if (!tdata) @@ -151,8 +152,14 @@ static int hwmon_thermal_add_sensor(struct device *dev, tdata->hwdev = hwdev; tdata->index = index; - devm_thermal_zone_of_sensor_register(&hwdev->dev, index, tdata, - &hwmon_thermal_ops); + tzd = devm_thermal_zone_of_sensor_register(&hwdev->dev, index, tdata, + &hwmon_thermal_ops); + /* + * If CONFIG_THERMAL_OF is disabled, this returns -ENODEV, + * so ignore that error but forward any other error. + */ + if (IS_ERR(tzd) && (PTR_ERR(tzd) != -ENODEV)) + return PTR_ERR(tzd); return 0; } @@ -621,14 +628,20 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, if (!chip->ops->is_visible(drvdata, hwmon_temp, hwmon_temp_input, j)) continue; - if (info[i]->config[j] & HWMON_T_INPUT) - hwmon_thermal_add_sensor(dev, hwdev, j); + if (info[i]->config[j] & HWMON_T_INPUT) { + err = hwmon_thermal_add_sensor(dev, + hwdev, j); + if (err) + goto free_device; + } } } } return hdev; +free_device: + device_unregister(hdev); free_hwmon: kfree(hwdev); ida_remove: