Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp623446pxv; Thu, 15 Jul 2021 11:48:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPUKn1LAZEyAuxqBy/qjBYmz0WvJSYlG+KgxZw53IXyhVcKtTD8uP6roAMKCc1/R8Wt141 X-Received: by 2002:a5d:8b85:: with SMTP id p5mr4159999iol.43.1626374919202; Thu, 15 Jul 2021 11:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626374919; cv=none; d=google.com; s=arc-20160816; b=mMzWcNqI0JmMYsnyoFo+lDaGZ3PwvUP5rGmw6tXY4vY9ZrijL60tHeDxdosRmvJeCQ gaAlgqy/WH9y682JAdY58xm+/MFN6vgD8EXrwY+pJFiGzPyZrSOhre+yR1XUJyIcTe+s fitr1fANzZXsMazMDgL3cJabGmYTrlKZSTEgLWTcsv413hnUPX39FGGynok+uov/IoWL exylAsYLTGXwniKv+W2OYZ8mqY3JIgwZ2/OS2VaNlPI7KMFkeDJKvrW4+5XooD1UwxHZ 5I47q+yWN1I7Po5ER6j+WjjsoE1rPwQcsPrgHJkSN6FZ480E1Jhj4/waGlGMRAmjNRvC 0OVQ== 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=BYfGZlPeGeWX/rZr2Cre/Km+kerpk9W6epnMx2R1d84=; b=XwaVkaxm6Wq/g+L8uy69OKcUNx244Jyo4A6a0AvzO4B4WAF7HuN7CPL3yGGzLr6dVE 0hEpf65QY7zk6F6JWiqI483f38AFuz4lieYtJmxT4h2VZYA5pR4rs0u+L2Jc/17fCU3O 4GBZNz/7VUyq+klNftItQQab3KzzyZE6ns8JgbM74XkJafjHxdWYndc9m2YuzcmxBKv6 eVD20mkrJ1Rk6O1nMk9xsfhAni7xZG4/scN0fpSXFbNE5z3fRjUF0ne9TaEvTjCGsJdC u41fW5wNVERM7qwyqroOD44bmAXpywyG7TqQoa0Eh3SqSduCaQl8kri6cmDz+moU1uPh 8DbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VoFg06uN; 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 p31si8313788jac.95.2021.07.15.11.48.26; Thu, 15 Jul 2021 11:48:39 -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=VoFg06uN; 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 S240690AbhGOStd (ORCPT + 99 others); Thu, 15 Jul 2021 14:49:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:49216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238747AbhGOSrY (ORCPT ); Thu, 15 Jul 2021 14:47:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1D30661396; Thu, 15 Jul 2021 18:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374670; bh=4Qji5lc7N8UusOdOSXaasI6/cy9f8frzo2SmYB/VB1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VoFg06uN4RfAfwoCCqUFMV0vPGdkKs+Mm3L3Sy5lgHCWblN4UPTOaxYmNcDnU1DFr RO6vctceN2HmJJVzXf/tzFSjJ0ItCV/dCs/bgVKE0sLGACD5+vKYcjXMDSoFcyVbDJ F9UNVAIaMWyXJepeSTWfnjYqqLJ+AkfgnrmDF1uM= 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.4 098/122] thermal/drivers/int340x/processor_thermal: Fix tcc setting Date: Thu, 15 Jul 2021 20:39:05 +0200 Message-Id: <20210715182518.340479151@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182448.393443551@linuxfoundation.org> References: <20210715182448.393443551@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 @@ -150,24 +150,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) @@ -176,14 +179,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) @@ -192,7 +196,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);