From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6199618FC6B; Tue, 10 Sep 2024 10:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725965102; cv=none; b=CFjs1FwMU4X8u94hksN6dKrM5DgWDrgRTOMz2AS3cDTKVsdD08CRYB44MX2F8rNHHNTdLpYOWuEHtq6DsNimkKATBwnIN/UcYy5Q9G74cMHyYfLAL9z1/vlls+0N68bCddDsEyixmEoocaixtPfWnUPV1G+yNKvpxQ+ydl8vcto= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725965102; c=relaxed/simple; bh=V6ItvJO0RjilbWTD+ZHkLg1hW+e268iVlG1FPXsUAGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PO1HrZotSdz2RfBKjyexy0FCj6HpHETCvAwVL/LW0PCXlXsHm+F+lbamveVv0QsXth7DgqZL4BF6SmCvJ4NchuKIexM+zH8CZZ8wHAoZXcBQKwTSpNw3btqCWBpaXBDv55A09BtaQeE1d9WZsXJdCkjFnGigeIWxKdgOhqkwEBU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=obZwmwU1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="obZwmwU1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E5D9C4CEC6; Tue, 10 Sep 2024 10:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725965102; bh=V6ItvJO0RjilbWTD+ZHkLg1hW+e268iVlG1FPXsUAGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=obZwmwU1/2fRmgDtlxeKK7js2CUbmHDaniQJUCSqt9OYiBAzEWPab7RcfEs2+Ieym FpAx0TX21J7y6Q7ETjCGP4qZfGvnMwERNyNE9KkeOzTYn1Dq9yDUGxj2GTqMu46Am+ JBNJkJ7eghDRu9LDeOoiIUJhXnV9elXRJNYj7340= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guenter Roeck , Sasha Levin Subject: [PATCH 5.10 138/186] hwmon: (w83627ehf) Fix underflows seen when writing limit attributes Date: Tue, 10 Sep 2024 11:33:53 +0200 Message-ID: <20240910092600.295213312@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092554.645718780@linuxfoundation.org> References: <20240910092554.645718780@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guenter Roeck [ Upstream commit 5c1de37969b7bc0abcb20b86e91e70caebbd4f89 ] DIV_ROUND_CLOSEST() after kstrtol() results in an underflow if a large negative number such as -9223372036854775808 is provided by the user. Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations. Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/w83627ehf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 3964ceab2817..acf36862851a 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c @@ -897,7 +897,7 @@ store_target_temp(struct device *dev, struct device_attribute *attr, if (err < 0) return err; - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 127); + val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 127000), 1000); mutex_lock(&data->update_lock); data->target_temp[nr] = val; @@ -922,7 +922,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, return err; /* Limit the temp to 0C - 15C */ - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 15); + val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 15000), 1000); mutex_lock(&data->update_lock); reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); -- 2.43.0