Skip to content

Commit 58b4621

Browse files
tobluxjarkkojs
authored andcommitted
keys: Remove redundant less-than-zero checks
The local variables 'size_t datalen' are unsigned and cannot be less than zero. Remove the redundant conditions. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent e1afacb commit 58b4621

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

security/keys/big_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
6666

6767
BUILD_BUG_ON(sizeof(*payload) != sizeof(prep->payload.data));
6868

69-
if (datalen <= 0 || datalen > 1024 * 1024 || !prep->data)
69+
if (datalen == 0 || datalen > 1024 * 1024 || !prep->data)
7070
return -EINVAL;
7171

7272
/* Set an arbitrary quota */

security/keys/encrypted-keys/encrypted.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ static int encrypted_instantiate(struct key *key,
795795
size_t datalen = prep->datalen;
796796
int ret;
797797

798-
if (datalen <= 0 || datalen > 32767 || !prep->data)
798+
if (datalen == 0 || datalen > 32767 || !prep->data)
799799
return -EINVAL;
800800

801801
datablob = kmalloc(datalen + 1, GFP_KERNEL);
@@ -856,7 +856,7 @@ static int encrypted_update(struct key *key, struct key_preparsed_payload *prep)
856856

857857
if (key_is_negative(key))
858858
return -ENOKEY;
859-
if (datalen <= 0 || datalen > 32767 || !prep->data)
859+
if (datalen == 0 || datalen > 32767 || !prep->data)
860860
return -EINVAL;
861861

862862
buf = kmalloc(datalen + 1, GFP_KERNEL);

security/keys/trusted-keys/trusted_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static int trusted_instantiate(struct key *key,
157157
int key_cmd;
158158
size_t key_len;
159159

160-
if (datalen <= 0 || datalen > 32767 || !prep->data)
160+
if (datalen == 0 || datalen > 32767 || !prep->data)
161161
return -EINVAL;
162162

163163
orig_datablob = datablob = kmalloc(datalen + 1, GFP_KERNEL);
@@ -240,7 +240,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
240240
p = key->payload.data[0];
241241
if (!p->migratable)
242242
return -EPERM;
243-
if (datalen <= 0 || datalen > 32767 || !prep->data)
243+
if (datalen == 0 || datalen > 32767 || !prep->data)
244244
return -EINVAL;
245245

246246
orig_datablob = datablob = kmalloc(datalen + 1, GFP_KERNEL);

security/keys/user_defined.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int user_preparse(struct key_preparsed_payload *prep)
6161
struct user_key_payload *upayload;
6262
size_t datalen = prep->datalen;
6363

64-
if (datalen <= 0 || datalen > 32767 || !prep->data)
64+
if (datalen == 0 || datalen > 32767 || !prep->data)
6565
return -EINVAL;
6666

6767
upayload = kmalloc(sizeof(*upayload) + datalen, GFP_KERNEL);

0 commit comments

Comments
 (0)