From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794064592; b=W1RsmFVA6fVnmTtevdqZMfKE3KgDkc1rjdaSX/dB/I1N8K+Xw8jvw72XPmnKQGhPnTKK +PbTCQwFufMbSMXkqt4VxH0HMk2NmKl7ShG3s57I5/glb35EPqSjQMc7ir+7yXHquhDLT xOammXac/n9Zkcol8j3Mkkn9vRFZYXdmdODKLRvC5GuJOKhZyMp7HsEEMImwozVQyWNdD /9LyPLLHJJScc9Z0U/prKe5R5W+7T84NSgcJz//Xhe/ziaNW5zp5kv9gAAc98oT4+6qH7 COOdZvGt5VF0vd96J5MzDPHbRUP44oFKJY8IMO9+EvIbFLVaiG7mQ4C/oLB7zbbXwag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794064592; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=U8KxXWaa0RGjRrAd40ni9lKqXcMFxZLHcJpPq7vxeu4=; b=uDeqtgW/p0vjeTwE2+G4eryvoxsFwml5jJm6dD1TZIDRiQQ19j8e8YcX2pRpWT3xqgIo RyNwEUpmY+HELIqD+ePWNY99FsfiWh5s8ZzpBpGH+sfyJZetWNNYj45I8CbcV9pE5Aamh 7fc6BTV0A+OYE5PgQSKQQUdnPsomavNnrAIAWSc7lRXEMmWirfku6WQluheM6Urd1qCT8 fsZAerGZ0rDLTSSs8DZnGikumg8WZy8J+Z8BIzSUSWQDhBWATvdO8kGnllntx3Up+ixfk MI3IRieqkXdIfbFIaUIj2Pbyv6b4aj0ScTIEFcaRR3gzfDP4EMww9XROYA0dopNQ2pQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uDtSA0O1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFF6D606A9C0; Sat, 7 Nov 2026 15:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uDtSA0O1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 590EB1F0089F; Sat, 7 Nov 2026 15:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794064591; bh=U8KxXWaa0RGjRrAd40ni9lKqXcMFxZLHcJpPq7vxeu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uDtSA0O1XU3NWlYi9cUTlh3PiLAbmKx0WZTibCLe5JoPxOE1zaZ9MD8LdoCRACd2L lBLK7bKpbrMQ5EmVzZDVE4Uso+V1MBfgxCwPMD4fJpEJFJ80LD5s5zmgsHtc+klVDg GYD6GiQPMiLpUsDLjsDKB3U/uOZhp0T5jHrqgGEk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Miquel Raynal , Alexey Charkov , Srinivas Kandagatla , Sasha Levin Subject: [PATCH 7.3 0607/1257] nvmem: rockchip-otp: Serialize reads Date: Sat, 7 Nov 2026 08:48:23 -0500 Message-ID: <20261107134956.078081020@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134939.434104957@linuxfoundation.org> References: <20261107134939.434104957@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Charkov [ Upstream commit 9fc6a1592d844c0397f115ee8cbd935169b9a71e ] The OTP controller is driven through a single set of registers holding a state machine which has to be stepped through for every word read, yet nothing keeps two readers out of each other's way. Concurrent reads interleave, and the outcome is either a reader bailing out: rockchip-otp 2a580000.otp: timeout during read setup or, worse, one of them silently taking delivery of the other's data. Reading two cells in parallel from userspace on RK3576 reproduces both within 150 iterations - 53 read errors and 9 corrupted results, the latter either losing their first word or, in one case, ending in the two bytes which belong to the other reader's cell - whereas the same reads issued sequentially never fail. Concurrency is not hypothetical here, as six thermal sensors source their trim values from the OTP and reach the driver straight from asynchronous driver probing. Guard the read path with a mutex. Reads are the only way into the hardware, as the driver registers no write callback, and they always run in process context, so a plain mutex spanning the whole clock-enable, read, clock-disable sequence is enough. Fixes: 755864feb729 ("nvmem: add Rockchip OTP driver") Cc: stable@vger.kernel.org Reviewed-by: Miquel Raynal Signed-off-by: Alexey Charkov Signed-off-by: Srinivas Kandagatla Link: https://patch.msgid.link/20261002101329.1084348-2-srini@kernel.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/nvmem/rockchip-otp.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/rockchip-otp.c b/drivers/nvmem/rockchip-otp.c index 2c0feb036f3fd..f8a8c7cece98d 100644 --- a/drivers/nvmem/rockchip-otp.c +++ b/drivers/nvmem/rockchip-otp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,8 @@ struct rockchip_otp { void __iomem *base; struct reset_control *rst; const struct rockchip_data *data; + /* Serializes access to the OTP controller state machine */ + struct mutex mutex; struct clk_bulk_data clks[]; }; @@ -272,10 +275,12 @@ static int rockchip_otp_read(void *context, unsigned int offset, if (!otp->data || !otp->data->reg_read) return -EINVAL; + mutex_lock(&otp->mutex); + ret = clk_bulk_prepare_enable(otp->data->num_clks, otp->clks); if (ret < 0) { dev_err(otp->dev, "failed to prepare/enable clks\n"); - return ret; + goto unlock; } offset += otp->data->read_offset; @@ -308,6 +313,9 @@ static int rockchip_otp_read(void *context, unsigned int offset, err: clk_bulk_disable_unprepare(otp->data->num_clks, otp->clks); +unlock: + mutex_unlock(&otp->mutex); + return ret; } @@ -431,6 +439,11 @@ static int rockchip_otp_probe(struct platform_device *pdev) otp->data = data; otp->dev = dev; + + ret = devm_mutex_init(dev, &otp->mutex); + if (ret) + return ret; + otp->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(otp->base)) return dev_err_probe(dev, PTR_ERR(otp->base), -- 2.53.0