Skip to content

Commit

Permalink
dm ioctl: use offsetof() instead of open-coding it
Browse files Browse the repository at this point in the history
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: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Bart Van Assche authored and Mike Snitzer committed Dec 8, 2016
1 parent b23df0d commit 6080758
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/md/dm-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
{
struct dm_ioctl *dmi;
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))
return -EFAULT;
Expand Down

0 comments on commit 6080758

Please sign in to comment.