From patchwork Mon Dec 4 22:20:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10091673 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 A8B346035E for ; Mon, 4 Dec 2017 22:22:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A8D729336 for ; Mon, 4 Dec 2017 22:22:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F7E92933B; Mon, 4 Dec 2017 22:22:41 +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 0F05429336 for ; Mon, 4 Dec 2017 22:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751862AbdLDWWj (ORCPT ); Mon, 4 Dec 2017 17:22:39 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36078 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751934AbdLDWWh (ORCPT ); Mon, 4 Dec 2017 17:22:37 -0500 Received: by mail-lf0-f68.google.com with SMTP id f20so20999065lfe.3 for ; Mon, 04 Dec 2017 14:22:37 -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=154UfNbz4dQmS5PP1DvXVSOTJwapP/SVIwa5hfpNWFI=; b=di1pG5G/mM/89/Q1/aOrFcS1MqpMBQgpzX6yhAN/NFD2dNmXs4xlVdz4RIvZh9rsbR ZGERc4s/O0aYWAED/lFgmSk8C7/TfZWxLWjyq4A5Rj+IiXgrukTzAAPzRBOHPU0rVGsj bKP8rhctL0ZYoA/zL68+cVa0CU3eI7+I9y6YQ= 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=154UfNbz4dQmS5PP1DvXVSOTJwapP/SVIwa5hfpNWFI=; b=hCPIIxL0ZVNipJ/7m4PxEQIMb41m6TRkfUhwMSzvGt7J/I15wVAxOQ3Hwa5AviZHid OqQ8w8Rtx0URDR4WNPUuQp+rOIUDuKZKZ6mjj4taFaAh5lcEW2PNOuheuwK9f5UDRtrM MC77GF9r3l4TPelPD7hkCB9At1l8VHqqLS/GDXhm9mm6WFEgZQK4OPnCN4UZp/e1aYj4 VNurKA3zdntFExDiRANXSQc4leC6M6jEINhl2iopz3VvS+6sKbN8VcBhzKXnEJbNV15I nUpxcX+hBEO9nFaLV2GoIC7GFR4vn0RFcA//OXCbuG0FOZXdajzbMWVIz8S02kn35fJV CxxA== X-Gm-Message-State: AJaThX5xRhl1oAqS1Rf3DVMTbkQ5DHCIlpTmjqjyWxruNBsk5RM1y+/2 1N6UHrTJvNJtsNA3V9DJG/svXe4rfpg= X-Google-Smtp-Source: AGs4zMYjJ6MTpZBrzWSCt+3yTh3OzYt693Z1GnQ4S3KoRWvxLyEdPd84YjaIPNOqLOVVg4PG5uKRBA== X-Received: by 10.25.81.65 with SMTP id f62mr7886801lfb.148.1512426156562; Mon, 04 Dec 2017 14:22:36 -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 h28sm2997315ljb.30.2017.12.04.14.22.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Dec 2017 14:22:35 -0800 (PST) From: Linus Walleij To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Linus Walleij Subject: [PATCH] hwmon: Deal with errors from the thermal subsystem Date: Mon, 4 Dec 2017 23:20:29 +0100 Message-Id: <20171204222029.11956-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 --- drivers/hwmon/hwmon.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index c9790e2c3440..6d1cb6b47490 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,10 @@ 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 (IS_ERR(tzd)) + return PTR_ERR(tzd); return 0; } @@ -621,14 +624,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: