From patchwork Mon Dec 5 04:55:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9460337 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 C54736022E for ; Mon, 5 Dec 2016 06:04:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA60424B5B for ; Mon, 5 Dec 2016 06:04:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC2E32621D; Mon, 5 Dec 2016 06:04:44 +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 60CBA24B5B for ; Mon, 5 Dec 2016 06:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751100AbcLEGEo (ORCPT ); Mon, 5 Dec 2016 01:04:44 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:51785 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751039AbcLEGEn (ORCPT ); Mon, 5 Dec 2016 01:04:43 -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=Ou7WhRUb82pghxDNvqOUTjb0Rj9TNpChNdMewHs+9RY=; b=ay1EwU0YC/pDLR bAoiV6fLghs9GvhzCoxAsDrAU9Vo9pyLxDTeL2ujGu89xcOsAYlN7jKqbSuaVvKH09zvHovFZY9/T ZIPU7u04Buai9YyWAs5tROgWc+tMxYq+Ni7RBWSnzwd+y4XjCKDVzJOXAECs6umQznctKGDjXsFsE x5SZ/k6kjzGYAIp71Kjw27k3ucyLbqf+Y0ZVspMwt06iBF3AjsI/Z+f4/noaAetOFaWhQcu5Nl0nY eX7vrznSe3xpH2N6g8VTcN2LOJWAx7QvRHwKm4VYPNSWfr7l1xnFWoiQ+QL0+D7TUW9THPuyvfQ2i i4ZuvtrnXLoRE7eYt6mQ==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:49774 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1cDlJn-0009dY-8J; Mon, 05 Dec 2016 04:55:59 +0000 From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Juerg Haefliger Subject: [PATCH 12/17] hwmon: (dme1737) Fix overflows seen when writing into limit attributes Date: Sun, 4 Dec 2016 20:55:35 -0800 Message-Id: <1480913740-5678-12-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 Writes into voltage limit, temperature limit, and temperature zone attributes can overflow due to unchecked parameters to multiplications and additions. Cc: Juerg Haefliger Signed-off-by: Guenter Roeck --- drivers/hwmon/dme1737.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index 8763c4a8280c..29d082c12c74 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c @@ -279,7 +279,8 @@ static inline int IN_FROM_REG(int reg, int nominal, int res) static inline int IN_TO_REG(long val, int nominal) { - return clamp_val((val * 192 + nominal / 2) / nominal, 0, 255); + return DIV_ROUND_CLOSEST(clamp_val(val, 0, 255 * nominal / 192) * 192, + nominal); } /* @@ -295,7 +296,7 @@ static inline int TEMP_FROM_REG(int reg, int res) static inline int TEMP_TO_REG(long val) { - return clamp_val((val < 0 ? val - 500 : val + 500) / 1000, -128, 127); + return DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); } /* Temperature range */ @@ -1028,6 +1029,8 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr, if (err) return err; + val = clamp_val(val, -256000, 255000); + mutex_lock(&data->update_lock); switch (fn) { case SYS_ZONE_AUTO_POINT1_TEMP_HYST: