From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342193; b=Gw6Zov41lqDftCNpAp1H36PqW1KBxynSI1Rok9o/VYj4bQ0hxFIr4y3G9P33G0gRrjZh Bn0U+F9tLvkE3cVx14mrhQ1ZfKWi76How6R/lBjg/0cJGJwNbaWWHtPcKzEpIGJAbjEb3 O7wwW/K7lkstAU/oMlR8+sgo1CjD5sEO6ljAu1M8gmB35Iv/7znOVlRPnR+VDIdlulKV3 KXYpxKvxqHZ3RXsO3Wh5vdi3sNdH+G4cOr3U85liB8tJO5g050Mqrhl6/8pRtKZ2N2Eer QYLsPPv51QmEJIn2XgRvTU7+F7Hq0YlbwQa/pku8U5f4H7bVZbKY0aIIKxq80KiXYJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342193; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=iIogYWagQPjF6VAkz/Rl6F2pjQEv9lR0RH6ZvFIji/8=; b=qpJMiFGzqFvAmHde1tnRkZ4mMmn/vnHocWZdjus+aiQCNhTU8OdKOBCNF+/rCrXEmRO3 B/2D4T1CkgkhNnOlfjsxcHiwWok3zi3ec9FeMHUcruHkCXdcY1LE9vRoVQyYboLazI5mp XvCX5KBi7deWDBtQ+UZ/sOPd5w/7CUsswMSbLrD2ZeGBKY//g+Y8jiEeoloVGs15MGwMc kehl2p7fVFziP/8BHiQ2TET6//U4Vhm4xCrjLaJaxN+L0ivZWGO0YKk+NAoEoVZacxUEg fgVrNKZBVhMWhX9Dhn88ApP5KwqNb+5oiB6ALqN0xJuB5S4tcJnUrStXP9lS2WaypWQ== 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=QHkyj5Wu; arc=none smtp.remote-ip=209.85.214.174 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 65C48606A32F for ; Thu, 3 Dec 2026 23:56:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65C48606A32F 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=QHkyj5Wu Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2f04b676219so2949955ad.0 for ; Thu, 03 Dec 2026 15:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796342192; x=1796946992; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iIogYWagQPjF6VAkz/Rl6F2pjQEv9lR0RH6ZvFIji/8=; b=QHkyj5WuvEPzBUSyc19yuR6dgTYvD+d+WirQYIYYOYZwqVyN4vupuGjuNQvz76LXJL DYhhOZnYuG9WEUnwoGRwRif4KzSFGB2b3XWV+lDwZflAbiMQggQkJVDXDkX+npdtapPn XAyU99qhwNlnrSK+tpB2/bCLmN+cLQjPx4uDm5cZN0OjHSj7f3xOrrkQMmUEIWTTFMCw PD8DGk0llYwf6pucSJMRHDf/b/2pZzNKIR/tQBABcuso2llmYP5iaZHVp8/iyxrOKXZH hNFVCEL/SaWCw156V7hkHdyE6QUQZionWWXBUR6vAzuQKe8VJ+Ut7wbK/4aGapfoKZ6w d4GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796342192; x=1796946992; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=iIogYWagQPjF6VAkz/Rl6F2pjQEv9lR0RH6ZvFIji/8=; b=Y46QXaVTAk92JaF2IyABsYleC+54szQ0UvvS9HBPtvqf0jvPMik9L4K+TbQCPXIF+V aB+4V3hBS4VkjqE769D8fB8fPL2ClqXldGIRmKD5pA/IpntwM2r6FS7r8AibJFrpC3rE 8ZGXJBFBpqfRJ66ZnXJlJuAe7XLoGpvV93sRn7q0TTww7dlijnJOnYQP2UCe5rwc51Gk pLBImmQrjHk4K8tQ0kXYb15bXfiYL51ier6kwxgZRMCvQcWr2usHfhIqBBkeIODetraq crusUWaPKPACrMyXJchm6POOlzTph6TAXIkeZHibVWDSV7spzNmNGwRyX7I5A211g/zr H0lQ== X-Gm-Message-State: APuU4Z9gNIfIjjHzEQ1hDpQrv5o4rY4+Q95NURteAZU6b7cPtcsh4kZs KxE1gwxRcMAXul48OnedIKwhm1TI8kcMwDKr6WPhXZjmdUQiilYSU1rEnLxVXRGj X-Gm-Gg: AZFdTZf/fqrSXPPs1cJ5hkfr+mSfQ9MTAKoiwYhnqmCPYl7UjSOlMkBBYC4j7pX/ld0 7VQeeMiSA+753Gu91OyVTgGNVm0Vne1+l3gMqbhuF243/eJwCcnLxiBBrcPNZtB22rLRvpnD8uw ENzSKpjuMI7p8Ql9PU4Ou3DztW2sf+/ebpi0krKHSrtY5X2w6MP+rDHw4bP3mx+DaqgDhD3Okhd +SVNJhR9P1c/iqIGV6bsuOljQKSIf9t30HuVt3+fNZE+I+0AvO6SUyKysrKMrQMgNaQiREfyT6D iF/JX/6EyeZAWekJi6+NP+NSDyp78WDZFi0dvw74Bmu/XX1UMG6VzNjXtdgiF/H4k2xi4Daon1/ 2SZf/zQeTP/qGUJasH/qY4aXPJ6DdN/SZm/i/Eop10bSPxfDXthNclx8D0gof9+JxW0T7gmYmqV fb+f3UVDbQVEk24kUlQ1GAeg5zD1E2kJ0jM28aKcBu8U3s/23Xj7T7Vnsbs9lcD7Mo3r37ddigk Le6momuRFb57ztekk64n8Q32JmFBKjyki/qp+nHLRy3KMT8BGwgmYKHrzl9/RbaJWc7u3saaI7e u8jbAnn67vp7RluGXk/avhmngxrV4tGB4Cst/hzmAvM1qsrHMJylEh7dgvBa3cBVwmThqhD+0CZ nW+/Vzxzr5aCezANn0dJi2BDtonOIHZLmvCyWSnUszZOTZOz+diDmmA9hAs0g4Fi13SN3kSuURy q8p5nC6tnPDeX14Ay2F8i045bkM7xmH7ojwmCvr1nH4X6K1Qq0XriaVzbRYC07crD5EA== X-Received: by 2002:a17:902:f641:b0:2ec:ff7f:6f1 with SMTP id d9443c01a7336-2f1ba12d050mr1783095ad.11.1796342192557; Thu, 03 Dec 2026 15:56:32 -0800 (PST) Received: from josephctchan-96c-1t.c.googlers.com.com (95.100.125.34.bc.googleusercontent.com. [34.125.100.95]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b7967a2bsm1660345ad.68.2026.12.03.15.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 15:56:32 -0800 (PST) From: Joseph CT Chan To: Mark Brown Cc: linux-spi@vger.kernel.org, David Lechner , Bart Van Assche , Joseph CT Chan , stable@vger.kernel.org Subject: [PATCH v3 2/5] spi: spi-mux: re-apply settings after child calls spi_setup() Date: Thu, 3 Dec 2026 23:56:22 +0000 Message-ID: <20261203235626.1437609-3-jctchan@gmail.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261203235626.1437609-1-jctchan@gmail.com> References: <20261203235626.1437609-1-jctchan@gmail.com> X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Joseph CT Chan spi_mux_select() copies a child's max_speed_hz, mode and bits_per_word into the spi-mux device and sets up the parent controller only when the mux switches to a different child (current_cs differs). If the child that is already selected changes its settings and calls spi_setup(), spi_mux_setup() only calls spi_setup() on the spi-mux device with its old settings, and current_cs still matches. The next transfers of that child then run with the old speed and mode. Set current_cs to SPI_MUX_NO_CS in spi_mux_setup(), so the next transfer copies the child's settings and sets up the parent again. spi_mux_setup() runs under the spi-mux controller's io_mutex, which the message pump holds while a message is forwarded, so this does not race with spi_mux_select(). The cost is one extra parent spi_setup() on the next transfer. Tested with KUnit (spi_mux: spi_mux_settings_lifecycle_test, added later in this series) on ARCH=um and x86_64; builds with W=1 on ARCH=um and x86_64. Not tested on hardware. Developed with help from the Claude and Gemini AI assistants. Fixes: e9e40543ad5b ("spi: Add generic SPI multiplexer") Cc: stable@vger.kernel.org Signed-off-by: Joseph CT Chan --- v3: Rebased on spi/for-7.5. drivers/spi/spi-mux.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/spi/spi-mux.c b/drivers/spi/spi-mux.c index 28d7718138a5..a7ea6585b374 100644 --- a/drivers/spi/spi-mux.c +++ b/drivers/spi/spi-mux.c @@ -86,7 +86,13 @@ static int spi_mux_setup(struct spi_device *spi) * can be called multiple times, won't do a valid setup now but we will * change the settings when we do a transfer (necessary because we * can't predict from which device it will be anyway) + * + * The child may have changed its settings, so make the next transfer + * copy them again even if this child is the current one. This runs + * under our io_mutex, so no message is being forwarded right now. */ + priv->current_cs = SPI_MUX_NO_CS; + return spi_setup(priv->spi); } -- 2.56.1.915.g69d5ec7298-goog