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 629F118E77F; Tue, 10 Sep 2024 10:44:53 +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=1725965093; cv=none; b=mfdspTWWhWlzlYBdnQT97UKkPz6HKmq9S1iPna7IuT8dHeyNqdylhMvu3OuR6uo9R37BJaAgyZsr9oX9zVddRGRiz5dKBQf4X1xY1nukACPYeNb2zfF92Bz5fsgNgnED1NpBU/VBgxzLUrHvHgom0UVa0gkG2IrE9U6Zkaj2RaQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725965093; c=relaxed/simple; bh=9ubCA5lKKznGG/ueIGP2o64cG5uJGRPPjFV8XRaPbv0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D/J5Otb0JB+SenO8cyjrCnZAABILyrtUoYx0hXNR0d0N3tlpI47x/DPkRyzoG/7BH6Zhn6pKCBQ35g/I0FLieuRKpJ4msSKD0wFLwV9pp4U9gmt8ESiGnt0P/MsSynABlDvKsR7f4Xog7lWGUmS06qTD17aBSFWkK90uKHDIy5w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=x6gq2/v+; 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="x6gq2/v+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8F94C4CEC3; Tue, 10 Sep 2024 10:44:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725965093; bh=9ubCA5lKKznGG/ueIGP2o64cG5uJGRPPjFV8XRaPbv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x6gq2/v+9a2mJqJ+jpm3NXyCvItvAEWOtdJrsiiu7J/EnicJZ0F/3ZA9KIZMBMBB9 e+79BaWYDDswcA8dLTw2/UKEDvg4TUF1YmlANhz/g7olasWjF2uMBUs1B7tRMdSszU qcs6ce88Wz1o9pyAbeaIAEkQ1xaZZtPkefW0E9jc= 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 135/186] hwmon: (adc128d818) Fix underflows seen when writing limit attributes Date: Tue, 10 Sep 2024 11:33:50 +0200 Message-ID: <20240910092600.155589496@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 8cad724c8537fe3e0da8004646abc00290adae40 ] 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/adc128d818.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c index 6c9a906631b8..e73c4de9471f 100644 --- a/drivers/hwmon/adc128d818.c +++ b/drivers/hwmon/adc128d818.c @@ -176,7 +176,7 @@ static ssize_t adc128_in_store(struct device *dev, mutex_lock(&data->update_lock); /* 10 mV LSB on limit registers */ - regval = clamp_val(DIV_ROUND_CLOSEST(val, 10), 0, 255); + regval = DIV_ROUND_CLOSEST(clamp_val(val, 0, 2550), 10); data->in[index][nr] = regval << 4; reg = index == 1 ? ADC128_REG_IN_MIN(nr) : ADC128_REG_IN_MAX(nr); i2c_smbus_write_byte_data(data->client, reg, regval); @@ -214,7 +214,7 @@ static ssize_t adc128_temp_store(struct device *dev, return err; mutex_lock(&data->update_lock); - regval = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127); + regval = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); data->temp[index] = regval << 1; i2c_smbus_write_byte_data(data->client, index == 1 ? ADC128_REG_TEMP_MAX -- 2.43.0