4 * Google VPD decoding routines.
6 * Copyright 2017 Google Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License v2.0 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/export.h>
20 #include "vpd_decode.h"
22 static int vpd_decode_len(const s32 max_len, const u8 *in,
23 s32 *length, s32 *decoded_len)
28 if (!length || !decoded_len)
38 *length |= in[i] & 0x7f;
47 int vpd_decode_string(const s32 max_len, const u8 *input_buf, s32 *consumed,
48 vpd_decode_callback callback, void *callback_arg)
59 if (*consumed >= max_len)
62 type = input_buf[*consumed];
70 res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
71 &key_len, &decoded_len);
72 if (res != VPD_OK || *consumed + decoded_len >= max_len)
75 *consumed += decoded_len;
76 key = &input_buf[*consumed];
80 res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
81 &value_len, &decoded_len);
82 if (res != VPD_OK || *consumed + decoded_len > max_len)
85 *consumed += decoded_len;
86 value = &input_buf[*consumed];
87 *consumed += value_len;
89 if (type == VPD_TYPE_STRING)
90 return callback(key, key_len, value, value_len,