public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] hwrng: core - drop unnecessary forward declarations
@ 2026-05-05  9:45 Thorsten Blum
  2026-05-05  9:45 ` [PATCH v2 2/4] hwrng: core - use bool for wait parameter in rng_get_data Thorsten Blum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-05-05  9:45 UTC (permalink / raw)
  To: Olivia Mackall, Herbert Xu, Lianjie Wang, David Laight,
	Jonathan McDowell
  Cc: Thorsten Blum, linux-crypto, linux-kernel

The forward declarations for drop_current_rng() and rng_get_data() are
not needed - remove them.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
No changes in patch 1/4.
---
 drivers/char/hw_random/core.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index aba92d777f72..68add1a97f31 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -54,13 +54,9 @@ module_param(default_quality, ushort, 0644);
 MODULE_PARM_DESC(default_quality,
 		 "default maximum entropy content of hwrng per 1024 bits of input");
 
-static void drop_current_rng(void);
 static int hwrng_init(struct hwrng *rng);
 static int hwrng_fillfn(void *unused);
 
-static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
-			       int wait);
-
 static size_t rng_buffer_size(void)
 {
 	return RNG_BUFFER_SIZE;

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

* [PATCH v2 2/4] hwrng: core - use bool for wait parameter in rng_get_data
  2026-05-05  9:45 [PATCH v2 1/4] hwrng: core - drop unnecessary forward declarations Thorsten Blum
@ 2026-05-05  9:45 ` Thorsten Blum
  2026-05-05  9:45 ` [PATCH v2 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE Thorsten Blum
  2026-05-05  9:45 ` [PATCH v2 4/4] hwrng: core - use sysfs_emit_at in rng_available_show Thorsten Blum
  2 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-05-05  9:45 UTC (permalink / raw)
  To: Olivia Mackall, Herbert Xu, David Laight, Jonathan McDowell,
	Lianjie Wang
  Cc: Thorsten Blum, linux-crypto, linux-kernel

The wait parameter in rng_get_data() is a boolean flag - use bool
instead of int to better reflect its actual type.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Formatting changes only as suggested by Andy.
---
 drivers/char/hw_random/core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 68add1a97f31..870e77c9ec20 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -210,8 +210,8 @@ static int rng_dev_open(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
-			int wait) {
+static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size, bool wait)
+{
 	int present;
 
 	BUG_ON(!mutex_is_locked(&reading_mutex));
@@ -534,8 +534,7 @@ static int hwrng_fillfn(void *unused)
 		}
 
 		mutex_lock(&reading_mutex);
-		rc = rng_get_data(rng, rng_fillbuf,
-				  rng_buffer_size(), 1);
+		rc = rng_get_data(rng, rng_fillbuf, rng_buffer_size(), true);
 		if (current_quality != rng->quality)
 			rng->quality = current_quality; /* obsolete */
 		quality = rng->quality;

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

* [PATCH v2 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE
  2026-05-05  9:45 [PATCH v2 1/4] hwrng: core - drop unnecessary forward declarations Thorsten Blum
  2026-05-05  9:45 ` [PATCH v2 2/4] hwrng: core - use bool for wait parameter in rng_get_data Thorsten Blum
@ 2026-05-05  9:45 ` Thorsten Blum
  2026-05-05  9:45 ` [PATCH v2 4/4] hwrng: core - use sysfs_emit_at in rng_available_show Thorsten Blum
  2 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-05-05  9:45 UTC (permalink / raw)
  To: Olivia Mackall, Herbert Xu, Lianjie Wang, David Laight,
	Jonathan McDowell
  Cc: Thorsten Blum, linux-crypto, linux-kernel

Replace the open-coded variant with MAX().

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Drop the explicit include as suggested by Herbert.
---
 drivers/char/hw_random/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 870e77c9ec20..26c46cd90a83 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -30,7 +30,7 @@
 
 #define RNG_MODULE_NAME		"hw_random"
 
-#define RNG_BUFFER_SIZE (SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES)
+#define RNG_BUFFER_SIZE		MAX(32, SMP_CACHE_BYTES)
 
 static struct hwrng __rcu *current_rng;
 /* the current rng has been explicitly chosen by user via sysfs */

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

* [PATCH v2 4/4] hwrng: core - use sysfs_emit_at in rng_available_show
  2026-05-05  9:45 [PATCH v2 1/4] hwrng: core - drop unnecessary forward declarations Thorsten Blum
  2026-05-05  9:45 ` [PATCH v2 2/4] hwrng: core - use bool for wait parameter in rng_get_data Thorsten Blum
  2026-05-05  9:45 ` [PATCH v2 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE Thorsten Blum
@ 2026-05-05  9:45 ` Thorsten Blum
  2 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-05-05  9:45 UTC (permalink / raw)
  To: Olivia Mackall, Herbert Xu, Lianjie Wang, Jonathan McDowell,
	David Laight
  Cc: Thorsten Blum, Andy Shevchenko, linux-crypto, linux-kernel

Replace strlcat() with sysfs_emit_at() in rng_available_show() and add
'int len' to keep track of the number of bytes written. sysfs_emit_at()
is preferred for formatting sysfs output because it provides safer
bounds checking.

Inline mutex_lock_interruptible() and drop the now-unused local error
variable. Remove the unnecessary 'buf' NUL initialization. Return 'len'
directly instead of strlen(buf).

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
No changes in patch 4/4.
---
 drivers/char/hw_random/core.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 26c46cd90a83..6931657ad2ca 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -25,6 +25,7 @@
 #include <linux/sched/signal.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/sysfs.h>
 #include <linux/uaccess.h>
 #include <linux/workqueue.h>
 
@@ -414,21 +415,17 @@ static ssize_t rng_available_show(struct device *dev,
 				  struct device_attribute *attr,
 				  char *buf)
 {
-	int err;
 	struct hwrng *rng;
+	int len = 0;
 
-	err = mutex_lock_interruptible(&rng_mutex);
-	if (err)
+	if (mutex_lock_interruptible(&rng_mutex))
 		return -ERESTARTSYS;
-	buf[0] = '\0';
-	list_for_each_entry(rng, &rng_list, list) {
-		strlcat(buf, rng->name, PAGE_SIZE);
-		strlcat(buf, " ", PAGE_SIZE);
-	}
-	strlcat(buf, "none\n", PAGE_SIZE);
+	list_for_each_entry(rng, &rng_list, list)
+		len += sysfs_emit_at(buf, len, "%s ", rng->name);
+	len += sysfs_emit_at(buf, len, "none\n");
 	mutex_unlock(&rng_mutex);
 
-	return strlen(buf);
+	return len;
 }
 
 static ssize_t rng_selected_show(struct device *dev,

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

end of thread, other threads:[~2026-05-05  9:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-05  9:45 [PATCH v2 1/4] hwrng: core - drop unnecessary forward declarations Thorsten Blum
2026-05-05  9:45 ` [PATCH v2 2/4] hwrng: core - use bool for wait parameter in rng_get_data Thorsten Blum
2026-05-05  9:45 ` [PATCH v2 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE Thorsten Blum
2026-05-05  9:45 ` [PATCH v2 4/4] hwrng: core - use sysfs_emit_at in rng_available_show Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox