summaryrefslogtreecommitdiff
path: root/common/cbi.c
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2019-03-06 14:30:04 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-08 21:20:36 -0800
commit03e1bfd9a375d52236323978e151ed6fdc68a59a (patch)
treeb41877c37393778e0db294531953e8f9da839541 /common/cbi.c
parente87f148d10a5dc52dd2895f6567e6f03b8e7ea66 (diff)
downloadchrome-ec-03e1bfd9a375d52236323978e151ed6fdc68a59a.tar.gz
cbi: Do not add tags if data size is zero
This change skips adding a tag to CBI if the size of its data is zero. Thus, callers of optional tags do not need to worry about checking if a tag should be added. It is taken care of within cbi_set_data. BUG=b:124282048 BRANCH=None TEST=Verified that MODEL_ID no longer shows up in cbi data. Change-Id: Id0c3da87a1479f5c52bd7b4f06840e5b4476b3d6 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://chromium-review.googlesource.com/1506439 Commit-Ready: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common/cbi.c')
-rw-r--r--common/cbi.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/common/cbi.c b/common/cbi.c
index e4dc001184..8517506eec 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -34,6 +34,14 @@ uint8_t *cbi_set_data(uint8_t *p, enum cbi_data_tag tag,
const void *buf, int size)
{
struct cbi_data *d = (struct cbi_data *)p;
+
+ /*
+ * If size of the data to be added is zero, then no need to add the tag
+ * as well.
+ */
+ if (size == 0)
+ return p;
+
d->tag = tag;
d->size = size;
memcpy(d->value, buf, size);
@@ -185,12 +193,13 @@ int cbi_set_board_info(enum cbi_data_tag tag, const uint8_t *buf, uint8_t size)
}
if (!d) {
+ uint8_t *p;
/* Not found. Check if new item would fit */
if (sizeof(cbi) < head->total_size + sizeof(*d) + size)
return EC_ERROR_OVERFLOW;
/* Append new item */
- cbi_set_data(&cbi[head->total_size], tag, buf, size);
- head->total_size += (sizeof(*d) + size);
+ p = cbi_set_data(&cbi[head->total_size], tag, buf, size);
+ head->total_size = p - cbi;
} else {
/* Overwrite existing item */
memcpy(d->value, buf, d->size);