From patchwork Sun Nov 20 22:33:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9438651 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 348266047D for ; Sun, 20 Nov 2016 22:33:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26A0C2895A for ; Sun, 20 Nov 2016 22:33:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B93E2896F; Sun, 20 Nov 2016 22:33:08 +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 C139F2895A for ; Sun, 20 Nov 2016 22:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753419AbcKTWdH (ORCPT ); Sun, 20 Nov 2016 17:33:07 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:37896 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753086AbcKTWdH (ORCPT ); Sun, 20 Nov 2016 17:33:07 -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=CRazgz3U3rmGzVFzXNyQ9/nch6oJmQlSDtkRZ/ug1Hg=; b=mfmCM1AlniPaLQ hnRpOR7WgMTVFG/G3GqZtqrpTE+1rlYz6Rs3E+h4y4zZ0l9lTU36YGyfXtMTSXr8FDDKIPTx/Lz4v wC2Nnjf+ciUoo5VVoY0gyC+ddH5MRbMTxbIZFKNa5sYr/WiK2Xa9hEA+5ZACC8cq/DigtU1AblurB xv1NFyWjemp2WUR5WgQvOvv85G1QFAm12KU9rOi+WS4QPv5AofH9RpvFco4YUbNa4DcBKco3WN94u LTo31Tf386jUrCwyOs+L/nzbtPiLOaD1CQEs/fHBHqKadC6BJ1H9puq5kRxC5YIna3dkeH8/ztR6J 3QfPkHZDVSGMA+TeomnA==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:44346 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1c8afX-0030FT-SX; Sun, 20 Nov 2016 22:33:04 +0000 From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 4/4] hwmon: (smsc47m192) Fix overflows seen when writing into limit attributes Date: Sun, 20 Nov 2016 14:33:00 -0800 Message-Id: <1479681180-6940-4-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1479681180-6940-1-git-send-email-linux@roeck-us.net> References: <1479681180-6940-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 Module test reports overflows when writing into temperature and voltage limit attributes temp1_min: Suspected overflow: [127000 vs. 0] temp1_max: Suspected overflow: [127000 vs. 0] temp1_offset: Suspected overflow: [127000 vs. 0] temp2_min: Suspected overflow: [127000 vs. 0] temp2_max: Suspected overflow: [127000 vs. 0] temp2_offset: Suspected overflow: [127000 vs. 0] temp3_min: Suspected overflow: [127000 vs. 0] temp3_max: Suspected overflow: [127000 vs. 0] temp3_offset: Suspected overflow: [127000 vs. 0] in0_min: Suspected overflow: [3320 vs. 0] in0_max: Suspected overflow: [3320 vs. 0] in4_min: Suspected overflow: [15938 vs. 0] in4_max: Suspected overflow: [15938 vs. 0] in6_min: Suspected overflow: [1992 vs. 0] in6_max: Suspected overflow: [1992 vs. 0] in7_min: Suspected overflow: [2391 vs. 0] in7_max: Suspected overflow: [2391 vs. 0] The problem is caused by conversions from unsigned long to long and from long to int. Signed-off-by: Guenter Roeck --- drivers/hwmon/smsc47m192.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index 6ac7cda72d4c..202e167d6a59 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c @@ -77,6 +77,7 @@ static inline unsigned int IN_FROM_REG(u8 reg, int n) static inline u8 IN_TO_REG(unsigned long val, int n) { + val = clamp_val(val, 0, 65535); return clamp_val(SCALE(val, 192, nom_mv[n]), 0, 255); } @@ -84,7 +85,7 @@ static inline u8 IN_TO_REG(unsigned long val, int n) * TEMP: 0.001 degC units (-128C to +127C) * REG: 1C/bit, two's complement */ -static inline s8 TEMP_TO_REG(int val) +static inline s8 TEMP_TO_REG(long val) { return SCALE(clamp_val(val, -128000, 127000), 1, 1000); }