Skip to content

Commit cc30677

Browse files
hw/arm/apple-silicon: some minor cleanup
1 parent 5115272 commit cc30677

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

hw/arm/apple-silicon/boot.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,18 @@ static const char *REM_PROPS[] = {
237237
#endif
238238
};
239239

240-
static void *srawmemchr(void *str, int chr)
240+
static const char *srawmemchr(const char *str, int chr)
241241
{
242-
uint8_t *ptr = (uint8_t *)str;
243-
244-
while (*ptr != chr) {
245-
ptr++;
242+
while (*str != chr) {
243+
str++;
246244
}
247245

248-
return ptr;
246+
return str;
249247
}
250248

251249
static uint64_t sstrlen(const char *str)
252250
{
253-
const int chr = *(uint8_t *)"$";
254-
char *end = srawmemchr((void *)str, chr);
255-
256-
return end - str;
251+
return srawmemchr(str, '$') - str;
257252
}
258253

259254
static void apple_boot_process_dt_node(AppleDTNode *node, AppleDTNode *parent)
@@ -265,8 +260,7 @@ static void apple_boot_process_dt_node(AppleDTNode *node, AppleDTNode *parent)
265260
uint64_t i;
266261
bool found;
267262

268-
prop = apple_dt_get_prop(node, "compatible");
269-
if (prop != NULL) {
263+
if ((prop = apple_dt_get_prop(node, "compatible")) != NULL) {
270264
assert_nonnull(prop->data);
271265
found = false;
272266
for (count = sizeof(KEEP_COMP) / sizeof(KEEP_COMP[0]), i = 0; i < count;
@@ -289,8 +283,7 @@ static void apple_boot_process_dt_node(AppleDTNode *node, AppleDTNode *parent)
289283
}
290284
}
291285

292-
prop = apple_dt_get_prop(node, "name");
293-
if (prop != NULL) {
286+
if ((prop = apple_dt_get_prop(node, "name")) != NULL) {
294287
assert_nonnull(prop->data);
295288
for (count = sizeof(REM_NAMES) / sizeof(REM_NAMES[0]), i = 0; i < count;
296289
i++) {
@@ -305,8 +298,7 @@ static void apple_boot_process_dt_node(AppleDTNode *node, AppleDTNode *parent)
305298
}
306299
}
307300

308-
prop = apple_dt_get_prop(node, "device_type");
309-
if (prop != NULL) {
301+
if ((prop = apple_dt_get_prop(node, "device_type")) != NULL) {
310302
assert_nonnull(prop->data);
311303
for (count = sizeof(REM_DEV_TYPES) / sizeof(REM_DEV_TYPES[0]), i = 0;
312304
i < count; i++) {
@@ -363,7 +355,7 @@ static void extract_im4p_payload(const char *filename, char *payload_type,
363355

364356
if (asn1_array2tree(img4_definitions_array, &img4_definitions,
365357
errorDescription) != ASN1_SUCCESS) {
366-
error_setg(&error_fatal, "ASN.1 parser initialisation failed: `%s`.",
358+
error_setg(&error_fatal, "ASN.1 parser initialisation failed: `%s`",
367359
errorDescription);
368360
return;
369361
}
@@ -389,20 +381,20 @@ static void extract_im4p_payload(const char *filename, char *payload_type,
389381
len = 4;
390382
ret = asn1_read_value(img4, "magic", magic, &len);
391383
if (ret != ASN1_SUCCESS) {
392-
error_setg(&error_fatal, "im4p magic read for `%s` failed: %d.",
384+
error_setg(&error_fatal, "im4p magic read for `%s` failed: %d",
393385
filename, ret);
394386
return;
395387
}
396388

397389
if (memcmp(magic, "IM4P", 4) != 0) {
398-
error_setg(&error_fatal, "`%s` is not an img4 payload.", filename);
390+
error_setg(&error_fatal, "`%s` is not an img4 payload", filename);
399391
return;
400392
}
401393

402394
len = 4;
403395
ret = asn1_read_value(img4, "type", payload_type, &len);
404396
if (ret != ASN1_SUCCESS) {
405-
error_setg(&error_fatal, "img4 payload type read for `%s` failed: %d.",
397+
error_setg(&error_fatal, "img4 payload type read for `%s` failed: %d",
406398
filename, ret);
407399
return;
408400
}
@@ -411,15 +403,15 @@ static void extract_im4p_payload(const char *filename, char *payload_type,
411403
ret = asn1_read_value(img4, "description", description, &len);
412404
if (ret != ASN1_SUCCESS) {
413405
error_setg(&error_fatal,
414-
"img4 payload description read for `%s` failed: %d.",
406+
"img4 payload description read for `%s` failed: %d",
415407
filename, ret);
416408
return;
417409
}
418410

419411
len = 0;
420412
ret = asn1_read_value(img4, "data", NULL, &len);
421413
if (ret != ASN1_MEM_ERROR) {
422-
error_setg(&error_fatal, "img4 payload size read for `%s` failed: %d.",
414+
error_setg(&error_fatal, "img4 payload size read for `%s` failed: %d",
423415
filename, ret);
424416
return;
425417
}
@@ -429,7 +421,7 @@ static void extract_im4p_payload(const char *filename, char *payload_type,
429421
g_free(file_data);
430422

431423
if (ret != ASN1_SUCCESS) {
432-
error_setg(&error_fatal, "img4 payload read for `%s` failed: %d.",
424+
error_setg(&error_fatal, "img4 payload read for `%s` failed: %d",
433425
filename, ret);
434426
return;
435427
}
@@ -466,7 +458,7 @@ static void extract_im4p_payload(const char *filename, char *payload_type,
466458
int decoded_length =
467459
decompress_lzss(decode_buffer, comp_header->data, compressed_size);
468460
if (decoded_length == 0 || decoded_length != uncompressed_size) {
469-
error_setg(&error_fatal, "LZSS decompression for `%s` failed.",
461+
error_setg(&error_fatal, "LZSS decompression for `%s` failed",
470462
filename);
471463
g_free(decode_buffer);
472464
return;
@@ -718,8 +710,8 @@ uint8_t *apple_boot_load_trustcache_file(const char *filename, uint64_t *size)
718710
memcmp(payload_type, "rtsc", 4) != 0 &&
719711
memcmp(payload_type, "raw", 4) != 0) {
720712
error_setg(&error_fatal,
721-
"`%s` is a `%.4s` object (expected `trst`/`rtsc`).",
722-
filename, payload_type);
713+
"`%s` is a `%.4s` object (expected `trst`/`rtsc`)", filename,
714+
payload_type);
723715
return NULL;
724716
}
725717

0 commit comments

Comments
 (0)