From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796082338; b=fQwMYryFj1YudQgXQrkjzR3GW5b1kX+74YHA9Ktre+iwB+xTwvK/NjqL61IWUpemWq/C GfMFVnZBRr+7jxZe6owv5R6fdz6B4+o1PnABMMQeMNtk9B+Hjd1fiua4sz7EgpZhlPrNJ SQiNaWOQBfhktyoqfoaC+o8JInegt6Gite/RlekpMT3f0dZ9TKfH4xS5aTi43/W+KJZ+X yiwUAVdLz1SspKyURn7bmbUyLRXpVqsfiN6tCtqZF8AnySwwjNMf8+uJMVb59sjYs5F2Z jufU94xCg7lsxbznziPGUKqrWG+BZOwSz2QTi0lgQF+4yMdB1D/DyrwTDAbRr3PhvJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796082338; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding: Content-Disposition; bh=bKElIdQoBx+DcydNqLcup4euRNJWGxYoFaaceu8ZMxE=; b=WmjXuWI/5bqxrgVliNgq7NnY5+nDtlrrk9aA7Lt4J9+XVaIyK6t1BjE6GjMtfBiYV/Hb GjWftiRVazITC9N5AP7pvEs6MM+a5R9OuMNNlWwZfgH8GeU7ZRhVC40QWKGmflTE8aLbA kpN6FSrLlE+GAZAw1ffvOm+h0wrtLoNStGAvc1wlahIlKssJDB6YVWayVWH3+m+YhZVRL pq3p0UJ3m3qubIPm2qGMe0m2MTm2qcG4vZei+we7wNACzDjezrdGEk9KT/As18aeLNfQM /yrEoBpuhr2MLdU5e+9rffNppAAf1rxPIZbTkvSHC3TT/7LjfIsJj/+jPGWA/rUDPoA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hD9kVliI; arc=none smtp.remote-ip=74.125.82.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44E8E606A32A for ; Mon, 30 Nov 2026 23:45:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 44E8E606A32A 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.a=rsa-sha256 header.s=20260707 header.b=hD9kVliI Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-1b589050416so4658068c88.0 for ; Mon, 30 Nov 2026 15:45:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796082337; x=1796687137; darn=vger.kernel.org; h=content-disposition:content-transfer-encoding:content-type :mime-version:references:in-reply-to:subject:cc:to:from:message-id :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=bKElIdQoBx+DcydNqLcup4euRNJWGxYoFaaceu8ZMxE=; b=hD9kVliI1mt+l/04hJUmCGRSiSUc4d/wC2VChO2lNeL+bs//fiOanCI3cmiApeSOYa G4O6C/roPm+P67XXGsJmIuUcV/9jf6dC2IoONLghHz+2SwlLb5ZeWGaowAAVDkrE0PFv SIcCcVRTwZ1/A4wGlPoPyGS0/y4k5e2Dyb4SR332ZZyiMl4+XHd0YDKbg3+mFHU7i/5+ 1SB8A/PNFXuggW15gw3SXuRFOVANDzUiu20qwUVCr61x6FQxXKwqvSJaF+86FCjJHfJW r/Bwfiaj6IhK2oZD+DcRcnHfWuDtE1Bz7B+tu1M6SgmKuswhVSAgnPlqVsJopyH/gMrc guTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796082337; x=1796687137; h=content-disposition:content-transfer-encoding:content-type :mime-version:references:in-reply-to:subject:cc:to:from:message-id :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=bKElIdQoBx+DcydNqLcup4euRNJWGxYoFaaceu8ZMxE=; b=ytmNlkiQc7KR1rFb/tz2btH40doxNyVv+vnyM1I5EB2UPATErg4/OB+AVKWFg1T9Eb 5snc8UnjQTOsF3TZBDAoIbJE9/XeIdmy3xbaLbdo57wTvSToesxM6paK8qo4s/dRdMwK 4uzB/9/xqnHm4Ub3a06dtmWhCtUdK60OGSqwIog3fJ+ay/mTvnv58vhbaDQP9fnOAdaC RFXppJHeHwDCBzqiUnjErHswI4T1z2/DikP/RP0VIp7ZgVliLrjgXwvn+d5pO2Y4kMxV XcboyB/ZDlRCdNUD/NSfpQ/z7/+9kA11qo3vkx4DYB80QWd5IaKMOL/baVSLEV47KI/N Gcsw== X-Forwarded-Encrypted: i=1; AL+hErE3P489A9Gb0Z1kXyvrsdV6DERCm7sR1nf36B/ShHNUz4gXxnMyPFXXkfVjYmh1p0E7duASzjmuJAQ43q0=@vger.kernel.org X-Gm-Message-State: APuU4Z/CJHlnHgLgBl8ddNAye2VYmXSCj7R5kCN8G5SWah4qx5KToJRS 9toYv89X32frprvCR916HUu8autKSOT75jrRRH8RyiUpl210eIHsvzZa X-Gm-Gg: AZFdTZfw7OIQpbGZZbCvhcoMP9EnDDsGHiZ/nXmvdT4FbUpqvpDwkn5lw7fXesqqE/6 qHobM5+RA1ai8JWCMKRDKuERFqpr5xjlA7FsSUIR1AlJuWaGLPZXHrcyd9Ko8PnlfZNoi472Mwu Kc81ytyTsbWMut6yNGPnlsyG8/E26Lio8zNRwQF5LRQ2UYKcAryhc9tMI1rI5Pml4ghf4ignx3M yhQCK/HqHhhPgVRStz1gQzYXP1Hcsi1r8WqkAUaKKdjwylg5x8Pli3ynen0Gh9ygERSPZS8L7CE vliQKP3Iwp1YbaajHefeymhYWKppi1N2M8xrR+OqT7QLKFDw8lkRB9foETv5NYFxxuPAC2YcHoD FGS+lQGLGIE6VWkdXcQA9Av3JMkPjZYngXHPZKruTwuy14ymUTMwsutVT3sT+5xZRFBFzHvLLdt fAhz1/FDoHegC7wAV2298TF4WJ1RKS5GvJTw3FUnfg9wDzuV0gHlgYq4Et7CkPmESSshE5swgKq aafl4mint9l3lnr96GeoJuqooec1Oc1H37vS3+kt0eNa3ZcbtanxfnKJT0dV4IUP90bgJ3aVaXe HrzSMc3RgB6TA75qiSOlMM9qx2NRwSpB8OFjbH7s+2eAQajtAbwVoFnkMMFfI1RLvHNh X-Received: by 2002:a05:7022:5f1c:b0:1b5:aa3f:5ed6 with SMTP id a92af1059eb24-1b5aa3f5fb9mr6094702c88.18.1796082337121; Mon, 30 Nov 2026 15:45:37 -0800 (PST) Received: from localhost ([2a00:79e0:2ebe:8:9f42:1ffe:38c8:d6a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b55681301asm81023453c88.8.2026.11.30.15.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 15:45:36 -0800 (PST) Date: Mon, 30 Nov 2026 15:45:35 -0800 Message-ID: From: Dmitry Torokhov To: Gui-Dong Han Cc: Dudley Du , Sakari Ailus , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com Subject: Re: [PATCH] Input: cyapa - publish PIP command state to the IRQ handler In-Reply-To: <20261130031927.557229-1-hanguidong02@gmail.com> References: <20261130031927.557229-1-hanguidong02@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Gui-Dong, On Mon, Nov 30, 2026 at 11:19:27AM +0800, Gui-Dong Han wrote: > Add smp_wmb() before atomic_inc(&pip->cmd_issued) in both command paths, > and use atomic_read_acquire(&pip->cmd_issued) in > cyapa_pip_irq_cmd_handler() to ensure the setup stores are visible once a > nonzero count is observed. > > Fixes: 6972a859601a ("Input: cyapa - add gen5 trackpad device basic functions support") > Signed-off-by: Gui-Dong Han Pairing a raw smp_wmb() plus atomic_inc() with atomic_read_acquire() is pretty awkward and asymmetric, and since commands are already serialized by cmd_lock, cmd_issued is really just a boolean flag rather than a counter. More importantly, adding barriers only papers over a bigger race on the error and timeout paths. cyapa_irq() is a threaded IRQ that sleeps in I2C reads inside cyapa_pip_irq_cmd_handler(). If a command write fails or times out while the handler is still running, the sender decrements cmd_issued, clears the response pointers, and returns (with the caller's stack response buffers going out of scope) without synchronizing with the IRQ thread. The handler can then dereference cleared/freed response pointers and run a second atomic_dec(), driving cmd_issued to -1 and permanently breaking touch reporting. Since cyapa_irq() already runs in thread context, I would prefer to drop the lockless atomic_t and manual barriers altogether and replace cmd_issued with a bool protected by a dedicated mutex separate from cmd_lock. Take it with guard()/scoped_guard() during setup, teardown, and timeout cancellation (without holding it across I2C writes, polling, or wait_for_completion_timeout(), and checking cmd_issued on timeout so a racing completion is not discarded), and hold it across cyapa_pip_irq_cmd_handler() so it is released before returning to cyapa_irq(). That handles memory ordering, the teardown races, and the -1 underflow together. Could you please rework and resubmit the patch along those lines? Thanks. -- Dmitry