Skip to content

Commit

Permalink
staging: comedi: comedi_fops: Removed int overflow check
Browse files Browse the repository at this point in the history
This became unnecessary with the previous commit.
Improved the readability of the remaining check, by using UINT_MAX.

Signed-off-by: Florian Schmaus <fschmaus@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Florian Schmaus authored and Greg Kroah-Hartman committed Dec 8, 2011
1 parent 2e1c394 commit c501816
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions drivers/staging/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2430,19 +2430,17 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
{
struct comedi_device_file_info *info = dev_get_drvdata(dev);
unsigned int new_max_size_kb;
uint64_t new_max_size;
unsigned int new_max_size;
int ret;
struct comedi_subdevice *const read_subdevice =
comedi_get_read_subdevice(info);

ret = kstrtouint(buf, 10, &new_max_size_kb);
if (ret)
return ret;
if (new_max_size_kb != (uint32_t) new_max_size_kb)
return -EINVAL;
new_max_size = ((uint64_t) new_max_size_kb) * bytes_per_kibi;
if (new_max_size != (uint32_t) new_max_size)
if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
return -EINVAL;
new_max_size = new_max_size_kb * bytes_per_kibi;

mutex_lock(&info->device->mutex);
if (read_subdevice == NULL ||
Expand Down Expand Up @@ -2493,7 +2491,7 @@ static ssize_t store_read_buffer_kb(struct device *dev,
{
struct comedi_device_file_info *info = dev_get_drvdata(dev);
unsigned int new_size_kb;
uint64_t new_size;
unsigned int new_size;
int retval;
int ret;
struct comedi_subdevice *const read_subdevice =
Expand All @@ -2502,11 +2500,9 @@ static ssize_t store_read_buffer_kb(struct device *dev,
ret = kstrtouint(buf, 10, &new_size_kb);
if (ret)
return ret;
if (new_size_kb != (uint32_t) new_size_kb)
return -EINVAL;
new_size = ((uint64_t) new_size_kb) * bytes_per_kibi;
if (new_size != (uint32_t) new_size)
if (new_size_kb > (UINT_MAX / bytes_per_kibi))
return -EINVAL;
new_size = new_size_kb * bytes_per_kibi;

mutex_lock(&info->device->mutex);
if (read_subdevice == NULL ||
Expand Down Expand Up @@ -2561,19 +2557,17 @@ static ssize_t store_max_write_buffer_kb(struct device *dev,
{
struct comedi_device_file_info *info = dev_get_drvdata(dev);
unsigned int new_max_size_kb;
uint64_t new_max_size;
unsigned int new_max_size;
int ret;
struct comedi_subdevice *const write_subdevice =
comedi_get_write_subdevice(info);

ret = kstrtouint(buf, 10, &new_max_size_kb);
if (ret)
return ret;
if (new_max_size_kb != (uint32_t) new_max_size_kb)
return -EINVAL;
new_max_size = ((uint64_t) new_max_size_kb) * bytes_per_kibi;
if (new_max_size != (uint32_t) new_max_size)
if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
return -EINVAL;
new_max_size = new_max_size_kb * bytes_per_kibi;

mutex_lock(&info->device->mutex);
if (write_subdevice == NULL ||
Expand Down Expand Up @@ -2624,7 +2618,7 @@ static ssize_t store_write_buffer_kb(struct device *dev,
{
struct comedi_device_file_info *info = dev_get_drvdata(dev);
unsigned int new_size_kb;
uint64_t new_size;
unsigned int new_size;
int retval;
int ret;
struct comedi_subdevice *const write_subdevice =
Expand All @@ -2633,11 +2627,9 @@ static ssize_t store_write_buffer_kb(struct device *dev,
ret = kstrtouint(buf, 10, &new_size_kb);
if (ret)
return ret;
if (new_size_kb != (uint32_t) new_size_kb)
if (new_size_kb > (UINT_MAX / bytes_per_kibi))
return -EINVAL;
new_size = ((uint64_t) new_size_kb) * bytes_per_kibi;
if (new_size != (uint32_t) new_size)
return -EINVAL;

mutex_lock(&info->device->mutex);
if (write_subdevice == NULL ||
Expand Down

0 comments on commit c501816

Please sign in to comment.