diff mbox series

mtd: rawnand: arasan: Fix double assertion of chip-select

Message ID Z0Iq9ex25MkwC_Cm@UBUNTU-PF54DSY0
State New
Headers show
Series mtd: rawnand: arasan: Fix double assertion of chip-select | expand

Commit Message

Maciej Andrzejewski Nov. 23, 2024, 7:20 p.m. UTC
When two chip-selects are configured in the device tree, and the second is
a non-native GPIO, both the GPIO-based chip-select and the first native
chip-select may be asserted simultaneously. This double assertion causes
incorrect read and write operations.

The issue occurs because when nfc->ncs <= 2, nfc->spare_cs is always
initialized to 0 due to static initialization. Consequently, when the
second chip-select (GPIO-based) is selected in anfc_assert_cs(), it is
detected by anfc_is_gpio_cs(), and nfc->native_cs is assigned the value 0.
This results in both the GPIO-based chip-select being asserted and the
NAND controller register receiving 0, erroneously selecting the native
chip-select.

This patch resolves the issue, as confirmed by oscilloscope testing with
configurations involving two or more chip-selects in the device tree.

Signed-off-by: Maciej Andrzejewski <maciej.andrzejewski@m-works.net>
---
 drivers/mtd/nand/raw/arasan-nand-controller.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Miquel Raynal Nov. 24, 2024, 11:54 a.m. UTC | #1
Hi Maciej,

On 23/11/2024 at 20:20:21 +01, Maciej Andrzejewski <maciej.andrzejewski@m-works.net> wrote:

> When two chip-selects are configured in the device tree, and the second is
> a non-native GPIO, both the GPIO-based chip-select and the first native
> chip-select may be asserted simultaneously. This double assertion causes
> incorrect read and write operations.
>
> The issue occurs because when nfc->ncs <= 2, nfc->spare_cs is always
> initialized to 0 due to static initialization. Consequently, when the
> second chip-select (GPIO-based) is selected in anfc_assert_cs(), it is
> detected by anfc_is_gpio_cs(), and nfc->native_cs is assigned the value 0.
> This results in both the GPIO-based chip-select being asserted and the
> NAND controller register receiving 0, erroneously selecting the native
> chip-select.
>
> This patch resolves the issue, as confirmed by oscilloscope testing with
> configurations involving two or more chip-selects in the device tree.
>

Ok to me, can you please send a v2 with correct Fixes and Cc: stable
tags, please?

Thanks,
Miquèl
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c b/drivers/mtd/nand/raw/arasan-nand-controller.c
index 5436ec4a8fde..7c97f421e382 100644
--- a/drivers/mtd/nand/raw/arasan-nand-controller.c
+++ b/drivers/mtd/nand/raw/arasan-nand-controller.c
@@ -1409,8 +1409,8 @@  static int anfc_parse_cs(struct arasan_nfc *nfc)
 	 * case, the "not" chosen CS is assigned to nfc->spare_cs and selected
 	 * whenever a GPIO CS must be asserted.
 	 */
-	if (nfc->cs_array && nfc->ncs > 2) {
-		if (!nfc->cs_array[0] && !nfc->cs_array[1]) {
+	if (nfc->cs_array) {
+		if (nfc->ncs > 2 && !nfc->cs_array[0] && !nfc->cs_array[1]) {
 			dev_err(nfc->dev,
 				"Assign a single native CS when using GPIOs\n");
 			return -EINVAL;