diff mbox series

[v2,1/2] crypto: qcom-rng: fix support for ACPI-based systems

Message ID 20240903212230.707376-2-bmasney@redhat.com (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series crypto: qcom-rng: fix support for ACPI-based systems | expand

Commit Message

Brian Masney Sept. 3, 2024, 9:22 p.m. UTC
The qcom-rng driver supports both ACPI and device tree based systems.
ACPI support was broken when the hw_random interface support was added.
Let's go ahead and fix this by adding a check for has_acpi_companion().

This fix was boot tested on a Qualcomm Amberwing server.

Fixes: f29cd5bb64c2 ("crypto: qcom-rng - Add hw_random interface support")
Reported-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
Closes: https://lore.kernel.org/linux-arm-msm/20240828184019.GA21181@eaf/
Cc: stable@vger.kernel.org
Signed-off-by: Brian Masney <bmasney@redhat.com>
---
Note: I looked at updating the struct qcom_rng_acpi_match to have
driver_data point to &qcom_prng_ee_of_data, however that won't work
since struct acpi_device_id has a driver_data member of type
kernel_ulong_t. struct of_device_id has the data member set to
type const void *. As I get available time, I'll look to see if
it's possible to migrate struct acpi_device_id.driver_data from
a kernel_ulong_t to a const void * to match what's done in
struct of_device_id. That will allow removing the has_acpi_companion()
check in the future. I suspect that change is not going to be trivial
though.

 drivers/crypto/qcom-rng.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

Comments

Brian Masney Sept. 4, 2024, 2:43 p.m. UTC | #1
On Tue, Sep 3, 2024 at 5:22 PM Brian Masney <bmasney@redhat.com> wrote:
> The qcom-rng driver supports both ACPI and device tree based systems.
> ACPI support was broken when the hw_random interface support was added.
> Let's go ahead and fix this by adding a check for has_acpi_companion().
>
> This fix was boot tested on a Qualcomm Amberwing server.
>
> Fixes: f29cd5bb64c2 ("crypto: qcom-rng - Add hw_random interface support")
> Reported-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
> Closes: https://lore.kernel.org/linux-arm-msm/20240828184019.GA21181@eaf/
> Cc: stable@vger.kernel.org
> Signed-off-by: Brian Masney <bmasney@redhat.com>

I found a cleaner and less intrusive way to fix this after looking
through some other drivers, so let me post a v3. Sorry about the
noise.

Brian
diff mbox series

Patch

diff --git a/drivers/crypto/qcom-rng.c b/drivers/crypto/qcom-rng.c
index c670d7d0c11e..7ba978f0ce8b 100644
--- a/drivers/crypto/qcom-rng.c
+++ b/drivers/crypto/qcom-rng.c
@@ -176,6 +176,21 @@  static struct rng_alg qcom_rng_alg = {
 	}
 };
 
+static struct qcom_rng_of_data qcom_prng_of_data = {
+	.skip_init = false,
+	.hwrng_support = false,
+};
+
+static struct qcom_rng_of_data qcom_prng_ee_of_data = {
+	.skip_init = true,
+	.hwrng_support = false,
+};
+
+static struct qcom_rng_of_data qcom_trng_of_data = {
+	.skip_init = true,
+	.hwrng_support = true,
+};
+
 static int qcom_rng_probe(struct platform_device *pdev)
 {
 	struct qcom_rng *rng;
@@ -196,7 +211,10 @@  static int qcom_rng_probe(struct platform_device *pdev)
 	if (IS_ERR(rng->clk))
 		return PTR_ERR(rng->clk);
 
-	rng->of_data = (struct qcom_rng_of_data *)of_device_get_match_data(&pdev->dev);
+	if (has_acpi_companion(&pdev->dev))
+		rng->of_data = &qcom_prng_ee_of_data;
+	else
+		rng->of_data = (struct qcom_rng_of_data *)of_device_get_match_data(&pdev->dev);
 
 	qcom_rng_dev = rng;
 	ret = crypto_register_rng(&qcom_rng_alg);
@@ -231,21 +249,6 @@  static void qcom_rng_remove(struct platform_device *pdev)
 	qcom_rng_dev = NULL;
 }
 
-static struct qcom_rng_of_data qcom_prng_of_data = {
-	.skip_init = false,
-	.hwrng_support = false,
-};
-
-static struct qcom_rng_of_data qcom_prng_ee_of_data = {
-	.skip_init = true,
-	.hwrng_support = false,
-};
-
-static struct qcom_rng_of_data qcom_trng_of_data = {
-	.skip_init = true,
-	.hwrng_support = true,
-};
-
 static const struct acpi_device_id __maybe_unused qcom_rng_acpi_match[] = {
 	{ .id = "QCOM8160", .driver_data = 1 },
 	{}