Skip to content

Commit

Permalink
crypto: testmgr - check that entries in alg_test_descs are in correct…
Browse files Browse the repository at this point in the history
… order

Patch adds check for alg_test_descs list order, so that accidentically
misplaced entries are found quicker. Duplicate entries are also checked for.

Signed-off-by: Jussi Kivilinna <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
jkivilin authored and herbertx committed Jun 21, 2013
1 parent 99f42f9 commit 5714758
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crypto/testmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3054,6 +3054,35 @@ static const struct alg_test_desc alg_test_descs[] = {
}
};

static bool alg_test_descs_checked;

static void alg_test_descs_check_order(void)
{
int i;

/* only check once */
if (alg_test_descs_checked)
return;

alg_test_descs_checked = true;

for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
int diff = strcmp(alg_test_descs[i - 1].alg,
alg_test_descs[i].alg);

if (WARN_ON(diff > 0)) {
pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
alg_test_descs[i - 1].alg,
alg_test_descs[i].alg);
}

if (WARN_ON(diff == 0)) {
pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
alg_test_descs[i].alg);
}
}
}

static int alg_find_test(const char *alg)
{
int start = 0;
Expand Down Expand Up @@ -3085,6 +3114,8 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
int j;
int rc;

alg_test_descs_check_order();

if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
char nalg[CRYPTO_MAX_ALG_NAME];

Expand Down

0 comments on commit 5714758

Please sign in to comment.