Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp694260rwl; Wed, 29 Mar 2023 07:19:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Zt/ErTW9s//K+eiAnpCccNCn2buxEiSbh7V79Hf7Uq2HLPM3aLna+bMouC/j1uFc+VpHeQ X-Received: by 2002:a17:906:4e0a:b0:931:829c:9d58 with SMTP id z10-20020a1709064e0a00b00931829c9d58mr20286869eju.23.1680099592328; Wed, 29 Mar 2023 07:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099592; cv=none; d=google.com; s=arc-20160816; b=yebO1YPRRs4E2p/s1rWW7kDE9rxsKppBZbDY0qj7sl9AA/+6DaZRjvffSw05QqNbUm iJf+cSLXmkjXSQPvc8qsDrbwuIBYKnPOa229NsFuanIZaqBjTwhLe9Q8Cm6kcmf92ehT FN8p/VPz9BriAAfoY46AJjzBxVfZn2obRlh/59xcnu4GRr6/LzW1xzEQg9MmtvJF+OgA EXWYFjT910FzBzwgyd+phhuJJqUJnF5ZTh0XG+YKpnexj93NnHKEu03RforXCR3isTr5 nofXMuk5TsQGE3Mv+wGgxc+Ty7AeHyzSRG2xk9c7YGtWjeB/q1t8Rs1QdOq1jAsXYaDF 0K5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=kkjlmmdc6+r7J1KgH/df1iRCkHOUNpvDCHr74dZ5Ttk=; b=LsD0nH396pGOLHytRAhiPz4VjPX5Fluf2HStlQbWyDQ/XQEt0uguNadcUp2ew7iNfj P6b0zrHMxnkDTQB3aCELBfGKKyJ6o0WZeFdHR3fXgg5C/Pfn6e3zZEkAuqZf+16hoPbw OaPQWYpOCwa8vJ4gqbfXdhlFOZdeUbbclcg+p8Kg6HOign0FdbC5FSl/zqWfANoFP64N FNKIBX9TlEoafAQMDYDvfC4OoG2lF3X7sBdJTWgxu81buHrI0ZZTktJc3ee3O9+CGUJt GWNFwAwmBt1h3vLrWUmwKthb8rd5LnzFk/pteT0UoDamAtx8IDKxtOzFZsl9+tF4bQsN yw7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hciMjcGJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a1709060bca00b009302e1c267asi28063784ejg.724.2023.03.29.07.19.26; Wed, 29 Mar 2023 07:19:52 -0700 (PDT) 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=@linaro.org header.s=google header.b=hciMjcGJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbjC2OSA (ORCPT + 99 others); Wed, 29 Mar 2023 10:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbjC2OQz (ORCPT ); Wed, 29 Mar 2023 10:16:55 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18F455B9F for ; Wed, 29 Mar 2023 07:16:05 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id l12so15871740wrm.10 for ; Wed, 29 Mar 2023 07:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680099363; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kkjlmmdc6+r7J1KgH/df1iRCkHOUNpvDCHr74dZ5Ttk=; b=hciMjcGJzvZUruUgDjUU1RMvOaqnB0d2RGwL16SljLlZzKv2NDMDVlSnI+DEcOv1if XQ1VEK/Ov7e8bcm3ETZLSNaz/ASh1RwapBpvR3oVVdbHAWaMAM7gKYWZUKLPr0aJT3TH AD7or7awvUreM76if5/PI6QdI8cXx2qKtJ9VUalPb4KPpE+0GEzYhQNLL7w7hmUOPfOF WzAH/cyl1aXxHEEsAYMEXgjgdrGCE6c8fvOo6FwDYIvzlqIum0yi3tZuW4AmdxoRTXpx SJIneEGJ0N3oGSEFcBfQrchbuXAiYkKgs/hMp7ZQsM9SpzaTVZWTgFxafX0M4HyVAnZ/ /QUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680099363; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kkjlmmdc6+r7J1KgH/df1iRCkHOUNpvDCHr74dZ5Ttk=; b=3f0k33wq4n8t3elFLNFA26NHy9hdASQN7BmAPQ2ZJxl2lWXWUJxZ2FmmhvmrX4P4a2 8Mcv5YxtXh2gQVin9P0znK9Xu83fm1uyOdLNLE5xImpihmIVvgHmt2byfn0FXpz/BEvH YFb5O5IlarlGzS9PU4VAv/YsRjqXRwOOHE3BhGoEbNWFyOyZ8jtJGWHuuJx6F5bDyMDk 0j4xqMeJCRZ1qkFa4/NTidzuczXLOx7DWnZXjrldaQXM5NL0NQbZyqb45eOHynjWlN2D CtvkQOWWe08VhUhInlOzJ2rEuFVCpmRSDT44RGRX+rAwLpEe+TcBblWeizYHUlX4DxJ/ Imyw== X-Gm-Message-State: AAQBX9c2m+jLYUTU4VGHyjrlUiFC00Viogo+/Li/NXU7kwW3gAJUfJBy gQ7y8wtaDRaxYUyD7QDN7wTlNUcrRTXoO67Z/yo= X-Received: by 2002:adf:eed1:0:b0:2d8:ce83:5de0 with SMTP id a17-20020adfeed1000000b002d8ce835de0mr16376520wrp.48.1680099363011; Wed, 29 Mar 2023 07:16:03 -0700 (PDT) Received: from ?IPV6:2a05:6e02:1041:c10:7c0e:2838:74e9:d05? ([2a05:6e02:1041:c10:7c0e:2838:74e9:d05]) by smtp.googlemail.com with ESMTPSA id a6-20020a056000100600b002c8ed82c56csm30319851wrx.116.2023.03.29.07.16.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Mar 2023 07:16:02 -0700 (PDT) Message-ID: <016dc073-c9a3-4b96-6c58-7b21e0f998a5@linaro.org> Date: Wed, 29 Mar 2023 16:16:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH -next] thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference Content-Language: en-US To: "Rafael J. Wysocki" Cc: Zhang Rui , linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, linux-kernel@vger.kernel.org References: <20230329090055.7537-1-rui.zhang@intel.com> <08aee7fe-eddc-7841-2539-16ae43fd8d66@linaro.org> From: Daniel Lezcano In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On 29/03/2023 14:06, Rafael J. Wysocki wrote: > On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano > wrote: >> >> On 29/03/2023 11:00, Zhang Rui wrote: >>> When the hwmon device node of a thermal zone device is not found, >>> using hwmon->device causes a kernel NULL pointer dereference. >>> >>> Reported-by: Preble Adam C >>> Signed-off-by: Zhang Rui >>> --- >>> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") >>> dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. >>> I'm not sure if the Fix tag applies to such commit or not. >> >> Actually it reverts the work done to encapsulate the thermal zone device >> structure. > > So maybe instead of the wholesale switch to using "driver-specific" > device pointers for printing messages, something like > thermal_zone_debug/info/warn/error() taking a thermal zone pointer as > the first argument can be defined? > > At least this particular bug could be avoided this way. Actually we previously said the thermal_hwmon can be considered as part of the thermal core code, so we can keep using tz->device. I'll drop this change from the series. On the other side, adding more thermal_zone_debug/info.. gives opportunities to external components of the core thermal framework to write thermal zone device related message. I'm not sure that is a good thing, each writer should stay in its namespace, no ? >>> --- >>> drivers/thermal/thermal_hwmon.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c >>> index c59db17dddd6..261743f461be 100644 >>> --- a/drivers/thermal/thermal_hwmon.c >>> +++ b/drivers/thermal/thermal_hwmon.c >>> @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) >>> hwmon = thermal_hwmon_lookup_by_type(tz); >>> if (unlikely(!hwmon)) { >>> /* Should never happen... */ >>> - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); >>> + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); >> >> As it 'Should never happen', I would replace that by: >> >> if (WARN_ON(!hwmon)) >> /* Should never happen... */ >> return; >> >> >> >>> return; >>> } >>> >> >> -- >> Linaro.org │ Open source software for ARM SoCs >> >> Follow Linaro: Facebook | >> Twitter | >> Blog >> -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog