Reapply "usb: yurex: Replace snprintf() with the safer scnprintf() variant"
This reverts commit 0ab72b7775
.
This commit is contained in:
parent
9156188795
commit
40a878f573
1 changed files with 11 additions and 8 deletions
|
@ -34,6 +34,8 @@
|
|||
#define YUREX_BUF_SIZE 8
|
||||
#define YUREX_WRITE_TIMEOUT (HZ*2)
|
||||
|
||||
#define MAX_S64_STRLEN 20 /* {-}922337203685477580{7,8} */
|
||||
|
||||
/* table of devices that work with this driver */
|
||||
static struct usb_device_id yurex_table[] = {
|
||||
{ USB_DEVICE(YUREX_VENDOR_ID, YUREX_PRODUCT_ID) },
|
||||
|
@ -400,8 +402,7 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
|
|||
{
|
||||
struct usb_yurex *dev;
|
||||
int len = 0;
|
||||
char in_buffer[20];
|
||||
unsigned long flags;
|
||||
char in_buffer[MAX_S64_STRLEN];
|
||||
|
||||
dev = file->private_data;
|
||||
|
||||
|
@ -411,13 +412,15 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&dev->lock, flags);
|
||||
len = snprintf(in_buffer, 20, "%lld\n", dev->bbu);
|
||||
spin_unlock_irqrestore(&dev->lock, flags);
|
||||
mutex_unlock(&dev->io_mutex);
|
||||
|
||||
if (WARN_ON_ONCE(len >= sizeof(in_buffer)))
|
||||
if (WARN_ON_ONCE(dev->bbu > S64_MAX || dev->bbu < S64_MIN)) {
|
||||
mutex_unlock(&dev->io_mutex);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
spin_lock_irq(&dev->lock);
|
||||
scnprintf(in_buffer, MAX_S64_STRLEN, "%lld\n", dev->bbu);
|
||||
spin_unlock_irq(&dev->lock);
|
||||
mutex_unlock(&dev->io_mutex);
|
||||
|
||||
return simple_read_from_buffer(buffer, count, ppos, in_buffer, len);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue