mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 09:34:12 +08:00
staging: comedi: cleanup sysfs functions
Make the comedi sysfs functions a bit more concise by shortening some of the verbose variable names and reusing some of the variables that were used for intermediate calculations. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Cc: Mori Hess <fmhess@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
4e2f002f7a
commit
72fd9facfb
@ -172,28 +172,19 @@ static int resize_async_buffer(struct comedi_device *dev,
|
|||||||
|
|
||||||
/* sysfs attribute files */
|
/* sysfs attribute files */
|
||||||
|
|
||||||
static const unsigned bytes_per_kibi = 1024;
|
|
||||||
|
|
||||||
static ssize_t show_max_read_buffer_kb(struct device *dev,
|
static ssize_t show_max_read_buffer_kb(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
ssize_t retval;
|
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned max_buffer_size_kb = 0;
|
struct comedi_subdevice *s = comedi_get_read_subdevice(info);
|
||||||
struct comedi_subdevice *const read_subdevice =
|
unsigned int size = 0;
|
||||||
comedi_get_read_subdevice(info);
|
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (read_subdevice &&
|
if (s && (s->subdev_flags & SDF_CMD_READ) && s->async)
|
||||||
(read_subdevice->subdev_flags & SDF_CMD_READ) &&
|
size = s->async->max_bufsize / 1024;
|
||||||
read_subdevice->async) {
|
|
||||||
max_buffer_size_kb = read_subdevice->async->max_bufsize /
|
|
||||||
bytes_per_kibi;
|
|
||||||
}
|
|
||||||
retval = snprintf(buf, PAGE_SIZE, "%i\n", max_buffer_size_kb);
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
return retval;
|
return snprintf(buf, PAGE_SIZE, "%i\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t store_max_read_buffer_kb(struct device *dev,
|
static ssize_t store_max_read_buffer_kb(struct device *dev,
|
||||||
@ -201,52 +192,40 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
|
|||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned int new_max_size_kb;
|
struct comedi_subdevice *s = comedi_get_read_subdevice(info);
|
||||||
unsigned int new_max_size;
|
unsigned int size;
|
||||||
int ret;
|
int err;
|
||||||
struct comedi_subdevice *const read_subdevice =
|
|
||||||
comedi_get_read_subdevice(info);
|
|
||||||
|
|
||||||
ret = kstrtouint(buf, 10, &new_max_size_kb);
|
err = kstrtouint(buf, 10, &size);
|
||||||
if (ret)
|
if (err)
|
||||||
return ret;
|
return err;
|
||||||
if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
|
if (size > (UINT_MAX / 1024))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
new_max_size = new_max_size_kb * bytes_per_kibi;
|
size *= 1024;
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (read_subdevice == NULL ||
|
if (s && (s->subdev_flags & SDF_CMD_READ) && s->async)
|
||||||
(read_subdevice->subdev_flags & SDF_CMD_READ) == 0 ||
|
s->async->max_bufsize = size;
|
||||||
read_subdevice->async == NULL) {
|
else
|
||||||
mutex_unlock(&info->device->mutex);
|
err = -EINVAL;
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
read_subdevice->async->max_bufsize = new_max_size;
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
return count;
|
return err ? err : count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_read_buffer_kb(struct device *dev,
|
static ssize_t show_read_buffer_kb(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
ssize_t retval;
|
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned buffer_size_kb = 0;
|
struct comedi_subdevice *s = comedi_get_read_subdevice(info);
|
||||||
struct comedi_subdevice *const read_subdevice =
|
unsigned int size = 0;
|
||||||
comedi_get_read_subdevice(info);
|
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (read_subdevice &&
|
if (s && (s->subdev_flags & SDF_CMD_READ) && s->async)
|
||||||
(read_subdevice->subdev_flags & SDF_CMD_READ) &&
|
size = s->async->prealloc_bufsz / 1024;
|
||||||
read_subdevice->async) {
|
|
||||||
buffer_size_kb = read_subdevice->async->prealloc_bufsz /
|
|
||||||
bytes_per_kibi;
|
|
||||||
}
|
|
||||||
retval = snprintf(buf, PAGE_SIZE, "%i\n", buffer_size_kb);
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
return retval;
|
return snprintf(buf, PAGE_SIZE, "%i\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t store_read_buffer_kb(struct device *dev,
|
static ssize_t store_read_buffer_kb(struct device *dev,
|
||||||
@ -254,57 +233,41 @@ static ssize_t store_read_buffer_kb(struct device *dev,
|
|||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned int new_size_kb;
|
struct comedi_subdevice *s = comedi_get_read_subdevice(info);
|
||||||
unsigned int new_size;
|
unsigned int size;
|
||||||
int retval;
|
int err;
|
||||||
int ret;
|
|
||||||
struct comedi_subdevice *const read_subdevice =
|
|
||||||
comedi_get_read_subdevice(info);
|
|
||||||
|
|
||||||
ret = kstrtouint(buf, 10, &new_size_kb);
|
err = kstrtouint(buf, 10, &size);
|
||||||
if (ret)
|
if (err)
|
||||||
return ret;
|
return err;
|
||||||
if (new_size_kb > (UINT_MAX / bytes_per_kibi))
|
if (size > (UINT_MAX / 1024))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
new_size = new_size_kb * bytes_per_kibi;
|
size *= 1024;
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (read_subdevice == NULL ||
|
if (s && (s->subdev_flags & SDF_CMD_READ) && s->async)
|
||||||
(read_subdevice->subdev_flags & SDF_CMD_READ) == 0 ||
|
err = resize_async_buffer(info->device, s, s->async, size);
|
||||||
read_subdevice->async == NULL) {
|
else
|
||||||
mutex_unlock(&info->device->mutex);
|
err = -EINVAL;
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
retval = resize_async_buffer(info->device, read_subdevice,
|
|
||||||
read_subdevice->async, new_size);
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
if (retval < 0)
|
return err ? err : count;
|
||||||
return retval;
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_max_write_buffer_kb(struct device *dev,
|
static ssize_t show_max_write_buffer_kb(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
ssize_t retval;
|
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned max_buffer_size_kb = 0;
|
struct comedi_subdevice *s = comedi_get_write_subdevice(info);
|
||||||
struct comedi_subdevice *const write_subdevice =
|
unsigned int size = 0;
|
||||||
comedi_get_write_subdevice(info);
|
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (write_subdevice &&
|
if (s && (s->subdev_flags & SDF_CMD_WRITE) && s->async)
|
||||||
(write_subdevice->subdev_flags & SDF_CMD_WRITE) &&
|
size = s->async->max_bufsize / 1024;
|
||||||
write_subdevice->async) {
|
|
||||||
max_buffer_size_kb = write_subdevice->async->max_bufsize /
|
|
||||||
bytes_per_kibi;
|
|
||||||
}
|
|
||||||
retval = snprintf(buf, PAGE_SIZE, "%i\n", max_buffer_size_kb);
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
return retval;
|
return snprintf(buf, PAGE_SIZE, "%i\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t store_max_write_buffer_kb(struct device *dev,
|
static ssize_t store_max_write_buffer_kb(struct device *dev,
|
||||||
@ -312,52 +275,40 @@ static ssize_t store_max_write_buffer_kb(struct device *dev,
|
|||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned int new_max_size_kb;
|
struct comedi_subdevice *s = comedi_get_write_subdevice(info);
|
||||||
unsigned int new_max_size;
|
unsigned int size;
|
||||||
int ret;
|
int err;
|
||||||
struct comedi_subdevice *const write_subdevice =
|
|
||||||
comedi_get_write_subdevice(info);
|
|
||||||
|
|
||||||
ret = kstrtouint(buf, 10, &new_max_size_kb);
|
err = kstrtouint(buf, 10, &size);
|
||||||
if (ret)
|
if (err)
|
||||||
return ret;
|
return err;
|
||||||
if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
|
if (size > (UINT_MAX / 1024))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
new_max_size = new_max_size_kb * bytes_per_kibi;
|
size *= 1024;
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (write_subdevice == NULL ||
|
if (s && (s->subdev_flags & SDF_CMD_WRITE) && s->async)
|
||||||
(write_subdevice->subdev_flags & SDF_CMD_WRITE) == 0 ||
|
s->async->max_bufsize = size;
|
||||||
write_subdevice->async == NULL) {
|
else
|
||||||
mutex_unlock(&info->device->mutex);
|
err = -EINVAL;
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
write_subdevice->async->max_bufsize = new_max_size;
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
return count;
|
return err ? err : count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_write_buffer_kb(struct device *dev,
|
static ssize_t show_write_buffer_kb(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
ssize_t retval;
|
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned buffer_size_kb = 0;
|
struct comedi_subdevice *s = comedi_get_write_subdevice(info);
|
||||||
struct comedi_subdevice *const write_subdevice =
|
unsigned int size = 0;
|
||||||
comedi_get_write_subdevice(info);
|
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (write_subdevice &&
|
if (s && (s->subdev_flags & SDF_CMD_WRITE) && s->async)
|
||||||
(write_subdevice->subdev_flags & SDF_CMD_WRITE) &&
|
size = s->async->prealloc_bufsz / 1024;
|
||||||
write_subdevice->async) {
|
|
||||||
buffer_size_kb = write_subdevice->async->prealloc_bufsz /
|
|
||||||
bytes_per_kibi;
|
|
||||||
}
|
|
||||||
retval = snprintf(buf, PAGE_SIZE, "%i\n", buffer_size_kb);
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
return retval;
|
return snprintf(buf, PAGE_SIZE, "%i\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t store_write_buffer_kb(struct device *dev,
|
static ssize_t store_write_buffer_kb(struct device *dev,
|
||||||
@ -365,34 +316,25 @@ static ssize_t store_write_buffer_kb(struct device *dev,
|
|||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
struct comedi_device_file_info *info = dev_get_drvdata(dev);
|
||||||
unsigned int new_size_kb;
|
struct comedi_subdevice *s = comedi_get_write_subdevice(info);
|
||||||
unsigned int new_size;
|
unsigned int size;
|
||||||
int retval;
|
int err;
|
||||||
int ret;
|
|
||||||
struct comedi_subdevice *const write_subdevice =
|
|
||||||
comedi_get_write_subdevice(info);
|
|
||||||
|
|
||||||
ret = kstrtouint(buf, 10, &new_size_kb);
|
err = kstrtouint(buf, 10, &size);
|
||||||
if (ret)
|
if (err)
|
||||||
return ret;
|
return err;
|
||||||
if (new_size_kb > (UINT_MAX / bytes_per_kibi))
|
if (size > (UINT_MAX / 1024))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
new_size = ((uint64_t) new_size_kb) * bytes_per_kibi;
|
size *= 1024;
|
||||||
|
|
||||||
mutex_lock(&info->device->mutex);
|
mutex_lock(&info->device->mutex);
|
||||||
if (write_subdevice == NULL ||
|
if (s && (s->subdev_flags & SDF_CMD_WRITE) && s->async)
|
||||||
(write_subdevice->subdev_flags & SDF_CMD_WRITE) == 0 ||
|
err = resize_async_buffer(info->device, s, s->async, size);
|
||||||
write_subdevice->async == NULL) {
|
else
|
||||||
mutex_unlock(&info->device->mutex);
|
err = -EINVAL;
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
retval = resize_async_buffer(info->device, write_subdevice,
|
|
||||||
write_subdevice->async, new_size);
|
|
||||||
mutex_unlock(&info->device->mutex);
|
mutex_unlock(&info->device->mutex);
|
||||||
|
|
||||||
if (retval < 0)
|
return err ? err : count;
|
||||||
return retval;
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device_attribute comedi_dev_attrs[] = {
|
static struct device_attribute comedi_dev_attrs[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user