diff options
author | Bart Van Assche <bart.vanassche@sandisk.com> | 2016-11-18 14:28:00 -0800 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2016-12-08 14:13:08 -0500 |
commit | 6080758d441acd7765314f3e9b6ca843e18e9a68 (patch) | |
tree | ed5a796823ccb7e039b209d7e88a550d3fd74e8f /drivers/md | |
parent | b23df0d048e5f137ad5c2a116ec0849a98d43b96 (diff) |
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: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-ioctl.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 966eb4b61aed..c72a77048b73 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -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; |