Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2723489imm; Mon, 24 Sep 2018 08:55:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV62QRiOr7lS2QV3G+I0dADtWOut9gHo+8Xv/0XfEgiB2m8MQR8xKK4f5InSErEDpQqzFeWpS X-Received: by 2002:a17:902:4503:: with SMTP id m3-v6mr11255841pld.168.1537804529946; Mon, 24 Sep 2018 08:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537804529; cv=none; d=google.com; s=arc-20160816; b=lamP9I2aG0HTghsgowxjhGvqVep23W1GJhDZbxnq8WTJshoYa+jRPIFKgOwJzgu3sF xXxyKetwso15TSlYalSDuYr6RNkpjzkY9/LzRQ/LFCW6o9cPgM/VvJhwmDNB9grHIM/K 1tob1iMZjAo21j1/ZW2xj8w/jE6kof4R1EN7yP7XEmQhhkv8iBSBHsKCDgnoudybsvyo ZprJ2oKIJz+0aKOTzhc23t46bgcakCrlu1n7kuZGIJTA8rtwDi62QAHHeDGBFadVNfXy eSHw6exVeCDjgEoZh66TiPNSffDm/HPfajzxEDpkSNqhhSZ1XGcWjYhoRcYDw+FAKaR7 MMrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Csqe0Y2+oowuJwJFhl6JfGwU4IIBJ0vNM6hKyBJNQsM=; b=VzckeyZzvvJF/ns8QT79NnNppPqMilGIZGiSJJ7HHZlA/QteQjUawGs+rhIk1HGzqr Tq4qVBLrLly2tfshK31V9DULYisc0P8CfJv93w27S7ZYYI77OLxA/oJEffkmtaAKdhgF p4Qz0BhdZNbINqJ+9PMcZoJ7UDR9PLYoGcF9HfzUYV2aUxbRL7v5X/DgT6W7fySpPbX0 HZq3QHn+ElMfW0NrEhpw12Vq1NzWvuoko2BE4QzMy9CyJFxBzRNjca2gdhEgqS9iZL4+ 5ZClvfCkZ6b4vq+zW5zLMzCth0H1lCK59scyNaytZ7NV3ewFOU/0JQ96v6gU3AGIoOcj WBzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hCNSnv+Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s127-v6si3523048pgc.623.2018.09.24.08.55.13; Mon, 24 Sep 2018 08:55:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hCNSnv+Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730676AbeIXV5z (ORCPT + 99 others); Mon, 24 Sep 2018 17:57:55 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35172 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728312AbeIXV5y (ORCPT ); Mon, 24 Sep 2018 17:57:54 -0400 Received: by mail-pl1-f195.google.com with SMTP id g2-v6so9299538plo.2; Mon, 24 Sep 2018 08:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Csqe0Y2+oowuJwJFhl6JfGwU4IIBJ0vNM6hKyBJNQsM=; b=hCNSnv+QstSPUsyErkEYzixHnbSsJOjHH6xluY9HthFeDh5+ExnIISf2VJDh3qafrr QkPp+ZkzTG9w3R/K8ucAD9szO6e4I76OFnc7LlbaWXRh5nbwVtOUjKwW6GLna5po/ZKj 7itcLYyglCsCQpDmecMXcCjTHUC9QBNsTtau0rb0h+fM5+NyKaCcrUAZpKVbVSj8W+xL DSmsZlVQKJfdbNFIRXNxVExZJIBu1srHr/0GSZ7P4+pePKjY2185LNMS20CSzjSepx5R j+ctik52DJcbHykuUe9q6MghO7DETZ28tcKFTbMl/fsclbiI0cgzKVWc5VcGVgswq5TI 7W1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Csqe0Y2+oowuJwJFhl6JfGwU4IIBJ0vNM6hKyBJNQsM=; b=GRh9NlHKZUo3364j1OzMmdlp8clwPErOsxD2XVbVCBiSX3ba7hb27SEVcshfDXBNyF FFkguQzqKWCNq7AZFT7gkOM/RacqbMNlE/RsZQ4rvDlwGb1h2xJbaWpa8Usyc7/ptjOL u7rlWPbL3MI555N5xHXVOlCfICPK0zqHG5hj0yGufcWpZxNLVy4VcyMbR+JQdf08uXYX fdPd4tf1M4NZu1dBJycjkaJOE8hFHs7fEkwXFV8U94xeCOBV3XtPvYLO2sOU4a7bTc8W Nkq65/3K6N4N/phYTCcGTCSpvPhyLNmJSKox0PT0++YmZDzpmZMvnw7T130xKGmaM7eq px8w== X-Gm-Message-State: ABuFfoi+HiR5JHZ39RLkYjjHIWP+Elkro1FmUW5sfPvVSYb4g8cra9QG xAiHn/6WMuX8wiSEIgqrslk= X-Received: by 2002:a17:902:4d45:: with SMTP id o5-v6mr11379771plh.78.1537804505258; Mon, 24 Sep 2018 08:55:05 -0700 (PDT) Received: from himanshu-Vostro-3559 ([103.233.116.134]) by smtp.gmail.com with ESMTPSA id y86-v6sm50918925pfk.84.2018.09.24.08.54.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Sep 2018 08:55:04 -0700 (PDT) Date: Mon, 24 Sep 2018 21:24:52 +0530 From: Himanshu Jha To: "Gustavo A. R. Silva" Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: adc: Fix potential integer overflow Message-ID: <20180924155452.GA7529@himanshu-Vostro-3559> References: <20180918125314.GA12752@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180918125314.GA12752@embeddedor.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gustavo, On Tue, Sep 18, 2018 at 07:53:14AM -0500, Gustavo A. R. Silva wrote: > Cast factor to s64 in order to give the compiler complete information > about the proper arithmetic to use and avoid a potential integer > overflow. Notice that such variable is being used in a context > that expects an expression of type s64 (64 bits, signed). > > Addresses-Coverity-ID: 1324146 ("Unintentional integer overflow") > Fixes: e13d757279bb ("iio: adc: Add QCOM SPMI PMIC5 ADC driver") > Signed-off-by: Gustavo A. R. Silva > --- > drivers/iio/adc/qcom-vadc-common.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c > index dcd7fb5..e360e27 100644 > --- a/drivers/iio/adc/qcom-vadc-common.c > +++ b/drivers/iio/adc/qcom-vadc-common.c > @@ -282,7 +282,7 @@ static int qcom_vadc_scale_code_voltage_factor(u16 adc_code, > voltage = div64_s64(voltage, data->full_scale_code_volt); > if (voltage > 0) { > voltage *= prescale->den; > - temp = prescale->num * factor; > + temp = prescale->num * (s64)factor; As Jonathan pointed it is a false positive, let me share some more insight on this particular set of warnings. `num` is u32 and `factor` is unsigned int(u32 on most implementations). So, if multiplication b/w them exceeds UNIT_MAX then that is perfectly defined behavior in C. And often called "wrapping". https://port70.net/~nsz/c/c11/n1570.html#6.2.5p9 And *if* it exceeds UNIT_MAX, then it is certainly wrong arthimetic implementation by the author. On the other hand, if it were the case signed int overflow then certainly it is undefined behavior and called "overflow". And here `temp` is guaranteed to not overflow! But I don't understand what issue are you trying to resolve here and I'm interested in this particular set of warnings because I too get coverity scan reports on the same although I only search for IIO drivers issues. Thanks -- Himanshu Jha Undergraduate Student Department of Electronics & Communication Guru Tegh Bahadur Institute of Technology