hwrng: core - drop unnecessary forward declarations
Subsystems (2)
PATCH v2 1/4 hwrng: core - drop unnecessary forward declarations
The forward declarations for drop_current_rng() and rng_get_data() are not needed - remove them.
---
No changes in patch 1/4.
--- drivers/char/hw_random/core.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/char/hw_random/core.c +0 -4
@@ -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 ;
PATCH v2 2/4 hwrng: core - use bool for wait parameter in rng_get_data
The wait parameter in rng_get_data() is a boolean flag - use bool instead of int to better reflect its actual type.
---
Formatting changes only as suggested by Andy.
--- drivers/char/hw_random/core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/char/hw_random/core.c +3 -4
@@ -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;
PATCH v2 3/4 hwrng: core - use MAX to simplify RNG_BUFFER_SIZE
In reply to Thorsten BlumReplace the open-coded variant with MAX().
---
Drop the explicit include as suggested by Herbert.
--- drivers/char/hw_random/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/core.c +1 -1
@@ -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 */
PATCH v2 4/4 hwrng: core - use sysfs_emit_at in rng_available_show
In reply to Thorsten BlumReplace 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).
---
No changes in patch 4/4.
--- drivers/char/hw_random/core.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/char/hw_random/core.c +7 -10
@@ -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,
Herbert Xu
maintainerQuoted 9 lines · Thorsten Blum
The forward declarations for
drop_current_rng()andrng_get_data()are not needed - remove them.Signed-off-by Thorsten Blum <[email protected]>---
No changes in patch 1/4.--- drivers/char/hw_random/core.c | 4 ---- 1 file changed, 4 deletions(-)
All 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