Skip to content

Commit e8a788c

Browse files
authored
Add counter check before accepting a Resource Config (#192)
--- Signed-off-by: Kartik Nema <kartnema@qti.qualcomm.com>
1 parent 030836e commit e8a788c

2 files changed

Lines changed: 63 additions & 5 deletions

File tree

resource-tuner/init/RestuneInit.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,9 @@ static ErrCode init(void* arg) {
494494
UrmSettings::metaConfigs.mPluginCount = (uint32_t)std::stol(resultBuffer);
495495

496496
uint32_t pluginCount = UrmSettings::metaConfigs.mPluginCount;
497-
if(pluginCount > MAX_EXTENSION_LIB_HANDLES) {
498-
extensionLibHandles = (void**) malloc(pluginCount * sizeof(void*));
499-
if(extensionLibHandles == nullptr) {
500-
return RC_MODULE_INIT_FAILURE;
501-
}
497+
extensionLibHandles = (void**) calloc(pluginCount, sizeof(void*));
498+
if(extensionLibHandles == nullptr) {
499+
return RC_MODULE_INIT_FAILURE;
502500
}
503501

504502
if(RC_IS_NOTOK(fetchMetaConfigs())) {

resource-tuner/init/RestuneParser.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,67 @@ static int8_t isKeyTypeList(const std::string& keyName) {
173173
return false;
174174
}
175175

176+
static int32_t onDeviceNodesCount(const std::string& filePath) {
177+
SETUP_LIBYAML_PARSING(filePath);
178+
179+
int8_t parsingDone = false;
180+
int8_t docMarker = false;
181+
int8_t parsingKey = false;
182+
int32_t count = 0;
183+
184+
std::string value = "";
185+
186+
while(!parsingDone) {
187+
if(!yaml_parser_parse(&parser, &event)) {
188+
return RC_YAML_PARSING_ERROR;
189+
}
190+
191+
switch(event.type) {
192+
case YAML_STREAM_END_EVENT:
193+
parsingDone = true;
194+
break;
195+
196+
case YAML_MAPPING_START_EVENT:
197+
if(!docMarker) {
198+
docMarker = true;
199+
}
200+
break;
201+
202+
case YAML_SCALAR_EVENT:
203+
if(event.data.scalar.value != nullptr) {
204+
value = reinterpret_cast<char*>(event.data.scalar.value);
205+
}
206+
207+
if(value == RESOURCE_CONFIGS_ELEM_RESOURCEPATH) {
208+
parsingKey = true;
209+
} else {
210+
if(parsingKey) {
211+
if(AuxRoutines::fileExists(value)) {
212+
count++;
213+
}
214+
}
215+
parsingKey = false;
216+
}
217+
218+
break;
219+
220+
default:
221+
break;
222+
}
223+
224+
yaml_event_delete(&event);
225+
}
226+
227+
TEARDOWN_LIBYAML_PARSING
228+
return count;
229+
}
230+
176231
ErrCode RestuneParser::parseResourceConfigYamlNode(const std::string& filePath) {
232+
if(onDeviceNodesCount(filePath) == 0) {
233+
// None of the nodes exsit, no need to parse these configs
234+
return RC_SUCCESS;
235+
}
236+
177237
SETUP_LIBYAML_PARSING(filePath);
178238

179239
ErrCode rc = RC_SUCCESS;

0 commit comments

Comments
 (0)