From: Conor Dooley <conor.dooley@microchip.com> To: Jassi Brar <jassisinghbrar@gmail.com> Cc: Conor Dooley <conor.dooley@microchip.com>, Daire McNamara <daire.mcnamara@microchip.com>, <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH v2 6/7] soc: microchip: mpfs: simplify error handling in mpfs_blocking_transaction() Date: Fri, 20 Jan 2023 14:37:34 +0000 [thread overview] Message-ID: <20230120143734.3438755-7-conor.dooley@microchip.com> (raw) In-Reply-To: <20230120143734.3438755-1-conor.dooley@microchip.com> The error handling has a kinda weird nested-if setup that is not really adding anything. Switch it to more of an early return arrangement as a predatory step for adding different handing for timeouts and failed services. Signed-off-by: Conor Dooley <conor.dooley@microchip.com> --- drivers/soc/microchip/mpfs-sys-controller.c | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c index e76a5e38f655..da9cfeda6f78 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -36,28 +36,26 @@ struct mpfs_sys_controller { int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, struct mpfs_mss_msg *msg) { unsigned long timeout = msecs_to_jiffies(MPFS_SYS_CTRL_TIMEOUT_MS); - int ret, err; + int ret; - err = mutex_lock_interruptible(&transaction_lock); - if (err) - return err; + ret = mutex_lock_interruptible(&transaction_lock); + if (ret) + return ret; reinit_completion(&sys_controller->c); ret = mbox_send_message(sys_controller->chan, msg); - if (ret >= 0) { - if (wait_for_completion_timeout(&sys_controller->c, timeout)) { - ret = 0; - } else { - ret = -ETIMEDOUT; - dev_warn(sys_controller->client.dev, - "MPFS sys controller transaction timeout\n"); - } - } else { - dev_err(sys_controller->client.dev, - "mpfs sys controller transaction returned %d\n", ret); + if (ret < 0) + goto out; + + ret = 0; /* mbox_send_message returns positive integers on success */ + if (!wait_for_completion_timeout(&sys_controller->c, timeout)) { + ret = -ETIMEDOUT; + dev_warn(sys_controller->client.dev, + "MPFS sys controller transaction timeout\n"); } +out: mutex_unlock(&transaction_lock); return ret; -- 2.39.0
WARNING: multiple messages have this Message-ID (diff)
From: Conor Dooley <conor.dooley@microchip.com> To: Jassi Brar <jassisinghbrar@gmail.com> Cc: Conor Dooley <conor.dooley@microchip.com>, Daire McNamara <daire.mcnamara@microchip.com>, <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH v2 6/7] soc: microchip: mpfs: simplify error handling in mpfs_blocking_transaction() Date: Fri, 20 Jan 2023 14:37:34 +0000 [thread overview] Message-ID: <20230120143734.3438755-7-conor.dooley@microchip.com> (raw) In-Reply-To: <20230120143734.3438755-1-conor.dooley@microchip.com> The error handling has a kinda weird nested-if setup that is not really adding anything. Switch it to more of an early return arrangement as a predatory step for adding different handing for timeouts and failed services. Signed-off-by: Conor Dooley <conor.dooley@microchip.com> --- drivers/soc/microchip/mpfs-sys-controller.c | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c index e76a5e38f655..da9cfeda6f78 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -36,28 +36,26 @@ struct mpfs_sys_controller { int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, struct mpfs_mss_msg *msg) { unsigned long timeout = msecs_to_jiffies(MPFS_SYS_CTRL_TIMEOUT_MS); - int ret, err; + int ret; - err = mutex_lock_interruptible(&transaction_lock); - if (err) - return err; + ret = mutex_lock_interruptible(&transaction_lock); + if (ret) + return ret; reinit_completion(&sys_controller->c); ret = mbox_send_message(sys_controller->chan, msg); - if (ret >= 0) { - if (wait_for_completion_timeout(&sys_controller->c, timeout)) { - ret = 0; - } else { - ret = -ETIMEDOUT; - dev_warn(sys_controller->client.dev, - "MPFS sys controller transaction timeout\n"); - } - } else { - dev_err(sys_controller->client.dev, - "mpfs sys controller transaction returned %d\n", ret); + if (ret < 0) + goto out; + + ret = 0; /* mbox_send_message returns positive integers on success */ + if (!wait_for_completion_timeout(&sys_controller->c, timeout)) { + ret = -ETIMEDOUT; + dev_warn(sys_controller->client.dev, + "MPFS sys controller transaction timeout\n"); } +out: mutex_unlock(&transaction_lock); return ret; -- 2.39.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2023-01-20 14:41 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-01-20 14:37 [PATCH v2 0/7] MPFS system controller/mailbox fixes Conor Dooley 2023-01-20 14:37 ` Conor Dooley 2023-01-20 14:37 ` [PATCH v2 1/7] mailbox: mpfs: fix an incorrect mask width Conor Dooley 2023-01-20 14:37 ` Conor Dooley 2023-01-20 14:37 ` [PATCH v2 2/7] mailbox: mpfs: switch to txdone_poll Conor Dooley 2023-01-20 14:37 ` Conor Dooley 2023-01-20 14:37 ` [PATCH v2 3/7] mailbox: mpfs: ditch a useless busy check Conor Dooley 2023-01-20 14:37 ` Conor Dooley 2023-01-20 14:37 ` [PATCH v2 4/7] soc: microchip: mpfs: fix some horrible alignment Conor Dooley 2023-01-20 14:37 ` Conor Dooley 2023-01-20 14:37 ` [PATCH v2 5/7] soc: microchip: mpfs: use a consistent completion timeout Conor Dooley 2023-01-20 14:37 ` Conor Dooley 2023-01-20 14:37 ` Conor Dooley [this message] 2023-01-20 14:37 ` [PATCH v2 6/7] soc: microchip: mpfs: simplify error handling in mpfs_blocking_transaction() Conor Dooley 2023-01-20 14:37 ` [PATCH v2 7/7] soc: microchip: mpfs: handle timeouts and failed services differently Conor Dooley 2023-01-20 14:37 ` Conor Dooley
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230120143734.3438755-7-conor.dooley@microchip.com \ --to=conor.dooley@microchip.com \ --cc=daire.mcnamara@microchip.com \ --cc=jassisinghbrar@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-riscv@lists.infradead.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.