From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796082338; b=Z4bTFPPoEeAp57VDDgqkWDH9lfWueou6aeLCC8IJUx4QWwpSnj36f64hkay/Tp8UpBr/ 3M2x2goTEr+Z9Lea3P9Sz1FgvWuGk43S+b206L+5uhSRp8omBLGB4slLHkxH0zdOeeQFG W6USf6pR/958W5FFtbfTbI2kfPMULCGXeNkXsY+lteT4GwVie/JY1lj+OxqyYkZoLGNzJ Bd8x0f2QNljhUh6dZUUl3oPEl9x7w9eltpnLJtpNBwwx2nORD0ta+PZ6RmPs0cRuDtMKa LuRPdq0O7vbSxudsZ+NTh55qzg1AeCHfGc1vXTkRum2KoTtEnbtKgvijoOE78or3i6Q== 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=4JfF+gKfus/QEvYulq4CfN3OAN5Nyitfbqb5NdrBBnzTfc9QfEvGlZsk6bGnGo40h6gR 92QAoB5sHPGKE10VrnTUO8eoRwvI0bpucBS+P9MyEJh4/A95SLZcY7la2ykuApqG9sz/a SD5tW0jCwHHWCU2OY2VwLIIIVc+BUd8HKU1vIXIilRYz8gpMWATar2/+NR4Dg5tugNDiz D5JHBDOdYcqiGH6Grmukl9KN2VKWmi3ak6cIsw3gDtW+ZOdsH0SoIux3rcg7w3S6E3Bwp ILL0El6qXvnmnfd4I/r8WPd4MzT1Vl+dnbH2eTKnUD7eGKh1HjS0r1/mKMB/uiNwoyw== 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.41 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (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 2C159606A32D for ; Mon, 30 Nov 2026 23:45:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2C159606A32D 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-f41.google.com with SMTP id a92af1059eb24-1b59dfe466bso4130126c88.1 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=Jwzfh1eYQNuEuRpM4ZPCHL3dSjntWFgitTxciyl6QyZ6O5Xx5YAX012w7fhrxTeKV6 giunTzFqfWRD7NTeSUUs4b9v+T693tlblhEMoiw3yTijeMIAUe9Tf5TeUsDkpsmB/zUu 3qcX7Cf0P9h6dk43cnSKiBTtBIZhpfsB2NqjWtNRJz+nOkGvjBY/fQxPjQY1JHCqpQlP D241UUEmpih4ZDGpkrVh8/bB6mEDErfN82Mdfh9sgLdw1wKyPoRi48jFYnLWLMX3Jq2T 3go6vIJWcUim2Ht3JJAe6WX/5L12FH6+aESPxpVtl7+P8x/m/FQbMl0z9Je0VTMS1Rcy HSPg== X-Forwarded-Encrypted: i=1; AL+hErEwskKkTK3xUjclBV9TZgjnJiB+MWFwz8XyRq0SAWlHig0LOEIePY3PUW250jsCGbK46zVISluoQG+0lg==@vger.kernel.org X-Gm-Message-State: APuU4Z9FqINgDxKPg65w0zVuKlZigKZsygvfGUTrPFXziFNXasS3FLMA sxAGx9W/1a+YM6sew3W2YizTcuQbs4cDGIRLWieaFXi2HPs8rrQhlzDQ X-Gm-Gg: AZFdTZef9oK5eyB1EPucDh4Pv8Xu13Lcsk4XJf/LemTQrdq9x/cAYOy5784EdVCscIt HDiwPS3y6Unzueew2K1M0CbVCVTcS1fjlrLrzZz7kQWr3uhzp8RqsYm7h7EWPz5j9n96QT0u0I6 72HTb5BF8R5O7rILpO+Ew6/wvso+Rvm2O/qaNNdTVdHIVXLEAjFm9JHS7dDxre+AwcXtASc2INV du80h+3H/XJ7KyL4kOET4MBpFO7Tke7TUdn7ZfSL0YJu48N8X0oqAoLrOE/4o4bA/BHoj4stSXY Ct5nvVCJgS+sUZ6uP7vXxOZcl++bIthDX/GGPtmkTxfy3rpLEPf9ao20MuWn1tbsIUkOzcUZ2oR SrccituGl+ZFKPeIU+XimZuaImv+qJh75FKJMbZFN2FkrwVm0bn8ermLIY/+zlhppV7tQxtjwQu +nDYvaJXpPhs1jLL2fuqtZUdstO/yaWlZImd4OzXTAUZnJanq8BPUocWy/OW6Hn416u9jtWNrBX 1ygCaXswd+Mm8DWlq5byjpfK76jX3wq7de6Ec2a4W59IH4vJQoF4GiZFbc2xVrZqJGSVXxPnxmD 9A7C/mKpKal3kp32jKxkJ939vAyeDNPoz7mxFUdO5uJKfo84VAtdMWdinz2tGDyV393d 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-input@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