Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1780307imu; Sat, 26 Jan 2019 10:30:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN6e4Ginpxc89iKmlSc/REJxdGfdx3uSZP3JrhoUOpQP1OE632rykcb0kK0VxWdLD6D7zEkN X-Received: by 2002:a63:fb15:: with SMTP id o21mr14160749pgh.211.1548527438343; Sat, 26 Jan 2019 10:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548527438; cv=none; d=google.com; s=arc-20160816; b=UXP+s6b54aFKNYnnwp30IG5Hx18/cFGIw3MAGf1EfwlFpbZLwYy9AumoW8tbSPKeu5 YeXJL0Ylrk/qquOQ1cjcsdgsVdV2o0lbEnHbbN2RluF7oHOIJFCSM3SOEEEuH56+d6X1 7t/ckqu8vuxzUDI2iLbS9Dig8t56VfXl7mQ5h1ohS24/DfhP7bapYYWWtfJAWG4u4lAp AYCHSjUnRDtG8eVyaiD1Lm5WYOPb/tV24C6AnB49SF1m5Ix55gTx4jDuxC6P9qFz+2Ae ET2rHuz9mi/X6Oufc3CGG9C0E4trWmTbjItvfEnmv+edQG61RbiP7UntAR+3LWCK8GTK 3TNg== 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=85i0xO4Ufuy3yokoQTioGKQhWIw/4dIyGB2xYgQrOa4=; b=Tce3ylErSFiQPu9hd/MW1O45xX4iVjc3bUGzNgv+c/a5mJWaYL95AhZQeSpKkv5Jm2 2snLW/kpGjwGft188gP8FOP6IudPD1qQdIe8ZNFccBDY3Y30x9WfcdQvRUkF3nITBnKM Kf2JaMWMZNNXs7tM8jUA1XIDEtVjuC6OB0X8h9zB2JzljN3vreG4zttPH0i5ovAWNGrw ZNHmLC6+shJc7ftMmPmXLpm49CGlofJ9hjERoGXjniOFZhScQvTPw1ZkCGkhDMqxuRZg H0OC3KyvyrlEDYaUvPIRz+kj5o4FxGyj83hUObet6GhcaZPqA15DYcyKoJWXzUuaRN0T s29Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=woz3Ulb6; 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 q15si28163214pgm.420.2019.01.26.10.30.20; Sat, 26 Jan 2019 10:30:38 -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=woz3Ulb6; 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 S1726189AbfAZSaR (ORCPT + 99 others); Sat, 26 Jan 2019 13:30:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:40496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726106AbfAZSaR (ORCPT ); Sat, 26 Jan 2019 13:30:17 -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 91E3E2184C; Sat, 26 Jan 2019 18:30:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548527416; bh=Lb5nsk+TNV5ZShC4CzD8Gbq3WWu4HtESt6MHRMbaW0A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=woz3Ulb6RPd0Or0RUN2UoeyC+aW32mPtZ3Qj5J2BGVfX+F9FmWn7UpKZ6nNB35pxe sPhcHtApMJX7poamSrs4V+K43lrRmfdOHqxzmhjhHOh7nFVRb3dQzFRHINrvaroY9c toSYCII3rBXRwLOFLogikvGGz2G0eB4Lv/Wtie+k= Date: Sat, 26 Jan 2019 18:30:11 +0000 From: Jonathan Cameron To: justinpopo6@gmail.com Cc: linux-iio@vger.kernel.org, knaack.h@gmx.de, lars@metafoo.de, linux-kernel@vger.kernel.org, f.fainelli@gmail.com, Mark Brown Subject: Re: [PATCH v2] iio: adc: ti-ads7950: inconsistency with spi msg Message-ID: <20190126183011.00f03cc3@archlinux> In-Reply-To: <1548440422-27943-1-git-send-email-justinpopo6@gmail.com> References: <1548440422-27943-1-git-send-email-justinpopo6@gmail.com> X-Mailer: Claws Mail 3.17.3 (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 Fri, 25 Jan 2019 10:20:22 -0800 justinpopo6@gmail.com wrote: > From: Justin Chen > > To read a channel we require 3 cycles to send, process, and receive > the data. The transfer buffer for the third transaction is left blank. > This leaves it up to the SPI driver to decide what to do. Interesting. I think that means you may have a bug in your SPI driver. The pointer in question is always left set to NULL in the adc driver (not explicitly but it will be because ultimately comes from a kzalloc). Documentation for an SPI message makes it clear that NULL is allowed. From include/linux/spi/spi.h "* Those segments always read the same number of bits as they * write; but one or the other is easily ignored by passing a null buffer * pointer. " Hmm. It does say 'ignored'. My assumption has always been that means it would be filled with zeros, but maybe I'm wrong. Mark? > > In one particular case, if the tx buffer is not set the spi driver > sets it to 0xff. This puts the ADC in a alarm programming state, > therefore the following read to a channel becomes erroneous. > > Instead of leaving us to the mercy of the SPI driver, we send the > ADC cmd on the third transaction to prevent inconsistent behavior. > > Fixes: 902c4b2446d4 ("iio: adc: New driver for TI ADS7950 chips") > Signed-off-by: Justin Chen > --- > drivers/iio/adc/ti-ads7950.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c > index 0ad6359..1255d8b 100644 > --- a/drivers/iio/adc/ti-ads7950.c > +++ b/drivers/iio/adc/ti-ads7950.c > @@ -422,6 +422,7 @@ static int ti_ads7950_probe(struct spi_device *spi) > st->scan_single_xfer[1].tx_buf = &st->single_tx; > st->scan_single_xfer[1].len = 2; > st->scan_single_xfer[1].cs_change = 1; > + st->scan_single_xfer[2].tx_buf = &st->single_tx; > st->scan_single_xfer[2].rx_buf = &st->single_rx; > st->scan_single_xfer[2].len = 2; >