Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2535882yba; Mon, 6 May 2019 07:39:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsrDW62vlx8Ez5TbnQ2tV2FPFZKGmxSS+6jacHAudXnDufsxrMVpgFdJ3LpPB8TNIt+fIM X-Received: by 2002:aa7:8383:: with SMTP id u3mr33217778pfm.245.1557153555348; Mon, 06 May 2019 07:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557153555; cv=none; d=google.com; s=arc-20160816; b=kUrWMkCGUg47ROsiOhoskGfONuuQkjc5NhrFOVDe/VxuNStMBpe/RbTm/So+0Wc66E QshzadQawdLxNL0h2TbgUDvBkcawhY0FRQNypsjKm0Qwdk1ovpkyzUCE4hqfpwtv89yL AR1acKsuNadwXk0lZGkbydDrtsYhHw9nWKDAFxC1dklGj0fDjRR+jeB3XvDpwdrhWlsu t55uSEpeYs71NIr/pxmbHIskrYsocv+tDFHGCtCCwpddBRdFx10AxjCY4QoV3kM4OPJl vbKmEICu1hIxIOkbz22HIYy1EYcBClOfzTSGImO7mH5S/1Bg1xqMrC5gh2YnIgqvZYUv jLxQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R0XY5pY7TobcRenNRtAOdwieKrg6dNu2AaeS4/YNdHw=; b=zc/XK7nLwk4htNH5xGoV5Y58wjSQNFrK1rz4M9SNQ9bI7qdfiJzKfAUntd1FNKlzPG M4DuupE42fH3odwo0xDu65GEI27zvJEmwlwyaDflITCjV94ySN+kL1gDHO4u70vsDdpq K0rA2X9Kk/WOjg/pxxfAGiww8/A5TGgITPrGMdnGcS3hi+VXgC5O+H4YYkujuspIMpMP HhO+Erm25jcu2T/tAAU8FaFqhYvJ2iUD8/gh6Ogds73Zce9QUSbt/+DGWraBnYZ+NixU FFCtvhsjjQWQss/fIjsDCG+JtoJtr3ekHF5QesaYjBNkUaf05JbxE7KGo//Q4VnD72NC 4RQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EUHeg1Fn; 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 b8si15231453pla.161.2019.05.06.07.38.59; Mon, 06 May 2019 07:39:15 -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=@kernel.org header.s=default header.b=EUHeg1Fn; 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 S1727390AbfEFOhY (ORCPT + 99 others); Mon, 6 May 2019 10:37:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:58050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726308AbfEFOhX (ORCPT ); Mon, 6 May 2019 10:37:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 1A4AF20449; Mon, 6 May 2019 14:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153442; bh=EJNks6oQRfwFiHCaA3iNcKyx/VTPfSwq9cHjpSIFI2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EUHeg1FnBKMjtA00yc1qo7zw4Na+g4hsDJOMzmPbgY+2lco9OdiavKwJp4ZwvZ/Vh izHdYZOw3bVdFupkxENoNtWUvSuAiKnuWQd0+hzYasc5l/mIlIdMeohpWSUWRJ413H W+t4Y3QyNw5vEp7gZ6EVr9kuCDGxGWDTdtcpOTUk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeremy Fertic , Jonathan Cameron Subject: [PATCH 5.0 091/122] staging: iio: adt7316: fix the dac write calculation Date: Mon, 6 May 2019 16:32:29 +0200 Message-Id: <20190506143102.862115202@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeremy Fertic commit 78accaea117c1ae878774974fab91ac4a0b0e2b0 upstream. 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. Fixes: 35f6b6b86ede ("staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver") Signed-off-by: Jeremy Fertic Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/staging/iio/addac/adt7316.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- 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 a 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 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; }