From patchwork Thu Nov 10 15:24:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 624378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6720C433FE for ; Thu, 10 Nov 2022 15:25:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231414AbiKJPZQ (ORCPT ); Thu, 10 Nov 2022 10:25:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231440AbiKJPZO (ORCPT ); Thu, 10 Nov 2022 10:25:14 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2682D32BB4; Thu, 10 Nov 2022 07:25:14 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id a7-20020a056830008700b0066c82848060so1293505oto.4; Thu, 10 Nov 2022 07:25:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=TQ10nOb48x6GWqAJdDBvsYg0lrgcue29G6thFXet4SM=; b=n2DGCbHt+mR7onXVMjOXSsZgggtd7o3Re8HqCI0ocAutSYfuU2eFDDf8Jai77X/hxn teTHZFGKoRuKrAiSt0NUQembHFQBIwwvamDuu+cz/BmdGeJIckbnb8TA/6DingXhTTlM MhE2MDyqCdFrs4hDOkb28rceWfIbIvjrAkVUO8cVelv6jBI7IodWaYYai4AsD6DgTj6G a3uI5UmjlVdFNOTMf6evSEVYMzj/JVIUhqousDWQgSAyVNjVYH1+ULpMsgv+ypvDYUfs cO015nJazP/FFcsYojL8gECxMXlkrtvrf18vhySVJo08vqHvuLliF0dhS5Vb4M0H+9m3 T9MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TQ10nOb48x6GWqAJdDBvsYg0lrgcue29G6thFXet4SM=; b=UBLqwP49ELiV7gOOrMmno05+OEFEfDEwdrw1m5BisgVAEuLoE/VcrhU9WX8oPjsW0a h7/JUeA+6yWHV4kaiLTjJdcBubfmMa2KI1VQ7pxzdw2cmdbhKkOJtcQO+kk2Ggt/2e/Y gtfWVfb07fxJvrptvUbeT+SsMAToPKxXDkPaj4EszgdqQmOwbqDXsqhcxNhcI/2mcomo Uqu7SnEdItvYEjdqXw2FZy16rbLgTwLIMtFzGWs0uXLIZ5PaTZZjYdZQiDDeso6whO9V Md9V+W9OclafYMi8A2UQOixP05fiXKlfu0ssYJhh48+6y5DGt8krpCQq5uDQ2FN6BYCs LxQA== X-Gm-Message-State: ACrzQf1yJADJ0PS0pIIxKFTS6O/GcK312dhcSKGnpKSdNGtw5HzbyttW t7yBj6RFShK/AqGM1kNI24xAc2+hmM8= X-Google-Smtp-Source: AMsMyM442yTxnWULQ5cboOlghbbZka7nh7aWZUlcO6geeTbFqr8HJBU/EsPbpHQylWpk+QrVCCIWNQ== X-Received: by 2002:a9d:4b19:0:b0:66c:55d2:c58a with SMTP id q25-20020a9d4b19000000b0066c55d2c58amr26740262otf.273.1668093913460; Thu, 10 Nov 2022 07:25:13 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id b20-20020a05687061d400b001324315bb6asm7626122oah.29.2022.11.10.07.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 07:25:13 -0800 (PST) Sender: Guenter Roeck From: Guenter Roeck To: "Rafael J . Wysocki" , Daniel Lezcano Cc: Amit Kucheria , Zhang Rui , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH v2 6/9] thermal/core: Protect hwmon accesses to thermal operations with thermal zone mutex Date: Thu, 10 Nov 2022 07:24:57 -0800 Message-Id: <20221110152500.3032655-7-linux@roeck-us.net> X-Mailer: git-send-email 2.36.2 In-Reply-To: <20221110152500.3032655-1-linux@roeck-us.net> References: <20221110152500.3032655-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In preparation to protecting access to thermal operations against thermal zone device removal, protect hwmon accesses to thermal zone operations with the thermal zone mutex. After acquiring the mutex, ensure that the thermal zone device is registered before proceeding. Signed-off-by: Guenter Roeck --- v2: Simplify error handling to avoid additional goto. Do not use ternary operator in modified code. drivers/thermal/thermal_hwmon.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index f53f4ceb6a5d..c594c42bea6d 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -77,7 +77,15 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf) int temperature; int ret; - ret = tz->ops->get_crit_temp(tz, &temperature); + mutex_lock(&tz->lock); + + if (device_is_registered(&tz->device)) + ret = tz->ops->get_crit_temp(tz, &temperature); + else + ret = -ENODEV; + + mutex_unlock(&tz->lock); + if (ret) return ret;