1 // SPDX-License-Identifier: GPL-2.0-only
5 * Google VPD decoding routines.
7 * Copyright 2017 Google Inc.
10 #include "vpd_decode.h"
12 static int vpd_decode_len(const s32 max_len, const u8 *in,
13 s32 *length, s32 *decoded_len)
18 if (!length || !decoded_len)
28 *length |= in[i] & 0x7f;
37 int vpd_decode_string(const s32 max_len, const u8 *input_buf, s32 *consumed,
38 vpd_decode_callback callback, void *callback_arg)
49 if (*consumed >= max_len)
52 type = input_buf[*consumed];
60 res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
61 &key_len, &decoded_len);
62 if (res != VPD_OK || *consumed + decoded_len >= max_len)
65 *consumed += decoded_len;
66 key = &input_buf[*consumed];
70 res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
71 &value_len, &decoded_len);
72 if (res != VPD_OK || *consumed + decoded_len > max_len)
75 *consumed += decoded_len;
76 value = &input_buf[*consumed];
77 *consumed += value_len;
79 if (type == VPD_TYPE_STRING)
80 return callback(key, key_len, value, value_len,