* [PATCH 2/4] hwrng: core - use bool for wait parameter in rng_get_data
2026-04-30 11:00 [PATCH 1/4] hwrng: core - drop unnecessary forward declarations Thorsten Blum
@ 2026-04-30 11:00 ` Thorsten Blum
2026-05-04 13:54 ` Andy Shevchenko
2026-04-30 11:00 ` [PATCH 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE Thorsten Blum
2026-04-30 11:00 ` [PATCH 4/4] hwrng: core - use sysfs_emit_at in rng_available_show Thorsten Blum
2 siblings, 1 reply; 10+ messages in thread
From: Thorsten Blum @ 2026-04-30 11:00 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu; +Cc: linux-crypto, linux-kernel, Thorsten Blum
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>
---
drivers/char/hw_random/core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 68add1a97f31..905a63525831 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -211,7 +211,7 @@ static int rng_dev_open(struct inode *inode, struct file *filp)
}
static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
- int wait) {
+ 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] 10+ messages in thread* Re: [PATCH 2/4] hwrng: core - use bool for wait parameter in rng_get_data
2026-04-30 11:00 ` [PATCH 2/4] hwrng: core - use bool for wait parameter in rng_get_data Thorsten Blum
@ 2026-05-04 13:54 ` Andy Shevchenko
2026-05-04 14:37 ` Thorsten Blum
0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-05-04 13:54 UTC (permalink / raw)
To: Thorsten Blum; +Cc: Olivia Mackall, Herbert Xu, linux-crypto, linux-kernel
On Thu, Apr 30, 2026 at 01:00:49PM +0200, Thorsten Blum wrote:
> The 'wait' parameter in rng_get_data() is a boolean flag - use bool
> instead of int to better reflect its actual type.
...
> static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
> - int wait) {
> + bool wait) {
You want to fix the checkpatch warnings while at it and indentation.
static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
bool wait)
{
...
> - rc = rng_get_data(rng, rng_fillbuf,
> - rng_buffer_size(), 1);
> + rc = rng_get_data(rng, rng_fillbuf, rng_buffer_size(), true);
Is it the only user? Why parameter is needed at all?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 2/4] hwrng: core - use bool for wait parameter in rng_get_data
2026-05-04 13:54 ` Andy Shevchenko
@ 2026-05-04 14:37 ` Thorsten Blum
2026-05-04 14:44 ` Andy Shevchenko
0 siblings, 1 reply; 10+ messages in thread
From: Thorsten Blum @ 2026-05-04 14:37 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Olivia Mackall, Herbert Xu, linux-crypto, linux-kernel
On Mon, May 04, 2026 at 03:54:14PM +0200, Andy Shevchenko wrote:
> On Thu, Apr 30, 2026 at 01:00:49PM +0200, Thorsten Blum wrote:
> > The 'wait' parameter in rng_get_data() is a boolean flag - use bool
> > instead of int to better reflect its actual type.
>
> ...
>
> > static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
> > - int wait) {
> > + bool wait) {
>
> You want to fix the checkpatch warnings while at it and indentation.
I just checked again, but I don't get any checkpatch warnings.
> static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
> bool wait)
> {
>
> ...
>
> > - rc = rng_get_data(rng, rng_fillbuf,
> > - rng_buffer_size(), 1);
> > + rc = rng_get_data(rng, rng_fillbuf, rng_buffer_size(), true);
>
> Is it the only user? Why parameter is needed at all?
The other one in rng_dev_read() already uses a boolean expression, hence
no changes.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 2/4] hwrng: core - use bool for wait parameter in rng_get_data
2026-05-04 14:37 ` Thorsten Blum
@ 2026-05-04 14:44 ` Andy Shevchenko
0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-05-04 14:44 UTC (permalink / raw)
To: Thorsten Blum; +Cc: Olivia Mackall, Herbert Xu, linux-crypto, linux-kernel
On Mon, May 04, 2026 at 04:37:17PM +0200, Thorsten Blum wrote:
> On Mon, May 04, 2026 at 03:54:14PM +0200, Andy Shevchenko wrote:
> > On Thu, Apr 30, 2026 at 01:00:49PM +0200, Thorsten Blum wrote:
...
> > > static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
> > > - int wait) {
> > > + bool wait) {
> >
> > You want to fix the checkpatch warnings while at it and indentation.
>
> I just checked again, but I don't get any checkpatch warnings.
Hmm... I remember for sure that checkpatch warns when it's a { on the line of
the prototype... Maybe it's about different scenario. Whatever, the coding
style is to have { on the new line.
...
> > > - rc = rng_get_data(rng, rng_fillbuf,
> > > - rng_buffer_size(), 1);
> > > + rc = rng_get_data(rng, rng_fillbuf, rng_buffer_size(), true);
> >
> > Is it the only user? Why parameter is needed at all?
>
> The other one in rng_dev_read() already uses a boolean expression, hence
> no changes.
Good, thanks for clarification.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE
2026-04-30 11:00 [PATCH 1/4] hwrng: core - drop unnecessary forward declarations Thorsten Blum
2026-04-30 11:00 ` [PATCH 2/4] hwrng: core - use bool for wait parameter in rng_get_data Thorsten Blum
@ 2026-04-30 11:00 ` Thorsten Blum
2026-05-04 13:56 ` Andy Shevchenko
2026-05-05 5:33 ` Herbert Xu
2026-04-30 11:00 ` [PATCH 4/4] hwrng: core - use sysfs_emit_at in rng_available_show Thorsten Blum
2 siblings, 2 replies; 10+ messages in thread
From: Thorsten Blum @ 2026-04-30 11:00 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu; +Cc: linux-crypto, linux-kernel, Thorsten Blum
Replace the open-coded variant with MAX().
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/char/hw_random/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 905a63525831..f8f7a2ee73c1 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -17,6 +17,7 @@
#include <linux/hw_random.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
+#include <linux/minmax.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/random.h>
@@ -30,7 +31,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] 10+ messages in thread
* Re: [PATCH 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE
2026-04-30 11:00 ` [PATCH 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE Thorsten Blum
@ 2026-05-04 13:56 ` Andy Shevchenko
2026-05-05 5:33 ` Herbert Xu
1 sibling, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-05-04 13:56 UTC (permalink / raw)
To: Thorsten Blum; +Cc: Olivia Mackall, Herbert Xu, linux-crypto, linux-kernel
On Thu, Apr 30, 2026 at 01:00:50PM +0200, Thorsten Blum wrote:
> Replace the open-coded variant with MAX().
Hmm... While this patch is correct the very similar is being used
outside of hwrng. Can we perhaps have a common definition somewhere
near to SMP_CACHE_BYTES?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE
2026-04-30 11:00 ` [PATCH 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE Thorsten Blum
2026-05-04 13:56 ` Andy Shevchenko
@ 2026-05-05 5:33 ` Herbert Xu
1 sibling, 0 replies; 10+ messages in thread
From: Herbert Xu @ 2026-05-05 5:33 UTC (permalink / raw)
To: Thorsten Blum; +Cc: Olivia Mackall, linux-crypto, linux-kernel
On Thu, Apr 30, 2026 at 01:00:50PM +0200, Thorsten Blum wrote:
> Replace the open-coded variant with MAX().
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/char/hw_random/core.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
> index 905a63525831..f8f7a2ee73c1 100644
> --- a/drivers/char/hw_random/core.c
> +++ b/drivers/char/hw_random/core.c
> @@ -17,6 +17,7 @@
> #include <linux/hw_random.h>
> #include <linux/kernel.h>
> #include <linux/kthread.h>
> +#include <linux/minmax.h>
No need for minmax.h because kernel.h already includes it.
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] 10+ messages in thread
* [PATCH 4/4] hwrng: core - use sysfs_emit_at in rng_available_show
2026-04-30 11:00 [PATCH 1/4] hwrng: core - drop unnecessary forward declarations Thorsten Blum
2026-04-30 11:00 ` [PATCH 2/4] hwrng: core - use bool for wait parameter in rng_get_data Thorsten Blum
2026-04-30 11:00 ` [PATCH 3/4] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE Thorsten Blum
@ 2026-04-30 11:00 ` Thorsten Blum
2026-05-04 13:58 ` Andy Shevchenko
2 siblings, 1 reply; 10+ messages in thread
From: Thorsten Blum @ 2026-04-30 11:00 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu; +Cc: linux-crypto, linux-kernel, Thorsten Blum
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).
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
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 f8f7a2ee73c1..1d1ea4ebde31 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -26,6 +26,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>
@@ -415,21 +416,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] 10+ messages in thread* Re: [PATCH 4/4] hwrng: core - use sysfs_emit_at in rng_available_show
2026-04-30 11:00 ` [PATCH 4/4] hwrng: core - use sysfs_emit_at in rng_available_show Thorsten Blum
@ 2026-05-04 13:58 ` Andy Shevchenko
0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-05-04 13:58 UTC (permalink / raw)
To: Thorsten Blum; +Cc: Olivia Mackall, Herbert Xu, linux-crypto, linux-kernel
On Thu, Apr 30, 2026 at 01:00:51PM +0200, Thorsten Blum wrote:
> 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).
This is almost the same I came up with (but only today), hence
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Also note, when series is more than a single patch, it's highly recommended to
have a cover letter. Some maintainers do even require that.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread