Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp711694pxv; Thu, 15 Jul 2021 14:09:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7iLhAD/IFGfvTiUCxlnjmReeIEkcV22pbVFdioUr5WyC5EmKzr9r9hGK1kaiVc0+PxLD0 X-Received: by 2002:a17:906:5a6f:: with SMTP id my47mr7762795ejc.29.1626383380201; Thu, 15 Jul 2021 14:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383380; cv=none; d=google.com; s=arc-20160816; b=jU+RBwP5oQV0T58jnac4D1YDszPArvCW+vps9zdQRdVdEuWdk6F0+V0pN+tnzce6ms l6oAQnmdoEt1dV5YcqYCylzH+Nov5xSotrEgqPJszRmIbjrVqHF9HRnz1d/sQ7ja7vLi j6q6FmCYU6F4vErp6X74QfuSq201T1+ZPvRfSw0o876Rqy7uVPFxAHj/u+/kjIb/5kr/ llEd1IVLAQ8ykcKDnmn6477WvPx/1zJzRZemTh0UGrUJ2kZtiK/SdXE062LBIuhjRqsM bOjiyeMXNdPK9EYicdu30YAB69Y8hLduLniwbqADVxSanzgakGJWCTaO5KmbSJKJw1JY IrBw== 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=kDOxXbMYtbXpuHXvF6DmPe+MdZhW5Oj8QMGk38DhkSk=; b=a4pK8yfsfamd+Xz6RU4uBOUR4BA3rR8cFtaIP/QQRZ9Mwt8hySxl2YAxjsetQeH04V SW4RoMptezMro2reinBPvGsqNNAbRQtfFmoOjsLem9vqtMzUx7CccQjmr92vo6si464V pbo9PWb1Al9NGrVdOjB2h5JFs9pdEnt0WVpx4ioBf3LS7sOxPSrbF9x/O2JIKf9Fl5Wi pUtYsqfUXKpXHYtpPFffNe/Gy9fFE1R1jqqLKW8HvBYFl0s/hDDPV6yMf4Wm/VzYBa+/ w4GrZLpCaz2lwMeprpF/5947iHXtxMlc81r0gnwg5TF7KQM2SBHPZ5rr4zlG9idFs1HR Ctlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g9kvkhfW; 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 x5si8158516ejf.530.2021.07.15.14.09.17; Thu, 15 Jul 2021 14:09:40 -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=g9kvkhfW; 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 S242985AbhGOTU7 (ORCPT + 99 others); Thu, 15 Jul 2021 15:20:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:39760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241820AbhGOTFS (ORCPT ); Thu, 15 Jul 2021 15:05:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5D00C613DC; Thu, 15 Jul 2021 19:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375705; bh=LzPTVCKk5pTrMWa6qyP+fACmjrQbtz4UR69fbiu+ICk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g9kvkhfWyKwYNlFohKIzGsPGK2mPN/51IrnbI+mYrM+DL1GI4vumM205PZkuqgYXc Gw/UmZ6oaiDBC/k+JNGfmlpmNi/0broBVvrQu6woFljMWc1yIIY526taxyR7+0Ucvy pGBUAx1Wlidh+qfPEf1RVMJ2fk8xJbs+VgTj5gQk= 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.12 199/242] thermal/drivers/int340x/processor_thermal: Fix tcc setting Date: Thu, 15 Jul 2021 20:39:21 +0200 Message-Id: <20210715182628.257866003@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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 @@ -100,24 +100,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) @@ -126,14 +129,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) @@ -142,7 +146,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);