hwrng: virtio - use min() in copy_data()
PATCH 1/2 hwrng: virtio - use min() in copy_data()
Use the simpler min() macro since all values are unsigned and compatible. The subtraction avail - vi->data_idx is also guaranteed to be positive by the preceding check.
--- drivers/char/hw_random/virtio-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/hw_random/virtio-rng.c +2 -2
@@ -81,13 +81,13 @@ static unsigned int copy_data(struct virtrng_info *vi, void *buf,* steered into adjacent slab memory, including under * speculation. */ - avail = min_t(unsigned int, vi->data_avail, sizeof(vi->data)); + avail =min (vi->data_avail,sizeof (vi->data));if (vi->data_idx >= avail) { vi->data_avail =0 ;request_entropy (vi);return 0 ; } - size = min_t(unsigned int, size, avail - vi->data_idx); + size =min (size, avail - vi->data_idx); idx =array_index_nospec (vi->data_idx,sizeof (vi->data));memcpy (buf, vi->data + idx, size); vi->data_idx += size;
PATCH 2/2 hwrng: virtio - use snprintf() in probe_common()
While the current code works correctly, replace the unbounded sprintf() with the safer snprintf() to follow secure coding best practices.
--- drivers/char/hw_random/virtio-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/virtio-rng.c +1 -1
@@ -162,7 +162,7 @@ static int probe_common(struct virtio_device *vdev) err = index; goto err_ida; } -sprintf (vi->name,"virtio_rng.%d" , index); +snprintf (vi->name,sizeof (vi->name),"virtio_rng.%d" , vi->index);init_completion (&vi->have_data); vi->hwrng = (struct hwrng ) {
[email protected]
AI reviewRe: [PATCH 2/2] hwrng: virtio - use snprintf() in probe_common()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
While the current code works correctly, replace the unbounded
sprintf()with the safersnprintf()to follow secure coding best practices.Signed-off-by Thorsten Blum <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/2] hwrng: virtio - use snprintf() in probe_common()
In reply to Thorsten BlumQuoted 13 lines · Thorsten Blum
While the current code works correctly, replace the unbounded
sprintf()with the safersnprintf()to follow secure coding best practices.Signed-off-by Thorsten Blum <[email protected]>--- drivers/char/hw_random/virtio-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/hw_random/virtio-rng.c +0
-0
drivers/char/hw_random/virtio-rng.c static int probe_common(struct virtio_device *vdev) · line 168
Quoted 8 lines
drivers/char/hw_random/virtio-rng.c +1
-1@@ -162,7 +162,7 @@ static int probe_common(struct virtio_device *vdev) err = index; goto err_ida; } -sprintf (vi->name,"virtio_rng.%d" , index); +snprintf (vi->name,sizeof (vi->name),"virtio_rng.%d" , vi->index);init_completion (&vi->have_data); vi->hwrng = (struct hwrng ) {
Re: [PATCH 2/2] hwrng: virtio - use snprintf() in probe_common()
In reply to Thorsten BlumQuoted 14 lines · Thorsten Blum
While the current code works correctly, replace the unbounded
sprintf()with the safersnprintf()to follow secure coding best practices.Signed-off-by Thorsten Blum <[email protected]>--- drivers/char/hw_random/virtio-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/hw_random/virtio-rng.c +0
-0
drivers/char/hw_random/virtio-rng.c static int probe_common(struct virtio_device *vdev) · line 168
Quoted 8 lines
drivers/char/hw_random/virtio-rng.c +1
-1@@ -162,7 +162,7 @@ static int probe_common(struct virtio_device *vdev) err = index; goto err_ida; } -sprintf (vi->name,"virtio_rng.%d" , index); +snprintf (vi->name,sizeof (vi->name),"virtio_rng.%d" , vi->index);init_completion (&vi->have_data); vi->hwrng = (struct hwrng ) {
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
Use the simpler
min()macro since all values are unsigned and compatible. The subtraction avail -vi->data_idxis also guaranteed to be positive by the preceding check.Signed-off-by Thorsten Blum <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Herbert Xu
maintainerQuoted 8 lines · Thorsten Blum
Use the simpler
min()macro since all values are unsigned and compatible. The subtraction avail -vi->data_idxis also guaranteed to be positive by the preceding check.Signed-off-by Thorsten Blum <[email protected]>--- drivers/char/hw_random/virtio-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 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