From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342193; b=pI6Zw8AfUgjQV3tRSSYhZfY/ONhPe5EuBG5e5dR1+XnHRMh0FAH8y4buufDqQg1rNAqZ uxq+iqe0DhUGJ5a+66dveI3XHn0oErWoSMeqgK/0gUBIFesDHSjj2/QTGHfO6pFW1EpCE q5MMvKwj7kFuMQnf1Jj3LcRNPFxKeV4qPGAM/yLvauK5InojGW4KYiOFpx9mGbmGMvoDw S5GHC1rFmZgJIVh1aeG/MDdK9mI+ZBN4jOUXp13Iz0pu4fEf53VDqfsyjK5MwJoZYDapB h6H5F8eJrKoYPgrtMJk+Bs9shIqHk0F5k53EHaTkmWjof/ifZZFevZvcAkgnIGc/hkA== 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-Forwarded-Encrypted: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=djQ0ypcnKhm5jfI9kQcO5+m+7nI3WVtKvoEGuWUIuXG2ND3hFDTQ9uqCqXEX7VlwRBnO dZ9wc9oPDwsmWN0XvMy/finzb1+FfX3UxplH+JlOV+tUD2SqaWqEmz1X3567wly4f4SIj QfAP+ZDjhGVDc4wHalP1s+6cxdUcdxRh1ejxaCRB43ydS0JLkgQrskk2OryLxZ596eCkr hmOC2emoQujibzWjJCsCBVjjV5Lzdr6M2XJdkvIWU9O3KNPUo0RIOH7OT+qKHrWd+kuqV Rl54lnZYcEmNte/olAiDBoID6xQf89lTADABySX+lkfu5MoMg8wYp+mnQp1U8W84KAA== 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.178 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 4D525606A322 for ; Thu, 3 Dec 2026 23:56:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4D525606A322 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-f178.google.com with SMTP id d9443c01a7336-2efe591a1f6so1678705ad.2 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=oL/vxGGtzZxzGokD1yXQn7qr5Jf2SoLL6f33Z9RXIaFD2chrXAYYCW3ZpAUU6A8Cju 0vFCEy6NdzZJetqtvselZ9m/WchpZAgX5a+C7HwuxioVAwoyllc9iTA6MM6r2otZIWCd QbigGNiXL2m3bZ4l2jKBfjX1JLPZEzXaQPHFF9Rou3v1qCRq5d71ymnV3HNQSqShWgdM eXka0HWf9Jd+7PqPxgkmwxg6SPKRNoc8yrv1wX6N2KZhwVo7TE8fmc3+Xkn41zREEC2x uhjUhIsL27ndOKv0hGPrdXpOdH5V4Thn9fVrxtHYC3q0nrJeK+N7a24eKaHtARzpWjKr fSaQ== X-Forwarded-Encrypted: i=1; AL+hErHUnlc1xeSwh68GqQkgFN6bOWyR883BiJOVQhUnKae/IXllAMWmm7VtwMwUBLsdIl/TOP5B5u0=@vger.kernel.org X-Gm-Message-State: APuU4Z+QfN1pI4CpNzFhXf8gOPA+sjZBqINpm3RXXXsBxCEaJFPN2atW MnZ6SpbgsH/p+PYQhcgFMqzJi/JDIeNfA4Amw9vMHprYRM6PRlmxkwIw X-Gm-Gg: AZFdTZfcbIK3O6jMzi1K6IHWBy/dQA4J0YaRCuf0norDSe7Pk7JrMGfA7zsMfVT850l YmJgaNmY2lJNpBKAjr6Pg+bHtLyLEV659q9S3jvfDzxZVNlvTi6SRbCoWyvS8gWP+4deQCNhiOW qyYOdqf5zytLRkowpN0/1MsFWJO1PzkKqBe9aEjVqi6kHmqlYrBPJO0Eyjd4WYLxmR+6mC/OqPS ImVJ/EXUbt0O4SYpOOiqiFKF03g7E69xJbwUm9ZJdEii81PhL27uVkfID18LKsSKWO0Gaa91mwX 0pK1X4AemfH1V9/LHbwOpFGN3WWo8vBKjf7rEtjXIwjhFIoiyM7NEmBaew2aS3tM4Jd/zsO4zRf Kx5b2MY3VC6DvdRirdLFWiRxoGyv/vD0CM+tKrSTLEVuIpq+/zvWyRglLM/fQB8+0bvSNl8mnl+ r+McTpxnwPbjZt8NdbHRQ4LkxIbeIZ8li9nxE6IpBtyeyDJ8qJw9PSEN/CK1jDYRqVG/elBZ4w5 C5LtfB/+nUUv4ClHgAySUIWUbrw1EUZxM2UbkAaVe6dS1YtNGoEGiPlFJJMwRsybRMRIzwqPtzR oPZgayezPhu7Bc3NwAxNoIKYCUtsalHjGEFqWTDVN2lX8xvf217uL77KUHbNnod34nkNRu+GjLO wpvtNOZw6lfuu/dbFnmbfUtjVttu09K9NXQBsPfLMQABZIy7dSILMMLqqua5SWLmnilcttsGHj7 vZEl4swX2JrHvf/HgDE/XW2EOrO0hrkLqGVAWPKKkNtUNGWpBSvU/NgXQO/m9p35dAfA== 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: stable@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