lkml.org 
[lkml]   [2019]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v24 06/24] x86/sgx: Add wrappers for ENCLS leaf functions
On Sat, Nov 30, 2019 at 01:13:08AM +0200, Jarkko Sakkinen wrote:
> +/**
> + * encls_failed() - Check if an ENCLS leaf function failed
> + * @ret: the return value of an ENCLS leaf function call
> + *
> + * Check if an ENCLS leaf function failed. This happens when the leaf function
> + * causes a fault that is not caused by an EPCM conflict or when the leaf
> + * function returns a non-zero value.
> + */
> +static inline bool encls_failed(int ret)
> +{
> + int epcm_trapnr =
> + boot_cpu_has(X86_FEATURE_SGX2) ? X86_TRAP_PF : X86_TRAP_GP;
> + bool fault = ret & ENCLS_FAULT_FLAG;
> +
> + return (fault && ENCLS_TRAPNR(ret) != epcm_trapnr) || (!fault && ret);
> +}

Can we make this function more readable?

static inline bool encls_failed(int ret)
{
int epcm_trapnr;

if (boot_cpu_has(X86_FEATURE_SGX2))
epcm_trapnr = X86_TRAP_PF;
else
epcm_trapnr = X86_TRAP_GP;

if (ret & ENCLS_FAULT_FLAG)
return ENCLS_TRAPNR(ret) != epcm_trapnr;

return !!ret;
}

I hope I've converted it correctly but I might've missed some corner
case...

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

\
 
 \ /
  Last update: 2019-12-17 15:47    [W:0.236 / U:22.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site