From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34DDA48AE3D for ; Tue, 5 May 2026 18:10:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778004634; cv=none; b=nqpxkuKkpIIsJWECPW0h8pWHdNtWgf7sFSGrxGh3Clbpmh6Hdr+HNAZ4QUw7Szi1FnTr864KRfaThUIx3KsAIcN9h1dBkW1CXy3ymQUoyGrjOFWEdarUJ/yMTVxW4q1/PRijqg4j+l7plF30SbQRm4PTu39qhQMtnNRWCCIsgv8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778004634; c=relaxed/simple; bh=ElxIShu9MGvxI7R5VGs6SocS6NurX6IGYv2XYH5ULlU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aUCfqcz7xTHL2/6Xl0gmlFjQK0lkKU5YbRyVp0L+1sv8NJk3dbnbCC+jCOw18A+JwpcmgebbTyO1vZtwz8YDvvF9rkSPkD+vC/E6MnupzzVT2zjs8SLlHAnsrDrUxpAqRAZlX9qkNLuPHAzcvUwMM9BJr/xJFQWXciRexFb2Js4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JLo+vqj6; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JLo+vqj6" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2ecf9e398f4so13323181eec.1 for ; Tue, 05 May 2026 11:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778004631; x=1778609431; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zx1umsJBGhZmdqwnCrzKLY80VDbMmJnRMhO75GMdDI8=; b=JLo+vqj6OjmX64DTdv2EKZuKahrXy3mYa8WXVVb0Mh/4LGEg4/IYfAjOj6tYTKbCK3 L1IHjlXCV05tPq8Dfm52qrtAUvZBK9i8ywXgFAhucceSNoW3valsK2kwYAI2+yMw/jW8 wL3BgZrYIw+iGwkuse8H1aknJZkegO5d+iBmRHZ3kEgZcVh9IxPcLTN++Xm6D5NzYFDw 2oa3EelnLn7h66wmDW2MS175k/A/pO8qGrMKn4uPGCjV37eK5LvDKG7rcLry617Q5dIp EDX3/5rm66ApK6OOxrkuM3BCWziPtWdFJEazapQDrsBEJ0WD2ZsyqAHv3ZFzN+laP+sN yyqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778004631; x=1778609431; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zx1umsJBGhZmdqwnCrzKLY80VDbMmJnRMhO75GMdDI8=; b=ey3xAhcnjTdKejkzCtRASl7yQRapfmBGFoUuRJMUHi5jjo2IYBadc3Ezsm3HPHkKgM tSQWuYz0QWPX3X+RbnOySNekezmrqpwhsZ/GyNUB8PZkDlEiO23xqzIZsnwjOcnHuXbv k+pShXOlxM3UTv7xfsH3wu/fatvDNBVznzJi0sMxiJgXVVAQQjBDmhG/ibrZwGSSN7Dr uAOZMEhVzQpSUawTDnU+qkbd5qsdSvu5+bVq3oW8x3HfyYfVDU79WdL9fbF1NHizDdQq uilGMF6VWUTpoxGzi/ZV/w4uQx88S5+TBX94ACrsp9JnbXSR1vpdi/IHF0qKMWqG3S+W XP7A== X-Forwarded-Encrypted: i=1; AFNElJ8mN6z/plHOeRBw4TaQNNF1ZSLt9bLEZrM0fokaNJjjVKlOH1a5d0lnGfgv6H7morEMMEa3nm7C0Zht5dk=@vger.kernel.org X-Gm-Message-State: AOJu0YzBkKwqzIQD5n8NpUpAfR0vbCtiHzbLOvbNXsrYftdkaeC7gmgy fO96REpBL2xor+41RrOadZ4rFP0ZuN+lnrvoIWux5pkwNG///9/x6wJE X-Gm-Gg: AeBDieuGNmsOVUB40VA5qYWF0RZUUBZClJ6lQis4VGUf/JVMMvQ/trNlJcR6TJuJKP8 mwpRxXeDbMR46SLa/lkWCDFUgKGwHrarJoZS9v2S3wB47tUJQpHDlsBCt93E6GqNXKIseAXSutY rAkAmth5QDlQg10UcMNgp1JHr61ucL+2YRyzPZTUOgd6JhYZAzeaMT49bNuJDhMr703o+ovL+CB UL7CsqQ+55CBNmn3jM+A9LwVaz6nIHj/wT12TOoT25y/KJEARU4dO0zW2EMAvy2Dq4GTp6MTfPP ZgA+5NgXYFLEjCZ8u32BOcUajVJ+tRIxedOq5TOQx4YL4TZr5xMy49VeM/hnKaBTWXaFjUf+412 iF6lHR9loOt8qHFVeKYqymqy2o/T/kWOo+AknzPHe38YpABX5WO25ZzK6p12//fVjK++7+47Qus npR4ryX0d5j5FsdSzj/gAryd3Pvc5fgIkc59efc6kmz/Z/CqHH/jF1Pc6hxhTwG1s7kdE3G3JBy CE= X-Received: by 2002:a05:7300:ec11:b0:2e5:5bf4:8869 with SMTP id 5a478bee46e88-2f54c87cd18mr185786eec.21.1778004631036; Tue, 05 May 2026 11:10:31 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:94ef:a6f3:2c96:2d58]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ee3889d611sm28496253eec.1.2026.05.05.11.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 11:10:30 -0700 (PDT) Date: Tue, 5 May 2026 11:10:26 -0700 From: Dmitry Torokhov To: Kris Bahnsen Cc: Marek Vasut , stable@vger.kernel.org, Mark Featherston , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] Input: ads7846 - don't use scratch for tx_buf when clearing register Message-ID: References: <20260430173739.3843425-1-kris@embeddedTS.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, May 05, 2026 at 09:21:50AM -0700, Kris Bahnsen wrote: > Dmitry, > > On 5/4/26 8:01 PM, Dmitry Torokhov wrote: > > Hi Kris, > > > > On Thu, Apr 30, 2026 at 05:37:38PM +0000, Kris Bahnsen wrote: > >> The workaround for XPT2046 clears the command register, giving the > >> touchscreen controller a NOP. The change incorrectly re-uses the > >> req->scratch variable which is used as rx_buf for xfer[5], so by > >> the time xfer[6] occurs, the contents of req->scratch may not be > >> 0. It was found that the touchscreen controller can end up in > >> a completely unresponsive state due to it being given a command > >> the driver does not expect. > >> > >> Instead, rely on the spi_transfer behavior of tx_buf being NULL to > >> transmit all 0 bits and use the scratch variable for the rx_buf for > >> both the 1 byte command to and 2 byte response from the controller. > >> > >> This change was tested on real TSC2046 and ADS7843 controllers, > >> but not the XPT2046 the workaround was originally created for. > >> Confirming that the original modification to clear the command > >> register does not impact either real controller. > >> > >> Fixes: 781a07da9bb94 ("Input: ads7846 - add dummy command register clearing cycle") > >> Cc: stable@vger.kernel.org > >> Co-developed-by: Mark Featherston > >> Signed-off-by: Mark Featherston > >> Signed-off-by: Kris Bahnsen > >> --- > >> > >> V1 -> V2: Don't use rx_buf when clearing command reg > >> V2 -> V3: Modify original 2 xfer command to eliminate dev_err() > >> output on xfer with len and NULL buffers > >> > >> drivers/input/touchscreen/ads7846.c | 3 +-- > >> 1 file changed, 1 insertion(+), 2 deletions(-) > >> > >> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c > >> index 4b39f7212d35c..488bcc8393293 100644 > >> --- a/drivers/input/touchscreen/ads7846.c > >> +++ b/drivers/input/touchscreen/ads7846.c > >> @@ -403,8 +403,7 @@ static int ads7846_read12_ser(struct device *dev, unsigned command) > >> spi_message_add_tail(&req->xfer[5], &req->msg); > >> > >> /* clear the command register */ > >> - req->scratch = 0; > >> - req->xfer[6].tx_buf = &req->scratch; > >> + req->xfer[6].rx_buf = &req->scratch; > > > > Sashiko (I believe correctly) pointed out that by doing this "scratch" > > is now write only and this may cause DMA from the device stomp on > > message status and other unrelated data that shares the same cacheline > > with scracth. While it was already a problem before now it is even more > > likely. > > > > Since scratch is now write-only I believe moving it below "sample" > > forces it into separate cacheline and fixes this problem. Could you > > please try making this change? > > Apologies, I'm not quite certain I understand what you mean by > "moving it below sample." Do you mean relocating the xfer[6] block > immediately below the xfer[3] block like so? If yes, I can get this > tested and a v4 patch together. If not, can you please clarify? I meant doing this: diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 093f4b56cc18..04ba98b62f70 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -328,7 +328,6 @@ struct ser_req { u8 ref_on; u8 command; u8 ref_off; - u16 scratch; struct spi_message msg; struct spi_transfer xfer[8]; /* @@ -336,6 +335,7 @@ struct ser_req { * transfer buffers to live in their own cache lines. */ __be16 sample ____cacheline_aligned; + u16 scratch; }; struct ads7845_ser_req { Thanks. -- Dmitry