From patchwork Mon Dec 5 04:55:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9460323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4F7496022E for ; Mon, 5 Dec 2016 06:03:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 437B324B5B for ; Mon, 5 Dec 2016 06:03:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3670F2621D; Mon, 5 Dec 2016 06:03:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE98524B5B for ; Mon, 5 Dec 2016 06:03:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751373AbcLEGDy (ORCPT ); Mon, 5 Dec 2016 01:03:54 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:50818 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbcLEGDu (ORCPT ); Mon, 5 Dec 2016 01:03:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=References:In-Reply-To:Message-Id:Date:Subject: Cc:To:From; bh=qkMQM+/JfcGguRxmi69BaK4s4L+tYBLsXhK6IoQjkR8=; b=TlG9bY7zghq9f0 i+l2cwZzR6z8TWUWOoG1wXelyfi/6jujVd4SVKeduWwlnJaCEqA2G+dxyJdTvJfJ9D9xmzJOxpiWQ gcjmknQNobHlrImQ9S9zyPhsIXMwNvDRZWHR8Wr3Qdfg1DTQbp3MzvRloJ9fO4xGwRLoxBjH46cOh 04PTv6ISa9hbV8gzatMyBxFcjOv9ixUkXIZb88m4cyslxQbgYrsyokNHUJeVYIURrDvJbpX9ycU2E 89UWNFBr1sL2W1wHF9mFthyTAhGCQicgsP8vz2E20+/N20jdTyGMA1tahACOrRnrgWCiqYRH9AFl9 Xf/sOYngm6WTdE35DEdA==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:49766 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1cDlJe-0009Ca-8U; Mon, 05 Dec 2016 04:55:50 +0000 From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 08/17] hwmon: (adt7470) Fix overflows seen when writing into limit attributes Date: Sun, 4 Dec 2016 20:55:31 -0800 Message-Id: <1480913740-5678-8-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1480913740-5678-1-git-send-email-linux@roeck-us.net> References: <1480913740-5678-1-git-send-email-linux@roeck-us.net> X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix overflows seen when writing large values into various temperature limit attributes. The input value passed to DIC_ROUND_CLOSEST() needs to be clamped to avoid such overflows. Signed-off-by: Guenter Roeck Reviewed-by: Jean Delvare --- drivers/hwmon/adt7470.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 6e60ca53406e..8996120b8170 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c @@ -483,8 +483,7 @@ static ssize_t set_temp_min(struct device *dev, if (kstrtol(buf, 10, &temp)) return -EINVAL; - temp = DIV_ROUND_CLOSEST(temp, 1000); - temp = clamp_val(temp, -128, 127); + temp = DIV_ROUND_CLOSEST(clamp_val(temp, -128000, 127000), 1000); mutex_lock(&data->lock); data->temp_min[attr->index] = temp; @@ -517,8 +516,7 @@ static ssize_t set_temp_max(struct device *dev, if (kstrtol(buf, 10, &temp)) return -EINVAL; - temp = DIV_ROUND_CLOSEST(temp, 1000); - temp = clamp_val(temp, -128, 127); + temp = DIV_ROUND_CLOSEST(clamp_val(temp, -128000, 127000), 1000); mutex_lock(&data->lock); data->temp_max[attr->index] = temp; @@ -880,8 +878,7 @@ static ssize_t set_pwm_tmin(struct device *dev, if (kstrtol(buf, 10, &temp)) return -EINVAL; - temp = DIV_ROUND_CLOSEST(temp, 1000); - temp = clamp_val(temp, -128, 127); + temp = DIV_ROUND_CLOSEST(clamp_val(temp, -128000, 127000), 1000); mutex_lock(&data->lock); data->pwm_tmin[attr->index] = temp;