Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp635291pxv; Thu, 15 Jul 2021 12:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1O3DA/NAPyf84nOlkcS6OsohqQ7og8L7LDL2Nzy4KAyWx9ygbpt04CaQzBGk7J9/dU1iF X-Received: by 2002:a6b:1685:: with SMTP id 127mr4273012iow.135.1626375922455; Thu, 15 Jul 2021 12:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375922; cv=none; d=google.com; s=arc-20160816; b=PpCCvmZ8Lp1BsR9WldJ72KKFWp5TrAoG/n8Xx2w9YStA/xwL6tFyvKXHyqG5ant7Ua Xwpja6WGZNFn+7rdcgHG9SvbDXd9uYDP3NL0YoQ1mus/QCYkuzV2RLTxw2GE1Wpgt4V0 JUGDb2HYP51tblOZeJHKOK/DgFQtzyqobiHtaN++D2tLIHmTCBUqQhFPaWiFkdyaLKcm G+myI9/lquav4WXHATx2E1JVsNrmOobrm2rMIE0f4+AYg9K+yN61kTccf6fa+ozL5zn9 KVlgxeSwGawRRKDqO1dRrX38Bs2u0aqxHp87TNDkSjuVaOr1ZnOnUQ+cWtC58EmWgt66 GD6w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rVzdXAcesu2INEiPybvP4aIS99LAiL1/R7MqqArQb6o=; b=dkwxYwGprfLA4zcY0GcM32XrvWJKTP78qyzQI9DxicQgGp7rDnGOnhJ0zd2pouGNcW FUjYQVVKrieoCz6Aty62khQz06kAgFNuQVteRHOo0idhPpWTXuXD0JPWtKz3LLjEK1VY byFfUQXgWHRVG825tFAFfPcAFHuQrs2Kc7zn+Rmf1+2hTjsONj6hHkkUOVuSQPnWootd 4IswA138fQYmt/WRS80oWHrAF40Y032y0cjZDuU6WF/lvNOvF6HdaDip5tAiFnJNiaMM To+FvR2vy+jmzmY27AFmZzXvpNdOsESiVjH7sLme3VOKSabnpR0tE1+o9mCh6HrCd/f9 ZuGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O5p59UL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si7906989ilm.77.2021.07.15.12.05.10; Thu, 15 Jul 2021 12:05:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O5p59UL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241874AbhGOTGC (ORCPT + 99 others); Thu, 15 Jul 2021 15:06:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:59828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240734AbhGOSz1 (ORCPT ); Thu, 15 Jul 2021 14:55:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C8DA613CC; Thu, 15 Jul 2021 18:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375151; bh=UhnBenFuO5eAzLlR9NLxfqYX1m7d7gtKMWKDHnFn80U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O5p59UL8Q4VCWd9mzdbhJH0PKQ6v+CGu0fjTf7D2K/rnpNHe8qmXke22GwDTcgcjG YCizUSnWLqvEMERdIxsPqnNKn4TkrWdOGsnFL9pN7vo+Nnuns/iO1B/5eTJ+y94Bi3 YaOFnS+9OvTwZ4rzGfhY9PEH7tVfdR83izikfL6M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Pandruvada , Zhang Rui , Daniel Lezcano Subject: [PATCH 5.10 180/215] thermal/drivers/int340x/processor_thermal: Fix tcc setting Date: Thu, 15 Jul 2021 20:39:12 +0200 Message-Id: <20210715182631.185482556@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Pandruvada commit fe6a6de6692e7f7159c1ff42b07ecd737df712b4 upstream. The following fixes are done for tcc sysfs interface: - TCC is 6 bits only from bit 29-24 - TCC of 0 is valid - When BIT(31) is set, this register is read only - Check for invalid tcc value - Error for negative values Fixes: fdf4f2fb8e899 ("drivers: thermal: processor_thermal_device: Export sysfs interface for TCC offset") Signed-off-by: Srinivas Pandruvada Cc: stable@vger.kernel.org Acked-by: Zhang Rui Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20210628215803.75038-1-srinivas.pandruvada@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/intel/int340x_thermal/processor_thermal_device.c | 20 ++++++---- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c @@ -156,24 +156,27 @@ static ssize_t tcc_offset_degree_celsius if (err) return err; - val = (val >> 24) & 0xff; + val = (val >> 24) & 0x3f; return sprintf(buf, "%d\n", (int)val); } -static int tcc_offset_update(int tcc) +static int tcc_offset_update(unsigned int tcc) { u64 val; int err; - if (!tcc) + if (tcc > 63) return -EINVAL; err = rdmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, &val); if (err) return err; - val &= ~GENMASK_ULL(31, 24); - val |= (tcc & 0xff) << 24; + if (val & BIT(31)) + return -EPERM; + + val &= ~GENMASK_ULL(29, 24); + val |= (tcc & 0x3f) << 24; err = wrmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, val); if (err) @@ -182,14 +185,15 @@ static int tcc_offset_update(int tcc) return 0; } -static int tcc_offset_save; +static unsigned int tcc_offset_save; static ssize_t tcc_offset_degree_celsius_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + unsigned int tcc; u64 val; - int tcc, err; + int err; err = rdmsrl_safe(MSR_PLATFORM_INFO, &val); if (err) @@ -198,7 +202,7 @@ static ssize_t tcc_offset_degree_celsius if (!(val & BIT(30))) return -EACCES; - if (kstrtoint(buf, 0, &tcc)) + if (kstrtouint(buf, 0, &tcc)) return -EINVAL; err = tcc_offset_update(tcc);