Commit 6080758d authored by Bart Van Assche's avatar Bart Van Assche Committed by Mike Snitzer

dm ioctl: use offsetof() instead of open-coding it

Subtracting sizes is a fragile approach because the result is only
correct if the compiler has not added any padding at the end of the
structure. Hence use offsetof() instead of size subtraction. An
additional advantage of offsetof() is that it makes the intent more
clear.
Signed-off-by: default avatarBart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent b23df0d0
...@@ -1697,7 +1697,7 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern ...@@ -1697,7 +1697,7 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
{ {
struct dm_ioctl *dmi; struct dm_ioctl *dmi;
int secure_data; int secure_data;
const size_t minimum_data_size = sizeof(*param_kernel) - sizeof(param_kernel->data); const size_t minimum_data_size = offsetof(struct dm_ioctl, data);
if (copy_from_user(param_kernel, user, minimum_data_size)) if (copy_from_user(param_kernel, user, minimum_data_size))
return -EFAULT; return -EFAULT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment