diff mbox series

[v3,2/6] spi: spi-mtk-nor: fix mishandled logics in checking SPI memory operation

Message ID 20200925145255.v3.2.I48d59ef5398f3633c6ebbab093da6b4b06495780@changeid
State New
Headers show
Series spi: spi-mtk-nor: Add mt8192 support | expand

Commit Message

Ikjoon Jang Sept. 25, 2020, 6:54 a.m. UTC
Fix a bug which limits its protocol availability in supports_op().

Fixes: a59b2c7c56bf ("spi: spi-mtk-nor: support standard spi properties")
Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
---

(no changes since v1)

 drivers/spi/spi-mtk-nor.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

Comments

Ikjoon Jang Sept. 25, 2020, 9:36 a.m. UTC | #1
On Fri, Sep 25, 2020 at 2:54 PM Ikjoon Jang <ikjn@chromium.org> wrote:
>

> Fix a bug which limits its protocol availability in supports_op().

>

> Fixes: a59b2c7c56bf ("spi: spi-mtk-nor: support standard spi properties")

> Signed-off-by: Ikjoon Jang <ikjn@chromium.org>

> ---


This is also duplicated work of https://patchwork.kernel.org/patch/11797723/,
I'm going to drop this patch in v4.

>

> (no changes since v1)

>

>  drivers/spi/spi-mtk-nor.c | 26 +++++++++++---------------

>  1 file changed, 11 insertions(+), 15 deletions(-)

>

> diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c

> index 6e6ca2b8e6c8..0f7d4ec68730 100644

> --- a/drivers/spi/spi-mtk-nor.c

> +++ b/drivers/spi/spi-mtk-nor.c

> @@ -211,28 +211,24 @@ static bool mtk_nor_supports_op(struct spi_mem *mem,

>         if (op->cmd.buswidth != 1)

>                 return false;

>

> +       if (!spi_mem_default_supports_op(mem, op))

> +               return false;

> +

>         if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) {

> -               switch(op->data.dir) {

> -               case SPI_MEM_DATA_IN:

> -                       if (!mtk_nor_match_read(op))

> -                               return false;

> -                       break;

> -               case SPI_MEM_DATA_OUT:

> -                       if ((op->addr.buswidth != 1) ||

> -                           (op->dummy.nbytes != 0) ||

> -                           (op->data.buswidth != 1))

> -                               return false;

> -                       break;

> -               default:

> -                       break;

> -               }

> +               if ((op->data.dir == SPI_MEM_DATA_IN) && mtk_nor_match_read(op))

> +                       return true;

> +               else if (op->data.dir == SPI_MEM_DATA_OUT)

> +                       return (op->addr.buswidth == 1) &&

> +                              (op->dummy.nbytes == 0) &&

> +                              (op->data.buswidth == 1);

>         }

> +

>         len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;

>         if ((len > MTK_NOR_PRG_MAX_SIZE) ||

>             ((op->data.nbytes) && (len == MTK_NOR_PRG_MAX_SIZE)))

>                 return false;

>

> -       return spi_mem_default_supports_op(mem, op);

> +       return true;

>  }

>

>  static void mtk_nor_setup_bus(struct mtk_nor *sp, const struct spi_mem_op *op)

> --

> 2.28.0.681.g6f77f65b4e-goog

>
diff mbox series

Patch

diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
index 6e6ca2b8e6c8..0f7d4ec68730 100644
--- a/drivers/spi/spi-mtk-nor.c
+++ b/drivers/spi/spi-mtk-nor.c
@@ -211,28 +211,24 @@  static bool mtk_nor_supports_op(struct spi_mem *mem,
 	if (op->cmd.buswidth != 1)
 		return false;
 
+	if (!spi_mem_default_supports_op(mem, op))
+		return false;
+
 	if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) {
-		switch(op->data.dir) {
-		case SPI_MEM_DATA_IN:
-			if (!mtk_nor_match_read(op))
-				return false;
-			break;
-		case SPI_MEM_DATA_OUT:
-			if ((op->addr.buswidth != 1) ||
-			    (op->dummy.nbytes != 0) ||
-			    (op->data.buswidth != 1))
-				return false;
-			break;
-		default:
-			break;
-		}
+		if ((op->data.dir == SPI_MEM_DATA_IN) && mtk_nor_match_read(op))
+			return true;
+		else if (op->data.dir == SPI_MEM_DATA_OUT)
+			return (op->addr.buswidth == 1) &&
+			       (op->dummy.nbytes == 0) &&
+			       (op->data.buswidth == 1);
 	}
+
 	len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
 	if ((len > MTK_NOR_PRG_MAX_SIZE) ||
 	    ((op->data.nbytes) && (len == MTK_NOR_PRG_MAX_SIZE)))
 		return false;
 
-	return spi_mem_default_supports_op(mem, op);
+	return true;
 }
 
 static void mtk_nor_setup_bus(struct mtk_nor *sp, const struct spi_mem_op *op)