From patchwork Mon Jul 15 11:59:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13733363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C76AC3DA5D for ; Mon, 15 Jul 2024 11:59:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 0D1B3C4AF0F; Mon, 15 Jul 2024 11:59:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABDBAC4AF0A; Mon, 15 Jul 2024 11:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721044758; bh=O4uaxv7GHUzy/dI7jVG1XspnPohL9XyQ4MFsapoSjic=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMqkDTFbHLikOHr0PN5S9G7uUaeB9g+Ji3Ii3M1AuXvcjnESyVXrcaIo17U+uSUxu 0xS95IWWm45V37EpMpYP+Ar1h//Kju1GQSWwApYZqTMVH0Q6Fzd4JIQt74C0qOQFjI Fb5g3Qs30kAZJWBB69WSTR13Dg+aRHm3lnsT5m54o2/ljeLwrDnUefMYU1ArCxEoaR Hf5EmX4gengCWyb0H5wWR421Fjtk6Az/Kb5ONPMHDb3pXMGjGCgDVYu0StBfRPcz01 dYw1JPHVu12sQUId+6umhB1C+5aM6LpIQh62Ot22OnI2FVVaqLQ8XMU2cocJbhGcyN Q/sGP2ZXe6jow== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Arnd Bergmann , soc@kernel.org, arm@kernel.org Cc: =?utf-8?q?Marek_Beh=C3=BAn?= , Andy Shevchenko Subject: [PATCH 1/3] firmware: turris-mox-rwtm: Do not complete if there are no waiters Date: Mon, 15 Jul 2024 13:59:10 +0200 Message-ID: <20240715115912.9507-2-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715115912.9507-1-kabel@kernel.org> References: <20240715115912.9507-1-kabel@kernel.org> MIME-Version: 1.0 Do not complete the "command done" completion if there are no waiters. This can happen if a wait_for_completion() timed out or was interrupted. Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver") Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 31d962cdd6eb..f1f9160c4195 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -2,7 +2,7 @@ /* * Turris Mox rWTM firmware driver * - * Copyright (C) 2019 Marek Behún + * Copyright (C) 2019, 2024 Marek Behún */ #include @@ -174,6 +174,9 @@ static void mox_rwtm_rx_callback(struct mbox_client *cl, void *data) struct mox_rwtm *rwtm = dev_get_drvdata(cl->dev); struct armada_37xx_rwtm_rx_msg *msg = data; + if (completion_done(&rwtm->cmd_done)) + return; + rwtm->reply = *msg; complete(&rwtm->cmd_done); } From patchwork Mon Jul 15 11:59:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13733364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1829C3DA5E for ; Mon, 15 Jul 2024 11:59:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id E4058C4AF0E; Mon, 15 Jul 2024 11:59:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62CD3C4AF0B; Mon, 15 Jul 2024 11:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721044760; bh=b/RMi8pE1O8XodlWSP/qHTIDmSEE5TbkZW23gWQrxh4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJrZdxvMHZgLmhYHGs60jVqTkYmC+ga3gxmwpyZ5IDhTML6agzK5CMrTsfsD3rKoi bUjXpmYt/tBLjKTwAnoSBEL9vmWppaUNY8IXPH9a/6faYAwi+qKK/sVkyVX1bjeDgi bB4nlat9bph5KW7qhZG5teHaYNKy0PX7Mt1o93hrkMFUnxfI/TX95BAQhucWNv0oNO BEvav6hqkQBspjqKdU+3qwUJYLuQ5ePAqEG8QyIi+CInW4fPoZDfpC3UXnbFcTBFzy jxuYV7hgBaVAqZup6eUmyx5+IzrlHnAZUnSLwQSRFJ1nHCmRefOfIg5zpRJpj1KUOP mkxiWUaTnTMwg== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Arnd Bergmann , soc@kernel.org, arm@kernel.org Cc: =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?Ilpo_J=C3=A4r?= =?utf-8?q?vinen?= , Andy Shevchenko Subject: [PATCH 2/3] firmware: turris-mox-rwtm: Fix checking return value of wait_for_completion_timeout() Date: Mon, 15 Jul 2024 13:59:11 +0200 Message-ID: <20240715115912.9507-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715115912.9507-1-kabel@kernel.org> References: <20240715115912.9507-1-kabel@kernel.org> MIME-Version: 1.0 The wait_for_completion_timeout() function returns 0 if timed out, and a positive value if completed. Fix the usage of this function. Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver") Fixes: 2eab59cf0d20 ("firmware: turris-mox-rwtm: fail probing when firmware does not support hwrng") Signed-off-by: Marek Behún Reviewed-by: Ilpo Järvinen Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index f1f9160c4195..3f4758e03c81 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -202,9 +202,8 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) + return -ETIMEDOUT; ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval); if (ret == -ENODATA) { @@ -238,9 +237,8 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) + return -ETIMEDOUT; ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval); if (ret == -ENODATA) { @@ -277,9 +275,8 @@ static int check_get_random_support(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) + return -ETIMEDOUT; return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval); } From patchwork Mon Jul 15 11:59:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13733365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA38AC3DA59 for ; Mon, 15 Jul 2024 11:59:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 98D20C4AF0E; Mon, 15 Jul 2024 11:59:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46A38C4AF0B; Mon, 15 Jul 2024 11:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721044762; bh=udt9/WXU0333dsDexLSegt9f3/2x+UBO21YW0AgcJHI=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWz1lIzbQEXJC+KBYVd5XHFus9Cow0WdmuAaRmY6/eUlZpDgxb9c+jFCMF7ISh2nS wpEna6C7fNjGeyJ8mSdGjoHXrhqX3DGBamRKcd+a+carTX1DswvYNVWMF97BpYDNAi tOhgfQhyXcHv1CehSgHfsVObnx28LGT32d+OIebEML9zWpgtqWjc2liZODqciVwDrW 9EeWtrsmfXDU7kAWNIfdfpnvE4aOqrZlJOMbp+VhxZtObbeZL5QL2B5tMKq8wQymkE jyEQYUJK6F1LBmtMiqzxmwaAjZRf4tNT+kr9A7MEDpOnw49vxwoYQoeNlIKtEW/L+u hhTqY5MPq5TpA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Arnd Bergmann , soc@kernel.org, arm@kernel.org Cc: =?utf-8?q?Marek_Beh=C3=BAn?= , Andy Shevchenko Subject: [PATCH 3/3] firmware: turris-mox-rwtm: Initialize completion before mailbox Date: Mon, 15 Jul 2024 13:59:12 +0200 Message-ID: <20240715115912.9507-4-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715115912.9507-1-kabel@kernel.org> References: <20240715115912.9507-1-kabel@kernel.org> MIME-Version: 1.0 Initialize the completion before the mailbox channel is requested. Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver") Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 3f4758e03c81..3e7f186d239a 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -499,6 +499,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rwtm); mutex_init(&rwtm->busy); + init_completion(&rwtm->cmd_done); rwtm->mbox_client.dev = dev; rwtm->mbox_client.rx_callback = mox_rwtm_rx_callback; @@ -512,8 +513,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) goto remove_files; } - init_completion(&rwtm->cmd_done); - ret = mox_get_board_info(rwtm); if (ret < 0) dev_warn(dev, "Cannot read board information: %i\n", ret);