@@ -107,12 +107,6 @@ static inline int mm_pkey_alloc(struct mm_struct *mm)
static inline int mm_pkey_free(struct mm_struct *mm, int pkey)
{
- if (!mmu_has_feature(MMU_FTR_PKEY))
- return -1;
-
- if (!mm_pkey_is_allocated(mm, pkey))
- return -EINVAL;
-
__mm_pkey_free(mm, pkey);
return 0;
@@ -107,9 +107,6 @@ int mm_pkey_alloc(struct mm_struct *mm)
static inline
int mm_pkey_free(struct mm_struct *mm, int pkey)
{
- if (!mm_pkey_is_allocated(mm, pkey))
- return -EINVAL;
-
mm_set_pkey_free(mm, pkey);
return 0;
@@ -803,10 +803,14 @@ SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val)
SYSCALL_DEFINE1(pkey_free, int, pkey)
{
- int ret;
+ int ret = -EINVAL;
+
+ if (!arch_pkeys_enabled())
+ return ret;
mmap_write_lock(current->mm);
- ret = mm_pkey_free(current->mm, pkey);
+ if (mm_pkey_is_allocated(current->mm, pkey))
+ ret = mm_pkey_free(current->mm, pkey);
mmap_write_unlock(current->mm);
/*