Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp496669ybl; Tue, 28 Jan 2020 06:52:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxYbaZiIzpjd+S6ps+VK9Yh2Z12HvBON8B3PolyExvvhaETLj20O+fpwzl9hldkkMsVBKfn X-Received: by 2002:aca:ed81:: with SMTP id l123mr3099948oih.129.1580223168360; Tue, 28 Jan 2020 06:52:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580223168; cv=none; d=google.com; s=arc-20160816; b=cedXPxDnQoKIaR0bB8SDeOOfBgITzcI1y1xAtphwTvrMViRS8JE5j/7eK0YKbdPYqO LvTMOZrdMuIbyutgmoGF48fCJ+0hGcpM69jnBxPktDltgkRQtIJc5VersJVRE3SH3wVh FASHsWlp84K/iQanm8SuArkj8gIe60bk3A6z4jQ+ginpW49HTgkyy0nfttCFK3oTdWnt k/A13Mj2C3G0Dy02O3WnK7io9xMJJoUGjoEhFajo7DwJUzjQTyp3VvMFK0vz+BEJ9nd7 LJIXA3vEzoy/20YOiQzG+jS8b4Ay4LfRkr7pccxTfGlt+OPxbBJ7zWXqS2Yg6Kdx/LMr JbXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xr4sy0DUx4l92/fWtDZD7F+nTo9gTtme9YZQISgApLI=; b=UFtzrluGeaBqXtckwBHclWErc4MZd40Om8EDXPPsSTMZwJdt7pllWlTW8bLrfLcrnA aTeNytw3yr3vVoP3YAOJx3C+tgaXS6zyx80hPa3vIniK2ZyWchRLolXaGOsXHkdpMu8+ 0pq12OxfQaepBr1lm2nNSt19mdH/UvvzfbyZ9IflN8VJAKodOmJxYLO2V4VU/ghJXnRh 9kUcZmUHoY3awFNjk0jMBaEkIih/HEq1OsItzbxXmJi74GVsQdu7+s1AD9xOx7j28phU JrEAEwLhveV2TwuIeiVK0HGckC1Jvt85d+KDoHImSjhzV90HIy/+u2P5SM7LDgh5xTL9 NaNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J3eXcurj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v14si8913118oth.181.2020.01.28.06.52.36; Tue, 28 Jan 2020 06:52:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J3eXcurj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726486AbgA1Oun (ORCPT + 99 others); Tue, 28 Jan 2020 09:50:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:43970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbgA1N6v (ORCPT ); Tue, 28 Jan 2020 08:58:51 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A61AD2173E; Tue, 28 Jan 2020 13:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580219931; bh=SFR2d31pGBWYC5sDAQbVOFXbyWhqJ2hBoTVTx7MidMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J3eXcurjfp7sYcj0xwaUDV5P4Ey4Zk4cHVTjwYEB5/q/4rsmiNNlw5/T20bet2FWw mRMnNZ8t9p1fb25dUXz/BxKulI0sqOlzjfkwLnB6KGilJSG3rv9SKrY/zPEy0AC7TO wBDLjVe8UzPUH9v1u2YT5ZCbhgC2MV0ZFzbfGXy0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Walleij , Guenter Roeck Subject: [PATCH 4.14 18/46] hwmon: Deal with errors from the thermal subsystem Date: Tue, 28 Jan 2020 14:57:52 +0100 Message-Id: <20200128135752.300771628@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135749.822297911@linuxfoundation.org> References: <20200128135749.822297911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Walleij commit 47c332deb8e89f6c59b0bb2615945c6e7fad1a60 upstream. 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. Fixes: d560168b5d0f ("hwmon: (core) New hwmon registration API") Signed-off-by: Linus Walleij Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/hwmon.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -143,6 +143,7 @@ static int hwmon_thermal_add_sensor(stru 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(stru 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 *d 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: