From patchwork Tue Aug 16 08:27:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 597667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B0D8C2BB41 for ; Tue, 16 Aug 2022 09:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233739AbiHPJlT (ORCPT ); Tue, 16 Aug 2022 05:41:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233955AbiHPJks (ORCPT ); Tue, 16 Aug 2022 05:40:48 -0400 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21C8C13927A; Tue, 16 Aug 2022 01:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1660638499; x=1692174499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EJd1o/p/S0Q3ZMPg/GLSYaA+EOKY6YoA3u+3TbLbo0w=; b=kTLFhALgIu/fDOUrMe3pM4b6qCS+8lduH9t3WEvPc0iGzYwYXyqhTU4M Q2My38g+MPfPtfs1gp+SgEWqvBRFx/4KoSBiTkUJa4SpMKZP0ZxJqO2t5 B4SMwQK/LoxPSS5dbkPzDLkcKQjpBPAr5L8ROGXqs3FF1wVD+2E9FTpgZ c=; X-IronPort-AV: E=Sophos;i="5.93,240,1654560000"; d="scan'208";a="1044708628" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-2dbf0206.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 08:28:00 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2a-2dbf0206.us-west-2.amazon.com (Postfix) with ESMTPS id B4BDCA27C8; Tue, 16 Aug 2022 08:28:00 +0000 (UTC) Received: from EX19D013UWB002.ant.amazon.com (10.13.138.21) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 16 Aug 2022 08:27:59 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D013UWB002.ant.amazon.com (10.13.138.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 16 Aug 2022 08:27:59 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 16 Aug 2022 08:27:59 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 5B13F4C51; Tue, 16 Aug 2022 08:27:57 +0000 (UTC) From: Eliav Farber To: , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH 11/16] hwmon: (mr75203) add protection for negative voltage value Date: Tue, 16 Aug 2022 08:27:52 +0000 Message-ID: <20220816082757.11990-12-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816082757.11990-1-farbere@amazon.com> References: <20220816082757.11990-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This change makes sure the returned voltage vlaue is 0 or positive. Signed-off-by: Eliav Farber --- drivers/hwmon/mr75203.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 417b135c1b3f..8d8883301ff5 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -216,6 +216,13 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) return ret; n &= SAMPLE_DATA_MSK; + + /* Voltage can't be negative */ + if (PVT_N_CONST * n < PVT_R_CONST) { + *val = 0; + return 0; + } + /* Convert the N bitstream count into voltage */ *val = pvt->vd[channel].pre_scaler; *val *= (PVT_N_CONST * n - PVT_R_CONST);