[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <201101180139.p0I1dh9T066040@www262.sakura.ne.jp>
Date: Tue, 18 Jan 2011 10:39:43 +0900
From: Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
To: zohar@...ux.vnet.ibm.com
Cc: safford@...son.ibm.com, safford@...ibm.com, jj@...osbits.net,
dhowells@...hat.com, jmorris@...ei.org, keyrings@...ux-nfs.org,
linux-security-module@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 3/3] trusted-keys: small cleanup
Mimi Zohar wrote:
> Change the existing '(!ret)' to '(ret < 0)', like the rest of the code?
> It's not wrong, but ....
Something like this?
----------------------------------------
>From 9793efa6fbef62d9e85a06c329761c081ff804c5 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
Date: Tue, 18 Jan 2011 10:14:32 +0900
Subject: [PATCH 3/3] trusted-keys: small cleanup
We can avoid scattering va_end() by changing from
initialize();
va_start();
for (;;) {
if (error condition) {
va_end();
goto out;
}
}
va_end();
if (error condition)
goto out;
finalize();
out:
to
initialize();
va_start();
for (;;) {
if (error condition)
break;
}
va_end();
if (error condition)
goto out;
finalize();
out:
.
Also, use
if (ret < 0)
goto out;
rather than
if (!ret)
ret = do_something();
to clarify error condition.
Signed-off-by: Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
---
security/keys/trusted_defined.c | 43 ++++++++++++++++++++-------------------
1 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/security/keys/trusted_defined.c b/security/keys/trusted_defined.c
index f7d0677..bc04de1 100644
--- a/security/keys/trusted_defined.c
+++ b/security/keys/trusted_defined.c
@@ -101,7 +101,7 @@ static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
if (dlen == 0)
break;
data = va_arg(argp, unsigned char *);
- if (data == NULL) {
+ if (!data) {
ret = -EINVAL;
break;
}
@@ -110,8 +110,9 @@ static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
break;
}
va_end(argp);
- if (!ret)
- ret = crypto_shash_final(&sdesc->shash, digest);
+ if (ret < 0)
+ goto out;
+ ret = crypto_shash_final(&sdesc->shash, digest);
out:
kfree(sdesc);
return ret;
@@ -150,21 +151,21 @@ static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
data = va_arg(argp, unsigned char *);
if (!data) {
ret = -EINVAL;
- va_end(argp);
- goto out;
+ break;
}
ret = crypto_shash_update(&sdesc->shash, data, dlen);
- if (ret < 0) {
- va_end(argp);
- goto out;
- }
+ if (ret < 0)
+ break;
}
va_end(argp);
+ if (ret < 0)
+ goto out;
ret = crypto_shash_final(&sdesc->shash, paramdigest);
- if (!ret)
- ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE,
- paramdigest, TPM_NONCE_SIZE, h1,
- TPM_NONCE_SIZE, h2, 1, &c, 0, 0);
+ if (ret < 0)
+ goto out;
+ ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE,
+ paramdigest, TPM_NONCE_SIZE, h1,
+ TPM_NONCE_SIZE, h2, 1, &c, 0, 0);
out:
kfree(sdesc);
return ret;
@@ -229,12 +230,12 @@ static int TSS_checkhmac1(unsigned char *buffer,
break;
dpos = va_arg(argp, unsigned int);
ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
- if (ret < 0) {
- va_end(argp);
- goto out;
- }
+ if (ret < 0)
+ break;
}
va_end(argp);
+ if (ret < 0)
+ goto out;
ret = crypto_shash_final(&sdesc->shash, paramdigest);
if (ret < 0)
goto out;
@@ -323,12 +324,12 @@ static int TSS_checkhmac2(unsigned char *buffer,
break;
dpos = va_arg(argp, unsigned int);
ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
- if (ret < 0) {
- va_end(argp);
- goto out;
- }
+ if (ret < 0)
+ break;
}
va_end(argp);
+ if (ret < 0)
+ goto out;
ret = crypto_shash_final(&sdesc->shash, paramdigest);
if (ret < 0)
goto out;
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists