aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/firewire/core-cdev.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index 5eba9e0f876c..0d3df0927efc 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1356,24 +1356,24 @@ static int dispatch_ioctl(struct client *client,
1356 return -ENODEV; 1356 return -ENODEV;
1357 1357
1358 if (_IOC_TYPE(cmd) != '#' || 1358 if (_IOC_TYPE(cmd) != '#' ||
1359 _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers)) 1359 _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers) ||
1360 _IOC_SIZE(cmd) > sizeof(buffer))
1360 return -EINVAL; 1361 return -EINVAL;
1361 1362
1362 if (_IOC_DIR(cmd) & _IOC_WRITE) { 1363 if (_IOC_DIR(cmd) == _IOC_READ)
1363 if (_IOC_SIZE(cmd) > sizeof(buffer) || 1364 memset(&buffer, 0, _IOC_SIZE(cmd));
1364 copy_from_user(&buffer, arg, _IOC_SIZE(cmd))) 1365
1366 if (_IOC_DIR(cmd) & _IOC_WRITE)
1367 if (copy_from_user(&buffer, arg, _IOC_SIZE(cmd)))
1365 return -EFAULT; 1368 return -EFAULT;
1366 }
1367 1369
1368 ret = ioctl_handlers[_IOC_NR(cmd)](client, &buffer); 1370 ret = ioctl_handlers[_IOC_NR(cmd)](client, &buffer);
1369 if (ret < 0) 1371 if (ret < 0)
1370 return ret; 1372 return ret;
1371 1373
1372 if (_IOC_DIR(cmd) & _IOC_READ) { 1374 if (_IOC_DIR(cmd) & _IOC_READ)
1373 if (_IOC_SIZE(cmd) > sizeof(buffer) || 1375 if (copy_to_user(arg, &buffer, _IOC_SIZE(cmd)))
1374 copy_to_user(arg, &buffer, _IOC_SIZE(cmd)))
1375 return -EFAULT; 1376 return -EFAULT;
1376 }
1377 1377
1378 return ret; 1378 return ret;
1379} 1379}