Skip to content

Commit 6dd5021

Browse files
povikmarcan
authored andcommitted
gpu: drm: apple: Add utility functions for matching on dict keys
Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
1 parent 592b582 commit 6dd5021

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

drivers/gpu/drm/apple/parser.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,39 @@ static int skip(struct dcp_parse_ctx *handle)
117117
}
118118
}
119119

120+
static int skip_pair(struct dcp_parse_ctx *handle)
121+
{
122+
int ret;
123+
124+
ret = skip(handle);
125+
if (ret)
126+
return ret;
127+
128+
return skip(handle);
129+
}
130+
131+
static bool consume_string(struct dcp_parse_ctx *ctx, const char *specimen)
132+
{
133+
struct dcp_parse_tag *tag;
134+
const char *key;
135+
ctx->pos = round_up(ctx->pos, 4);
136+
137+
if (ctx->pos + sizeof(*tag) + strlen(specimen) - 1 > ctx->len)
138+
return false;
139+
tag = ctx->blob + ctx->pos;
140+
key = ctx->blob + ctx->pos + sizeof(*tag);
141+
if (tag->padding)
142+
return false;
143+
144+
if (tag->type != DCP_TYPE_STRING ||
145+
tag->size != strlen(specimen) ||
146+
strncmp(key, specimen, tag->size))
147+
return false;
148+
149+
skip(ctx);
150+
return true;
151+
}
152+
120153
/* Caller must free the result */
121154
static char *parse_string(struct dcp_parse_ctx *handle)
122155
{

0 commit comments

Comments
 (0)