Skip to content

Commit

Permalink
staging: comedi: comedi_fops: fix a number of sizeof(struct foo) forms
Browse files Browse the repository at this point in the history
As mentioned in CodingStyle, the prefered form is:

	p = kmalloc(sizeof(*p), ...);

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Jan 7, 2013
1 parent 76cca89 commit bc252fd
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions drivers/staging/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
return 0;
}

if (copy_from_user(&it, arg, sizeof(struct comedi_devconfig)))
if (copy_from_user(&it, arg, sizeof(it)))
return -EFAULT;

it.board_name[COMEDI_NAMELEN - 1] = 0;
Expand Down Expand Up @@ -519,7 +519,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev,
struct comedi_subdevice *s;
int retval = 0;

if (copy_from_user(&bc, arg, sizeof(struct comedi_bufconfig)))
if (copy_from_user(&bc, arg, sizeof(bc)))
return -EFAULT;

if (bc.subdevice >= dev->n_subdevices || bc.subdevice < 0)
Expand Down Expand Up @@ -552,7 +552,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev,
bc.maximum_size = async->max_bufsize;

copyback:
if (copy_to_user(arg, &bc, sizeof(struct comedi_bufconfig)))
if (copy_to_user(arg, &bc, sizeof(bc)))
return -EFAULT;

return 0;
Expand Down Expand Up @@ -601,7 +601,7 @@ static int do_devinfo_ioctl(struct comedi_device *dev,
else
devinfo.write_subdevice = -1;

if (copy_to_user(arg, &devinfo, sizeof(struct comedi_devinfo)))
if (copy_to_user(arg, &devinfo, sizeof(devinfo)))
return -EFAULT;

return 0;
Expand All @@ -628,9 +628,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev,
struct comedi_subdinfo *tmp, *us;
struct comedi_subdevice *s;

tmp =
kcalloc(dev->n_subdevices, sizeof(struct comedi_subdinfo),
GFP_KERNEL);
tmp = kcalloc(dev->n_subdevices, sizeof(*tmp), GFP_KERNEL);
if (!tmp)
return -ENOMEM;

Expand Down Expand Up @@ -681,8 +679,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev,
us->settling_time_0 = s->settling_time_0;
}

ret = copy_to_user(arg, tmp,
dev->n_subdevices * sizeof(struct comedi_subdinfo));
ret = copy_to_user(arg, tmp, dev->n_subdevices * sizeof(*tmp));

kfree(tmp);

Expand All @@ -709,7 +706,7 @@ static int do_chaninfo_ioctl(struct comedi_device *dev,
struct comedi_subdevice *s;
struct comedi_chaninfo it;

if (copy_from_user(&it, arg, sizeof(struct comedi_chaninfo)))
if (copy_from_user(&it, arg, sizeof(it)))
return -EFAULT;

if (it.subdev >= dev->n_subdevices)
Expand Down Expand Up @@ -776,7 +773,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
struct comedi_subdevice *s;
struct comedi_async *async;

if (copy_from_user(&bi, arg, sizeof(struct comedi_bufinfo)))
if (copy_from_user(&bi, arg, sizeof(bi)))
return -EFAULT;

if (bi.subdevice >= dev->n_subdevices || bi.subdevice < 0)
Expand Down Expand Up @@ -831,7 +828,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
bi.buf_read_ptr = async->buf_read_ptr;

copyback:
if (copy_to_user(arg, &bi, sizeof(struct comedi_bufinfo)))
if (copy_to_user(arg, &bi, sizeof(bi)))
return -EFAULT;

return 0;
Expand Down Expand Up @@ -865,7 +862,7 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
int i = 0;
int ret = 0;

if (copy_from_user(&insnlist, arg, sizeof(struct comedi_insnlist)))
if (copy_from_user(&insnlist, arg, sizeof(insnlist)))
return -EFAULT;

data = kmalloc(sizeof(unsigned int) * MAX_SAMPLES, GFP_KERNEL);
Expand All @@ -875,16 +872,15 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
goto error;
}

insns =
kcalloc(insnlist.n_insns, sizeof(struct comedi_insn), GFP_KERNEL);
insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL);
if (!insns) {
DPRINTK("kmalloc failed\n");
ret = -ENOMEM;
goto error;
}

if (copy_from_user(insns, insnlist.insns,
sizeof(struct comedi_insn) * insnlist.n_insns)) {
sizeof(*insns) * insnlist.n_insns)) {
DPRINTK("copy_from_user failed\n");
ret = -EFAULT;
goto error;
Expand Down Expand Up @@ -1185,7 +1181,7 @@ static int do_insn_ioctl(struct comedi_device *dev,
goto error;
}

if (copy_from_user(&insn, arg, sizeof(struct comedi_insn))) {
if (copy_from_user(&insn, arg, sizeof(insn))) {
ret = -EFAULT;
goto error;
}
Expand Down Expand Up @@ -1229,7 +1225,7 @@ static int do_cmd_ioctl(struct comedi_device *dev,
int ret = 0;
unsigned int __user *user_chanlist;

if (copy_from_user(&cmd, arg, sizeof(struct comedi_cmd))) {
if (copy_from_user(&cmd, arg, sizeof(cmd))) {
DPRINTK("bad cmd address\n");
return -EFAULT;
}
Expand Down Expand Up @@ -1319,7 +1315,7 @@ static int do_cmd_ioctl(struct comedi_device *dev,
/* restore chanlist pointer before copying back */
cmd.chanlist = (unsigned int __force *)user_chanlist;
cmd.data = NULL;
if (copy_to_user(arg, &cmd, sizeof(struct comedi_cmd))) {
if (copy_to_user(arg, &cmd, sizeof(cmd))) {
DPRINTK("fault writing cmd\n");
ret = -EFAULT;
goto cleanup;
Expand Down Expand Up @@ -1378,7 +1374,7 @@ static int do_cmdtest_ioctl(struct comedi_device *dev,
unsigned int *chanlist = NULL;
unsigned int __user *user_chanlist;

if (copy_from_user(&cmd, arg, sizeof(struct comedi_cmd))) {
if (copy_from_user(&cmd, arg, sizeof(cmd))) {
DPRINTK("bad cmd address\n");
return -EFAULT;
}
Expand Down Expand Up @@ -1442,7 +1438,7 @@ static int do_cmdtest_ioctl(struct comedi_device *dev,
/* restore chanlist pointer before copying back */
cmd.chanlist = (unsigned int __force *)user_chanlist;

if (copy_to_user(arg, &cmd, sizeof(struct comedi_cmd))) {
if (copy_to_user(arg, &cmd, sizeof(cmd))) {
DPRINTK("bad cmd address\n");
ret = -EFAULT;
goto cleanup;
Expand Down Expand Up @@ -2260,7 +2256,7 @@ EXPORT_SYMBOL(comedi_get_subdevice_runflags);

static void comedi_device_init(struct comedi_device *dev)
{
memset(dev, 0, sizeof(struct comedi_device));
memset(dev, 0, sizeof(*dev));
spin_lock_init(&dev->spinlock);
mutex_init(&dev->mutex);
dev->minor = -1;
Expand All @@ -2282,7 +2278,7 @@ int comedi_alloc_board_minor(struct device *hardware_device)
struct device *csdev;
unsigned i;

info = kzalloc(sizeof(struct comedi_file_info), GFP_KERNEL);
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (info == NULL)
return -ENOMEM;
info->device = kzalloc(sizeof(struct comedi_device), GFP_KERNEL);
Expand Down Expand Up @@ -2365,7 +2361,7 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
struct device *csdev;
unsigned i;

info = kmalloc(sizeof(struct comedi_file_info), GFP_KERNEL);
info = kmalloc(sizeof(*info), GFP_KERNEL);
if (info == NULL)
return -ENOMEM;
info->device = dev;
Expand Down

0 comments on commit bc252fd

Please sign in to comment.