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 C1892172BA8; Tue, 10 Sep 2024 10:33:54 +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=1725964434; cv=none; b=rlB7Wda1dJmHQhkwXmyTQEe7vVbeIExDEtOwn66sjBECmvpJbqFnehrjX7au27KGjBUVwq1yTHP7LDvuomgCtWXpnCMKETml798giPdQHqx0iajUg8radTjpeQ6tHwzSLW4atoDy152kz0zIZLuZHtHd2DKnwBLhom8xf5UzIqA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725964434; c=relaxed/simple; bh=wSbXyWWdt33nIdDWSXRdQF8aB0ORh0Dk5br/SKVeqA0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TRgS6dc10Br17ngrurzLmR8xcGlWYk76Had/2Ty0EyOvISXrl2KGtryfqa7oM1dNC+x62UjGONJ/DjxeRGWeiNUWgwK8iWFAj84I14Cm1BByaZpvOc1pc8hB1KACdY1R/DLFvdNEsJzwviLJ/GsL+RmYKVbiPC+G4AofYO1wtug= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=csMx+VBj; 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="csMx+VBj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47F68C4CEC6; Tue, 10 Sep 2024 10:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725964434; bh=wSbXyWWdt33nIdDWSXRdQF8aB0ORh0Dk5br/SKVeqA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=csMx+VBjHmNRg+zpG5/kihgrc8VDjIIubccp/1hdKANU85BptMG6umQpwTNq34MPW 2DkOMwY21jNmBSJYYcQmyYnTxSD0KP4jf5Uu3UPQ5RQsoSeTf4X2rmYYqkgqR4vHqY /7KjBOR4Nd4ti11ZvwWkmgTpj8iaoorva23QHgnw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guenter Roeck , Sasha Levin Subject: [PATCH 6.6 155/269] hwmon: (w83627ehf) Fix underflows seen when writing limit attributes Date: Tue, 10 Sep 2024 11:32:22 +0200 Message-ID: <20240910092613.726163423@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092608.225137854@linuxfoundation.org> References: <20240910092608.225137854@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 6.6-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 fe960c0a624f..7d7d70afde65 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c @@ -895,7 +895,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; @@ -920,7 +920,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