linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: xilinx: prevent probing on non-xilinx hardware
@ 2022-03-04  7:36 Corentin Labbe
  2022-03-09  3:22 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Corentin Labbe @ 2022-03-04  7:36 UTC (permalink / raw)
  To: davem, harsha.harsha, herbert, kalyani.akula, michal.simek
  Cc: linux-arm-kernel, linux-crypto, linux-kernel, Corentin Labbe

The zynqmp-sha driver is always loaded and register its algorithm even on
platform which do not have the proper hardware.
This lead to a stacktrace due to zynqmp-sha3-384 failing its crypto
self tests.
So check if hardware is present via the firmware API call get_version.

While at it, simplify the platform_driver by using module_platform_driver()

Furthermore the driver should depend on ZYNQMP_FIRMWARE since it cannot
work without it.

Fixes: 7ecc3e34474b ("crypto: xilinx - Add Xilinx SHA3 driver")
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
 drivers/crypto/Kconfig             |  2 +-
 drivers/crypto/xilinx/zynqmp-sha.c | 35 +++++++-----------------------
 2 files changed, 9 insertions(+), 28 deletions(-)

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 51df3cd9934f..52bb632a91d5 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -822,7 +822,7 @@ config CRYPTO_DEV_ZYNQMP_AES
 
 config CRYPTO_DEV_ZYNQMP_SHA3
 	bool "Support for Xilinx ZynqMP SHA3 hardware accelerator"
-	depends on ARCH_ZYNQMP
+	depends on ZYNQMP_FIRMWARE
 	select CRYPTO_SHA3
 	help
 	  Xilinx ZynqMP has SHA3 engine used for secure hash calculation.
diff --git a/drivers/crypto/xilinx/zynqmp-sha.c b/drivers/crypto/xilinx/zynqmp-sha.c
index 89549f4788ba..43ff170ff1c2 100644
--- a/drivers/crypto/xilinx/zynqmp-sha.c
+++ b/drivers/crypto/xilinx/zynqmp-sha.c
@@ -193,6 +193,13 @@ static int zynqmp_sha_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	int err;
+	u32 v;
+
+	/* Verify the hardware is present */
+	err = zynqmp_pm_get_api_version(&v);
+	if (err)
+		return err;
+
 
 	err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(ZYNQMP_DMA_BIT_MASK));
 	if (err < 0) {
@@ -251,33 +258,7 @@ static struct platform_driver zynqmp_sha_driver = {
 	},
 };
 
-static int __init sha_driver_init(void)
-{
-	struct platform_device *pdev;
-	int ret;
-
-	ret = platform_driver_register(&zynqmp_sha_driver);
-	if (ret)
-		return ret;
-
-	pdev = platform_device_register_simple(zynqmp_sha_driver.driver.name,
-					       0, NULL, 0);
-	if (IS_ERR(pdev)) {
-		ret = PTR_ERR(pdev);
-		platform_driver_unregister(&zynqmp_sha_driver);
-		pr_info("Failed to register ZynqMP SHA3 dvixe %d\n", ret);
-	}
-
-	return ret;
-}
-
-device_initcall(sha_driver_init);
-
-static void __exit sha_driver_exit(void)
-{
-	platform_driver_unregister(&zynqmp_sha_driver);
-}
-
+module_platform_driver(zynqmp_sha_driver);
 MODULE_DESCRIPTION("ZynqMP SHA3 hardware acceleration support.");
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Harsha <harsha.harsha@xilinx.com>");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: xilinx: prevent probing on non-xilinx hardware
  2022-03-04  7:36 [PATCH] crypto: xilinx: prevent probing on non-xilinx hardware Corentin Labbe
@ 2022-03-09  3:22 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2022-03-09  3:22 UTC (permalink / raw)
  To: Corentin Labbe
  Cc: davem, harsha.harsha, kalyani.akula, michal.simek,
	linux-arm-kernel, linux-crypto, linux-kernel

On Fri, Mar 04, 2022 at 07:36:48AM +0000, Corentin Labbe wrote:
> The zynqmp-sha driver is always loaded and register its algorithm even on
> platform which do not have the proper hardware.
> This lead to a stacktrace due to zynqmp-sha3-384 failing its crypto
> self tests.
> So check if hardware is present via the firmware API call get_version.
> 
> While at it, simplify the platform_driver by using module_platform_driver()
> 
> Furthermore the driver should depend on ZYNQMP_FIRMWARE since it cannot
> work without it.
> 
> Fixes: 7ecc3e34474b ("crypto: xilinx - Add Xilinx SHA3 driver")
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
>  drivers/crypto/Kconfig             |  2 +-
>  drivers/crypto/xilinx/zynqmp-sha.c | 35 +++++++-----------------------
>  2 files changed, 9 insertions(+), 28 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-09  3:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04  7:36 [PATCH] crypto: xilinx: prevent probing on non-xilinx hardware Corentin Labbe
2022-03-09  3:22 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).