Instead of looping through the array of reserved bytes use memchr_inv() to check the bytes. Cc: Sean Christopherson <sean.j.christpherson@xxxxxxxxx> Cc: Shay Katz-zamir <shay.katz-zamir@xxxxxxxxx> Cc: Serge Ayoun <serge.ayoun@xxxxxxxxx> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@xxxxxxxxxxxxxxx> --- arch/x86/kernel/cpu/sgx/driver/ioctl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/driver/ioctl.c b/arch/x86/kernel/cpu/sgx/driver/ioctl.c index 64d3286f3324..d5f326411df0 100644 --- a/arch/x86/kernel/cpu/sgx/driver/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/driver/ioctl.c @@ -414,7 +414,6 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo) { u64 page_type = secinfo->flags & SGX_SECINFO_PAGE_TYPE_MASK; u64 perm = secinfo->flags & SGX_SECINFO_PERMISSION_MASK; - int i; if ((secinfo->flags & SGX_SECINFO_RESERVED_MASK) || ((perm & SGX_SECINFO_W) && !(perm & SGX_SECINFO_R)) || @@ -422,9 +421,8 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo) page_type != SGX_SECINFO_REG)) return -EINVAL; - for (i = 0; i < SGX_SECINFO_RESERVED_SIZE; i++) - if (secinfo->reserved[i]) - return -EINVAL; + if (memchr_inv(secinfo->reserved, 0, SGX_SECINFO_RESERVED_SIZE)) + return -EINVAL; return 0; } -- 2.20.1