Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2020940ybl; Thu, 15 Aug 2019 05:18:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxM/0D31jOzVTHQJ360wkB1YTfBcSivg2BLTFOiNsGwy1kMoimKUhlzvgIOBztK8/dSmi9X X-Received: by 2002:a63:550e:: with SMTP id j14mr2955063pgb.302.1565871492466; Thu, 15 Aug 2019 05:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565871492; cv=none; d=google.com; s=arc-20160816; b=HvZguS4GXId857SrV+csSdZa1u0o51yDuSZHnNWR85aSp3QJACGu71coOHhnywvpmM mwuAvj1YtvtwofHcDq7pEygSlYUIMI/nCb/plpmde/FicwRDXFfpFfcVw28W0cZV9mk7 iMwKZ2RJI6z2qVk7EKZ47i5NSvEm0eqbNnPgGxFHf/M/anr+H/XhUMM4DQusEuFVoCC3 6teFqJt1LwQ57JLmqMKVvgFTu/70u5NFFHxrNyVIsfsF/UVzVtVoJlV80g6LO6jdVxRI 4P+0zbDNkTdhzz7ercrGp2ouImBKwMOP/Hzngtqe1QDoshw5mmXVwSw9yAD0bIYgEyTR JjrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=2y8LEmmUqNbXx8O024xEhEDMMWRizP9krQy9X0vxXdM=; b=Yh4BB3J+kCwOqVhcuDUR1hvOAUvx/xOqsfsUJa9bYwD9KXR54I6nLl8K/4LaOkz/xk Jz8g+1eaFkfMXiOQzB5neaFkjuPZmkzNf7Qyi2/eDDAnFknnwNtwEgUSj2//rI/6M9d+ 2TEy1Xx5JWFCSLbHqu+0sF9GfOerq7/afqoeFtsBZqSRObjMrt0fbW2AwEIni9kMrk1X /1hjSmhLYm2ZVDF/LYrrBzzwN7jopne6iQV9pKU96X8DMKBW0ceKBfW3RLVj2japQwHh wAwOQXS4ywDN7d0gdzvxqgpnpPuho9++x7Cbgqtjqe7LCsbnNnZzGxGOfStHnhZZAPE3 ub4A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z30si1747699pga.346.2019.08.15.05.17.56; Thu, 15 Aug 2019 05:18:12 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730643AbfHOMAS (ORCPT + 99 others); Thu, 15 Aug 2019 08:00:18 -0400 Received: from www381.your-server.de ([78.46.137.84]:59664 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729818AbfHOMAS (ORCPT ); Thu, 15 Aug 2019 08:00:18 -0400 X-Greylist: delayed 1174 seconds by postgrey-1.27 at vger.kernel.org; Thu, 15 Aug 2019 08:00:17 EDT Received: from sslproxy05.your-server.de ([78.46.172.2]) by www381.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1hyE7Q-0004qd-Ce; Thu, 15 Aug 2019 13:40:36 +0200 Received: from [93.104.111.225] (helo=[192.168.178.20]) by sslproxy05.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1hyE7Q-000IFI-3p; Thu, 15 Aug 2019 13:40:36 +0200 Subject: Re: static analysis bug report in drivers/staging/iio/dac/ad5380.c To: Colin Ian King , Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , Michael Hennerich , Stefan Popa , linux-iio@vger.kernel.org, "devel@driverdev.osuosl.org" Cc: "linux-kernel@vger.kernel.org" References: From: Lars-Peter Clausen Message-ID: <1f73a6d5-9e77-6f2f-8fcf-ec87f5ffa54d@metafoo.de> Date: Thu, 15 Aug 2019 13:40:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.100.3/25542/Thu Aug 15 10:25:56 2019) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/15/19 12:21 PM, Colin Ian King wrote: > Hi, > > Static analysis with Coverity Scan has detected a potential assignment > bug in ad5380.c: > > 217 case IIO_CHAN_INFO_CALIBBIAS: > 218 ret = regmap_read(st->regmap, > AD5380_REG_OFFSET(chan->address), > 219 val); > 220 if (ret) > 221 return ret; > 222 *val >>= chan->scan_type.shift; > > CID 43178 (#1 of 1): Unused value (UNUSED_VALUE)assigned_pointer: > Assigning value from val - (1 << chan->scan_type.realbits) / 2 to val > here, but that stored value is not used. > > 223 val -= (1 << chan->scan_type.realbits) / 2; > 224 return IIO_VAL_INT; > > val is a pointer and so updating it before a return is probably not the > intention. I suspect the intention was probably: > > *val -= (1 << chan->scan_type.realbits) / 2; > > However, I'm not confident about this as the following case has: > > 225 case IIO_CHAN_INFO_SCALE: > 226 *val = 2 * st->vref; > 227 *val2 = chan->scan_type.realbits; > 228 return IIO_VAL_FRACTIONAL_LOG2; > > which may imply the update maybe to *val2 instead, e.g.: > > *val2 -= (1 << chan->scan_type.realbits) / 2; > > Any ideas? Updating changing val to *val is the right fix in this case.