1 // SPDX-License-Identifier: GPL-2.0-only
5 * Google VPD decoding routines.
7 * Copyright 2017 Google Inc.
10 #include <linux/export.h>
12 #include "vpd_decode.h"
14 static int vpd_decode_len(const s32 max_len, const u8 *in,
15 s32 *length, s32 *decoded_len)
20 if (!length || !decoded_len)
30 *length |= in[i] & 0x7f;
39 int vpd_decode_string(const s32 max_len, const u8 *input_buf, s32 *consumed,
40 vpd_decode_callback callback, void *callback_arg)
51 if (*consumed >= max_len)
54 type = input_buf[*consumed];
62 res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
63 &key_len, &decoded_len);
64 if (res != VPD_OK || *consumed + decoded_len >= max_len)
67 *consumed += decoded_len;
68 key = &input_buf[*consumed];
72 res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
73 &value_len, &decoded_len);
74 if (res != VPD_OK || *consumed + decoded_len > max_len)
77 *consumed += decoded_len;
78 value = &input_buf[*consumed];
79 *consumed += value_len;
81 if (type == VPD_TYPE_STRING)
82 return callback(key, key_len, value, value_len,