* [PATCH -next v3 RESEND] mtd: rawnand: Propagate error and simplify ternary operators for brcmstb_nand_wait_for_completion()
@ 2023-08-08 3:29 Ruan Jinjie
2023-08-08 22:32 ` William Zhang
2023-08-18 14:41 ` Miquel Raynal
0 siblings, 2 replies; 3+ messages in thread
From: Ruan Jinjie @ 2023-08-08 3:29 UTC (permalink / raw)
To: linux-mtd, Brian Norris, Kamal Dasu,
Broadcom internal kernel review list, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
Cc: ruanjinjie
As bcmnand_ctrl_poll_status() return negative errno, so return true if
sts < 0. The < 0 case does not exist for wait_for_completion_timeout(),
so return true if sts = 0 and zero otherwise. Both of the true return
of them can be considered as a -ETIMEDOUT err, so return -ETIMEDOUT
if err is true to propagate err from its caller.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
v3:
- Update the commit title and message.
- Do not change the return type from bool to int.
- Return -ETIMEDOUT if err is true.
v2:
- Update the commit title and message.
- Propagate the error instead of upon error.
---
drivers/mtd/nand/raw/brcmnand/brcmnand.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 03764b589ec5..440bef477930 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -1666,13 +1666,13 @@ static bool brcmstb_nand_wait_for_completion(struct nand_chip *chip)
disable_ctrl_irqs(ctrl);
sts = bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY,
NAND_CTRL_RDY, 0);
- err = (sts < 0) ? true : false;
+ err = sts < 0;
} else {
unsigned long timeo = msecs_to_jiffies(
NAND_POLL_STATUS_TIMEOUT_MS);
/* wait for completion interrupt */
sts = wait_for_completion_timeout(&ctrl->done, timeo);
- err = (sts <= 0) ? true : false;
+ err = !sts;
}
return err;
@@ -1688,6 +1688,7 @@ static int brcmnand_waitfunc(struct nand_chip *chip)
if (ctrl->cmd_pending)
err = brcmstb_nand_wait_for_completion(chip);
+ ctrl->cmd_pending = 0;
if (err) {
u32 cmd = brcmnand_read_reg(ctrl, BRCMNAND_CMD_START)
>> brcmnand_cmd_shift(ctrl);
@@ -1696,8 +1697,8 @@ static int brcmnand_waitfunc(struct nand_chip *chip)
"timeout waiting for command %#02x\n", cmd);
dev_err_ratelimited(ctrl->dev, "intfc status %08x\n",
brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS));
+ return -ETIMEDOUT;
}
- ctrl->cmd_pending = 0;
return brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS) &
INTFC_FLASH_STATUS;
}
--
2.34.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH -next v3 RESEND] mtd: rawnand: Propagate error and simplify ternary operators for brcmstb_nand_wait_for_completion()
2023-08-08 3:29 [PATCH -next v3 RESEND] mtd: rawnand: Propagate error and simplify ternary operators for brcmstb_nand_wait_for_completion() Ruan Jinjie
@ 2023-08-08 22:32 ` William Zhang
2023-08-18 14:41 ` Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: William Zhang @ 2023-08-08 22:32 UTC (permalink / raw)
To: Ruan Jinjie, linux-mtd, Brian Norris, Kamal Dasu,
Broadcom internal kernel review list, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
[-- Attachment #1.1: Type: text/plain, Size: 2396 bytes --]
On 08/07/2023 08:29 PM, 'Ruan Jinjie' via BCM-KERNEL-FEEDBACK-LIST,PDL
wrote:
> As bcmnand_ctrl_poll_status() return negative errno, so return true if
> sts < 0. The < 0 case does not exist for wait_for_completion_timeout(),
> so return true if sts = 0 and zero otherwise. Both of the true return
> of them can be considered as a -ETIMEDOUT err, so return -ETIMEDOUT
> if err is true to propagate err from its caller.
>
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> v3:
> - Update the commit title and message.
> - Do not change the return type from bool to int.
> - Return -ETIMEDOUT if err is true.
> v2:
> - Update the commit title and message.
> - Propagate the error instead of upon error.
> ---
> drivers/mtd/nand/raw/brcmnand/brcmnand.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> index 03764b589ec5..440bef477930 100644
> --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> @@ -1666,13 +1666,13 @@ static bool brcmstb_nand_wait_for_completion(struct nand_chip *chip)
> disable_ctrl_irqs(ctrl);
> sts = bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY,
> NAND_CTRL_RDY, 0);
> - err = (sts < 0) ? true : false;
> + err = sts < 0;
> } else {
> unsigned long timeo = msecs_to_jiffies(
> NAND_POLL_STATUS_TIMEOUT_MS);
> /* wait for completion interrupt */
> sts = wait_for_completion_timeout(&ctrl->done, timeo);
> - err = (sts <= 0) ? true : false;
> + err = !sts;
> }
>
> return err;
> @@ -1688,6 +1688,7 @@ static int brcmnand_waitfunc(struct nand_chip *chip)
> if (ctrl->cmd_pending)
> err = brcmstb_nand_wait_for_completion(chip);
>
> + ctrl->cmd_pending = 0;
> if (err) {
> u32 cmd = brcmnand_read_reg(ctrl, BRCMNAND_CMD_START)
> >> brcmnand_cmd_shift(ctrl);
> @@ -1696,8 +1697,8 @@ static int brcmnand_waitfunc(struct nand_chip *chip)
> "timeout waiting for command %#02x\n", cmd);
> dev_err_ratelimited(ctrl->dev, "intfc status %08x\n",
> brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS));
> + return -ETIMEDOUT;
> }
> - ctrl->cmd_pending = 0;
> return brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS) &
> INTFC_FLASH_STATUS;
> }
>
Reviewed-by: William Zhang <william.zhang@broadcom.com>
[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]
[-- Attachment #2: Type: text/plain, Size: 144 bytes --]
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next v3 RESEND] mtd: rawnand: Propagate error and simplify ternary operators for brcmstb_nand_wait_for_completion()
2023-08-08 3:29 [PATCH -next v3 RESEND] mtd: rawnand: Propagate error and simplify ternary operators for brcmstb_nand_wait_for_completion() Ruan Jinjie
2023-08-08 22:32 ` William Zhang
@ 2023-08-18 14:41 ` Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2023-08-18 14:41 UTC (permalink / raw)
To: Ruan Jinjie, linux-mtd, Brian Norris, Kamal Dasu,
Broadcom internal kernel review list, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
On Tue, 2023-08-08 at 03:29:43 UTC, Ruan Jinjie wrote:
> As bcmnand_ctrl_poll_status() return negative errno, so return true if
> sts < 0. The < 0 case does not exist for wait_for_completion_timeout(),
> so return true if sts = 0 and zero otherwise. Both of the true return
> of them can be considered as a -ETIMEDOUT err, so return -ETIMEDOUT
> if err is true to propagate err from its caller.
>
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> Reviewed-by: William Zhang <william.zhang@broadcom.com>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-18 14:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-08 3:29 [PATCH -next v3 RESEND] mtd: rawnand: Propagate error and simplify ternary operators for brcmstb_nand_wait_for_completion() Ruan Jinjie
2023-08-08 22:32 ` William Zhang
2023-08-18 14:41 ` Miquel Raynal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.