vboot: remove OffsetOf function
Should use vboot2 equivalent instead: vb2_offset_of BUG=b:124141368 TEST=make clean && make runtests BRANCH=none Change-Id: I64afc88477cbb615a661833f45761030c55fcdf6 Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1675868 Tested-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
000ae5faa8
commit
9e9619fd4a
|
@ -47,11 +47,6 @@ enum {
|
|||
};
|
||||
extern const char *kVbootErrors[VBOOT_ERROR_MAX];
|
||||
|
||||
/**
|
||||
* Return offset of ptr from base.
|
||||
*/
|
||||
uint64_t OffsetOf(const void *base, const void *ptr);
|
||||
|
||||
/*
|
||||
* Helper functions to get data pointed to by a public key or signature.
|
||||
*/
|
||||
|
|
|
@ -28,11 +28,6 @@ const char *kVbootErrors[VBOOT_ERROR_MAX] = {
|
|||
"Shared data invalid."
|
||||
};
|
||||
|
||||
uint64_t OffsetOf(const void *base, const void *ptr)
|
||||
{
|
||||
return (uint64_t)(size_t)ptr - (uint64_t)(size_t)base;
|
||||
}
|
||||
|
||||
/* Helper functions to get data pointed to by a public key or signature. */
|
||||
|
||||
uint8_t *GetPublicKeyData(VbPublicKey *key)
|
||||
|
@ -65,7 +60,7 @@ int VerifyMemberInside(const void *parent, uint64_t parent_size,
|
|||
uint64_t member_data_offset,
|
||||
uint64_t member_data_size)
|
||||
{
|
||||
uint64_t end = OffsetOf(parent, member);
|
||||
uint64_t end = vb2_offset_of(parent, member);
|
||||
|
||||
if (end > parent_size)
|
||||
return 1;
|
||||
|
@ -107,7 +102,7 @@ int VerifySignatureInside(const void *parent, uint64_t parent_size,
|
|||
|
||||
void PublicKeyInit(VbPublicKey *key, uint8_t *key_data, uint64_t key_size)
|
||||
{
|
||||
key->key_offset = OffsetOf(key, key_data);
|
||||
key->key_offset = vb2_offset_of(key, key_data);
|
||||
key->key_size = key_size;
|
||||
key->algorithm = VB2_ALG_COUNT; /* Key not present yet */
|
||||
key->key_version = 0;
|
||||
|
|
|
@ -58,7 +58,6 @@ int main(void)
|
|||
VbVerifyMemoryBootImage(0, 0, 0, 0, 0);
|
||||
|
||||
/* vboot_common.h */
|
||||
OffsetOf(0, 0);
|
||||
GetPublicKeyData(0);
|
||||
GetPublicKeyDataC(0);
|
||||
GetSignatureData(0);
|
||||
|
|
|
@ -152,6 +152,8 @@ static void test_helper_functions(void)
|
|||
TEST_EQ((int)vb2_offset_of(p, p), 0, "vb2_offset_of() equal");
|
||||
TEST_EQ((int)vb2_offset_of(p, p+10), 10,
|
||||
"vb2_offset_of() positive");
|
||||
TEST_EQ((int)vb2_offset_of(p, p+0x12345678), 0x12345678,
|
||||
"vb2_offset_of() large");
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "2common.h"
|
||||
#include "host_common.h"
|
||||
#include "test_common.h"
|
||||
#include "utility.h"
|
||||
|
@ -54,27 +55,19 @@ static void ArraySizeTest(void)
|
|||
/* Helper functions not dependent on specific key sizes */
|
||||
static void VerifyHelperFunctions(void)
|
||||
{
|
||||
{
|
||||
uint8_t *p = (uint8_t *)VerifyHelperFunctions;
|
||||
TEST_EQ((int)OffsetOf(p, p), 0, "OffsetOf() equal");
|
||||
TEST_EQ((int)OffsetOf(p, p+10), 10, "OffsetOf() positive");
|
||||
TEST_EQ((int)OffsetOf(p, p+0x12345678), 0x12345678,
|
||||
"OffsetOf() large");
|
||||
}
|
||||
|
||||
{
|
||||
VbPublicKey k = {sizeof(k), 2, 3, 4};
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyData(&k)), sizeof(k),
|
||||
TEST_EQ((int)vb2_offset_of(&k, GetPublicKeyData(&k)), sizeof(k),
|
||||
"GetPublicKeyData() adjacent");
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyDataC(&k)), sizeof(k),
|
||||
TEST_EQ((int)vb2_offset_of(&k, GetPublicKeyDataC(&k)), sizeof(k),
|
||||
"GetPublicKeyDataC() adjacent");
|
||||
}
|
||||
|
||||
{
|
||||
VbPublicKey k = {123, 2, 3, 4};
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyData(&k)), 123,
|
||||
TEST_EQ((int)vb2_offset_of(&k, GetPublicKeyData(&k)), 123,
|
||||
"GetPublicKeyData() spaced");
|
||||
TEST_EQ((int)OffsetOf(&k, GetPublicKeyDataC(&k)), 123,
|
||||
TEST_EQ((int)vb2_offset_of(&k, GetPublicKeyDataC(&k)), 123,
|
||||
"GetPublicKeyDataC() spaced");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue