Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4450051rwb; Tue, 16 Aug 2022 23:21:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6FAnh3JGg3fI/iBHqIcpgxKVQtGnh2PAYk+2iItzWfjA9/azHdVsabblV3qAGhk2pxNTPV X-Received: by 2002:a05:6402:4303:b0:43d:94f5:8081 with SMTP id m3-20020a056402430300b0043d94f58081mr21087911edc.288.1660717299810; Tue, 16 Aug 2022 23:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660717299; cv=none; d=google.com; s=arc-20160816; b=Puma2Wfw6h3o9CGzYaTtSAgyGyrCZoU+RjRwYkS3FwqLTvuC2o5F/A8tVAyWW3ZKDV cGFoXQARd6Rsdpa73gKQY0KFX/oBctwuRjYV99y4BeuUNSMMMvxWa6phZnP5GE/Jh3f0 g3viZuVY8Td9q4dJi3ScTnbm6zJldOptQsUjO3G31A/4f/F81xQBuYVCcbuQ/evnSGAL 2iLbrkIb+ZEqCW8QJ7COOeZhtJNqDe/l6tGPOnZFel+uKwMBo3/eQDC3Z4ICkKmOa57Q AOCPHmektyoMAA8Ml3p5yVA9WeFAH7c1yNGwOVX/v1JUGaE+czJ9D6BTQtm8xqdOmLoM XzRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fs/9146WgnjF/BhtH8jRN4vQYRrSPrHOqbPejU/yHNA=; b=LV318yikszG5cu+XoA6iymf7nAfcN+60S6duJDKmmnzojF3t1dE7pJhN3wccewh6t2 mZLDaSdTbmZHfkh1qWTudtHHzlDFtlTS+wfWGy4kADF8Cpceyz/cNbAbRUaG01eiXHoo cgyfu0XUMEtPLO9y2F69clBO6Igh/GuGjNuqnOXpAjwjaraPL01g+9LM5tsSQyMhp9HT aljdW46lzIgF4rVGbuDpvilIkoIWNOcI0Q3l7r68Bm1jfEP1e9dVUFccbBX9egtfP1pZ 4VFmoON/M3YcWC7iQDyj3B+cBj/63wsQsESwDU/vt7+wNQzxEsbQbYeAal7qDxKVWnFM SDiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=prZs6LcX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020aa7d1c6000000b0043d35059c65si11127841edp.160.2022.08.16.23.21.13; Tue, 16 Aug 2022 23:21:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=prZs6LcX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238804AbiHQFpE (ORCPT + 99 others); Wed, 17 Aug 2022 01:45:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238715AbiHQFoR (ORCPT ); Wed, 17 Aug 2022 01:44:17 -0400 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A6D67CB7D; Tue, 16 Aug 2022 22:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1660715041; x=1692251041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fs/9146WgnjF/BhtH8jRN4vQYRrSPrHOqbPejU/yHNA=; b=prZs6LcXJs0gtkSmrGHoe/OaWZ8zVFVszsKhyP4cHI6eFGtIzrZVuefs Xb3xG5xIgNmSxs+J0F+OWBWXwQM6fT5Yh5iHZeVqVqodZcStOQPnPY9/V oSYaqkCmG8n6f5lSiA7IgOWPBga/z0U1+LkVhLDdoWbEjrtPHxWVSE7lM Y=; X-IronPort-AV: E=Sophos;i="5.93,242,1654560000"; d="scan'208";a="120136357" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-41c1ef8b.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 05:43:47 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-41c1ef8b.us-east-1.amazon.com (Postfix) with ESMTPS id 303CA1600D3; Wed, 17 Aug 2022 05:43:43 +0000 (UTC) Received: from EX19D013UWA001.ant.amazon.com (10.13.138.253) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Wed, 17 Aug 2022 05:43:23 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D013UWA001.ant.amazon.com (10.13.138.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Wed, 17 Aug 2022 05:43:22 +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; Wed, 17 Aug 2022 05:43:22 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 8D9FF4C75; Wed, 17 Aug 2022 05:43:21 +0000 (UTC) From: Eliav Farber To: , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v2 11/16] hwmon: (mr75203) add protection for negative voltage value Date: Wed, 17 Aug 2022 05:43:16 +0000 Message-ID: <20220817054321.6519-12-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220817054321.6519-1-farbere@amazon.com> References: <20220817054321.6519-1-farbere@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 24a00339cfd8..e3191f590167 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -218,6 +218,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); -- 2.37.1