From patchwork Thu Nov 10 15:25:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 18166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp211992wru; Thu, 10 Nov 2022 07:28:52 -0800 (PST) X-Google-Smtp-Source: AMsMyM7BFVigR7ueR8g3HBzcWwlKbjflforaL1L67nNk6uEpiFSdKFWJW6WV7/1XDWZmZy9/xvlY X-Received: by 2002:a05:6402:40d0:b0:462:7b99:d424 with SMTP id z16-20020a05640240d000b004627b99d424mr62747024edb.62.1668094131624; Thu, 10 Nov 2022 07:28:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668094131; cv=none; d=google.com; s=arc-20160816; b=FY/gVyPkHXDvG+Yr5uTS42J1AyHhjVHj2iqNaAUuIjTiYfO68f2W7l53ARYQfb9npw rJxkbvSfxQeYE9mYmq69Op3itnRMN4GwciRRvLAMnUvE8fq2MG9Lgf98sRauCLRXVavX dAbfvHRGeTGmeHNmCWxjZH8GCq3KVbZnbdgG8+zUm8syg2ttHrnCK8oSeC+qCt3PVCYp mozaBjhyb/JQssNxChM4gw2EGE/nlzJ/eVwLxxzBVcrgYzeF6hk0nIlZuvw/VEaVvY/4 cA6hmoQ32UytLUBlL4P51qFLosR9RkaGWh7nldsAZVUDZ20A0chnARRLNM30hgCb7gId lgrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=BP0JS35IGfSl0FVl/KECGclfAmAetA4hJ3SBTMSOqEY=; b=ogIKUrhhNBQLGMZH/3DBpi2Wsvp4n/58piWnku9w+kvNrvQAePVNzMpB5kAWIT9pey 2TVCluem/1kfPTuB98N09ZSWSs4xs8nWCNu37hEwDQmo0T/jFsfRZbheVGiGbZR2II07 5dVlNCG+wkwx2MKhXOV6rDNbOtv+zg+kMO8vRddD0JELUq1Q5diJCMDpXduGiJUYzqdB NtIkwajrUfI08wFpiethlFYKYw179PEiqh9QWk9SZSS816dhR3q4ardtP1kA/Nerjb9G 2cSYmOPfMMUEzuOWTgoyael9IlWK17exgUcAmfY3pU2x7hVfEfIimOM+hqAgxlDFggN2 WP+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="K8P/qg9j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a056402520400b004523826ed6dsi21390631edd.554.2022.11.10.07.28.26; Thu, 10 Nov 2022 07:28:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="K8P/qg9j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbiKJPZx (ORCPT + 99 others); Thu, 10 Nov 2022 10:25:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbiKJPZg (ORCPT ); Thu, 10 Nov 2022 10:25:36 -0500 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18A863F047; Thu, 10 Nov 2022 07:25:19 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id v81so2138495oie.5; Thu, 10 Nov 2022 07:25:19 -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=BP0JS35IGfSl0FVl/KECGclfAmAetA4hJ3SBTMSOqEY=; b=K8P/qg9jSQx3oCgYAtr8dQEh/PdPjWLXH7I9sz7vHYpsmm6tPvZjZ2GZodU1BXAga/ iPWHc8tCLgQpFL9Rq34MMot+WoWC3whB/GF3/bzQWpih5sjjSpD90h7SAplIdkKD50L9 Lm8EzhYJ8djTH5zjsmGaU5TsUajgq0AeNeoT9kkrfFyLi/NcW9kmCRBVMlfpibdTdEyW ZA/2lA5ebJ7pyOjrVbmTsGIVLJ18E6i/KnwudIuE2jbmMZb5PE7pIpK+KCTpDYdlsBr6 ljlbKpenBWOVclXzyovtd3/cB4NDEH7/e+2akCzXAmnKNLEQWxM6yxrki73TZbBlK2YM kDWw== 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=BP0JS35IGfSl0FVl/KECGclfAmAetA4hJ3SBTMSOqEY=; b=2bfCWdYV9/2726VoiciW1ddSH1TUEvJwXuCMFNVVuHlMWrmt3/T+jIxHr56lXNTAmW kLKUIe78+Qaidl241avJUz5BVppIk/ecE1DVFmBdJAVmfFw7Ri9Z2zGkkvE+fBfbvEBI uVBlfPhBiMNxBcAak4x7n5hQMXDiYkijjK+EgYIwFctqWw5o1aPqDoo/TwN6UIEVsfd+ A/DUb0xWrSt1OkEaMG6Yiab8WWH1e495gzzXTeFEi9OdMxri96DQKSk1jhkcXGFhnyEZ 7U+BqXH2NmqzQ594crXRnxUy/Sge15Nn2TyZin+1v1LVDSQWOY4U3e+ua0/T5sedMMXL cHgw== X-Gm-Message-State: ACrzQf1FXsnS3oNTmxNYniB1Dg6l4JS+Ycd8LLHLndxY4bSzPR0s8DOU 5at+FRpVrErC11TbM560wwM= X-Received: by 2002:a54:410e:0:b0:35a:5a4b:a836 with SMTP id l14-20020a54410e000000b0035a5a4ba836mr17076466oic.95.1668093918430; Thu, 10 Nov 2022 07:25:18 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id x34-20020a056870b42200b0013d7fffbc3csm7651353oap.58.2022.11.10.07.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 07:25:18 -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 9/9] thermal/core: Protect thermal device operations against thermal device removal Date: Thu, 10 Nov 2022 07:25:00 -0800 Message-Id: <20221110152500.3032655-10-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 X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749123471860517632?= X-GMAIL-MSGID: =?utf-8?q?1749123471860517632?= Thermal device operations may be called after thermal zone device removal. After thermal zone device removal, thermal zone device operations must no longer be called. To prevent such calls from happening, ensure that the thermal device is registered before executing any thermal device operations. Signed-off-by: Guenter Roeck --- v2: Fixed spelling error in description drivers/thermal/thermal_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index b8e3b262b2bd..aa0107f11c98 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -203,6 +203,9 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *tz, mutex_lock(&thermal_governor_lock); mutex_lock(&tz->lock); + if (!device_is_registered(&tz->device)) + goto exit; + gov = __find_governor(strim(policy)); if (!gov) goto exit; @@ -445,6 +448,12 @@ static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, return ret; } + if (!device_is_registered(&tz->device)) { + mutex_unlock(&tz->lock); + + return -ENODEV; + } + if (tz->ops->change_mode) ret = tz->ops->change_mode(tz, mode); @@ -486,7 +495,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { mutex_lock(&tz->lock); - __thermal_zone_device_update(tz, event); + if (device_is_registered(&tz->device)) + __thermal_zone_device_update(tz, event); mutex_unlock(&tz->lock); } EXPORT_SYMBOL_GPL(thermal_zone_device_update);