Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1573874imu; Sun, 16 Dec 2018 04:06:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/XXLaI3s8/lkVydZb+dQK9w1KJjG8A2uBzhvshHv2AI0kDQ4AFMXQVpwkhJscntj1PNbp3X X-Received: by 2002:a62:399b:: with SMTP id u27mr9665086pfj.181.1544961993441; Sun, 16 Dec 2018 04:06:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544961993; cv=none; d=google.com; s=arc-20160816; b=Nkp5miXCFn7wETsPL5V65QYkDSdNHgdZ/CRy51PaFYhqyrymvfCV0T4BU2PoH9hqxD pQgm+rTBSzkEzMo53XLY3Z3t1CAZnHLtbf84q4cOKvKqpAznltGPvEE7E/Waches6qNb BjFc4HWuz9cEJvrLJbLDhbLP5aa9kGOTg+rmqmw7NHZfTaDg5+GUBTh3BLfNV3FZuJ+i zrUaAGk5u4ANtabOj4uLDblM220sg+c6tHQlAUjgUAzeP/cRo8HX4F5PU9bWzL57vvMr WBYFA+o46J4oJV6OGqZtVVlmmycqg+jtsqgbWN79RdDKuYbgCEQJELCCIy0NL4Wl7Bef priw== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ZRUymE2Prd25aLyvu7Kj9np38uETcCMO5RN1AnMKX9Y=; b=Ii0SmAuKTWxCv9s5hA99EG4B643wxh5gCGLca4NPf1QqbNy5aCrZuE7my63jCks3Lm i0HKK5spcINwcugexDBT79ley+xTEn32XwQ7HJirMSy/ks+a6WCqBZPEN4qxyQiiIpPb wMd57vIV9ISLAxmXajnJGwEJyMPGmoMKmoyNwnjmLva83IjPxrinptTW+s6FKq8ae8pz DXbtuXt4Qne3lGQVKvbO08gxgLnkVIOuHmeMZqBaI4ZFvo+nZefI2pfNfF7eaHoIigRV s9+/VPb60VUqsBTtcK3RX3JUFzAHTRb/cjqzhXxxwa5bQEPdIO6uoQekk6ebv7kmuN/M cDBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zstsRZGS; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12si8098750plt.213.2018.12.16.04.06.17; Sun, 16 Dec 2018 04:06:33 -0800 (PST) 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=@kernel.org header.s=default header.b=zstsRZGS; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730250AbeLPLsB (ORCPT + 99 others); Sun, 16 Dec 2018 06:48:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:59386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729820AbeLPLsB (ORCPT ); Sun, 16 Dec 2018 06:48:01 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE684217FB; Sun, 16 Dec 2018 11:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544960880; bh=0RmhPlYhRloPOberTFh5JtK5N6gYp1Z19h586rMpmSo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=zstsRZGSYKZjvUOGe4uwecO1oKEP7oIZRphEgahI88ikon8j8vqHTEj30t2PGxOZ2 wlhTkDMZsg9ffWrkut3tMEoe95lt8T+q99NHgnBPDpFj2rvDNnBJitQ1jiQSf0p9qM VGkXRx1b8YrNEcm7AGIxSuphWB5SmIspMdpYtHm0= Date: Sun, 16 Dec 2018 11:47:55 +0000 From: Jonathan Cameron To: Jeremy Fertic Cc: Lars-Peter Clausen , Michael Hennerich , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 06/11] staging: iio: adt7316: fix the dac write calculation Message-ID: <20181216114755.675f3de3@archlinux> In-Reply-To: <20181212005503.28054-7-jeremyfertic@gmail.com> References: <20181212005503.28054-1-jeremyfertic@gmail.com> <20181212005503.28054-7-jeremyfertic@gmail.com> X-Mailer: Claws Mail 3.17.2 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 Dec 2018 17:54:58 -0700 Jeremy Fertic wrote: > The lsb calculation is not masking the correct bits from the user input. > Subtract 1 from (1 << offset) to correctly set up the mask to be applied > to user input. > > The lsb register stores its value starting at the bit 7 position. > adt7316_store_DAC() currently assumes the value is at the other end of the > register. Shift the lsb value before storing it in a new variable lsb_reg, > and write this variable to the lsb register. > > Signed-off-by: Jeremy Fertic Looks right to me. Wow this driver had some impressively wrong maths in it ;) Glad you are fixing this up. I'll pick up in v2. Thanks, Jonathan > --- > drivers/staging/iio/addac/adt7316.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c > index b7d12d003ddc..77ef3c209b67 100644 > --- a/drivers/staging/iio/addac/adt7316.c > +++ b/drivers/staging/iio/addac/adt7316.c > @@ -1442,7 +1442,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, > static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip, > int channel, const char *buf, size_t len) > { > - u8 msb, lsb, offset; > + u8 msb, lsb, lsb_reg, offset; > u16 data; > int ret; > > @@ -1460,9 +1460,13 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip, > return -EINVAL; > > if (chip->dac_bits > 8) { > - lsb = data & (1 << offset); > + lsb = data & ((1 << offset) - 1); > + if (chip->dac_bits == 12) > + lsb_reg = lsb << ADT7316_DA_12_BIT_LSB_SHIFT; > + else > + lsb_reg = lsb << ADT7316_DA_10_BIT_LSB_SHIFT; > ret = chip->bus.write(chip->bus.client, > - ADT7316_DA_DATA_BASE + channel * 2, lsb); > + ADT7316_DA_DATA_BASE + channel * 2, lsb_reg); > if (ret) > return -EIO; > }