Skip to contentSkip to conversation

hw_random: timeriomem_rng: relax check on memory resource size

PATCH In review Daniel Mack 2 participants 2 messages Aug 31, 2019 – Sep 5, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw_random: timeriomem_rng: relax check on memory resource size

The timeriomem_rng driver only accesses the first 4 bytes of the given memory area and currently, it also forces that memory resource to be exactly 4 bytes in size.

This, however, is problematic when used with device-trees that are generated from things like FPGA toolchains, where the minimum size of an exposed memory block may be something like 4k.

Hence, let's only check for what's needed for the driver to operate properly; namely that we have enough memory available to read the random data from.

---
 Documentation/devicetree/bindings/rng/timeriomem_rng.txt | 2 +-
 drivers/char/hw_random/timeriomem-rng.c                  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/rng/timeriomem_rng.txt +1 -1
index 214940093b55..fb4846160047 100644
@@ -12,7 +12,7 @@ Optional properties:
             which disables using this rng to automatically fill the kernel's
             entropy pool.
 
-N.B. currently 'reg' must be four bytes wide and aligned
+N.B. currently 'reg' must be at least four bytes wide and 32-bit aligned
 
 Example:
 
drivers/char/hw_random/timeriomem-rng.c +2 -2
index f615684028af..dc0194d85d80 100644
@@ -120,9 +120,9 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
 	if (!res)
 		return -ENXIO;
 
-	if (res->start % 4 != 0 || resource_size(res) != 4) {
+	if (res->start % 4 != 0 || resource_size(res) < 4) {
 		dev_err(&pdev->dev,
-			"address must be four bytes wide and aligned\n");
+			"address must be at least four bytes wide and 32-bit aligned\n");
 		return -EINVAL;
 	}
 
Signature · 1 line
2.21.0
maintainer
#1 lore raw
Quoted 12 lines · Daniel Mack

The timeriomem_rng driver only accesses the first 4 bytes of the given memory area and currently, it also forces that memory resource to be exactly 4 bytes in size.

This, however, is problematic when used with device-trees that are generated from things like FPGA toolchains, where the minimum size of an exposed memory block may be something like 4k.

Hence, let's only check for what's needed for the driver to operate properly; namely that we have enough memory available to read the random data from.

Quoted 5 lines
---
 Documentation/devicetree/bindings/rng/timeriomem_rng.txt | 2 +-
 drivers/char/hw_random/timeriomem-rng.c                  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt