From: Jan Kiszka <
jan.k...@siemens.com>
Improve the consistency of our coding style use, mostly around
encapsulating even single-line-blocks in braces and avoiding assignments
in if statements.
Signed-off-by: Jan Kiszka <
jan.k...@siemens.com>
---
drivers/watchdog/atom-quark.c | 27 ++++++++++++++++++---------
drivers/watchdog/i6300esb.c | 18 ++++++++++++------
drivers/watchdog/itco.c | 33 ++++++++++++++++++++++-----------
env/env_api_fat.c | 11 +++++++----
env/env_config_file.c | 3 +--
env/env_disk_utils.c | 10 ++++++----
env/uservars.c | 3 ++-
main.c | 31 ++++++++++++++++++++-----------
tools/bg_setenv.c | 3 ++-
tools/ebgpart.c | 6 ++++--
tools/tests/fake_devices.c | 15 ++++++++-------
tools/tests/test_ebgenv_api_internal.c | 9 ++++++---
tools/tests/test_probe_config_file.c | 14 +++++++-------
13 files changed, 115 insertions(+), 68 deletions(-)
diff --git a/drivers/watchdog/atom-quark.c b/drivers/watchdog/atom-quark.c
index ccf2adb..4e6f9ba 100644
--- a/drivers/watchdog/atom-quark.c
+++ b/drivers/watchdog/atom-quark.c
@@ -41,8 +41,9 @@ static EFI_STATUS unlock_timer_regs(EFI_PCI_IO *pci_io, UINT32 wdt_base)
EfiPciIoWidthUint8,
EFI_PCI_IO_PASS_THROUGH_BAR,
wdt_base + RELOAD0_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = 0x86;
return uefi_call_wrapper(pci_io->Io.Write, 6, pci_io,
@@ -58,15 +59,17 @@ static EFI_STATUS write_timer_regs(EFI_PCI_IO *pci_io, UINT32 wdt_base,
EFI_STATUS status;
status = unlock_timer_regs(pci_io, wdt_base);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
status = uefi_call_wrapper(pci_io->Io.Write, 6, pci_io,
EfiPciIoWidthUint8,
EFI_PCI_IO_PASS_THROUGH_BAR,
wdt_base + timer, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value >>= 8;
timer++;
@@ -85,17 +88,20 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
if (!pci_io || pci_vendor_id != PCI_VENDOR_ID_INTEL ||
(pci_device_id != PCI_DEVICE_ID_INTEL_ITC &&
pci_device_id != PCI_DEVICE_ID_INTEL_CENTERTON &&
- pci_device_id != PCI_DEVICE_ID_INTEL_QUARK_X1000))
+ pci_device_id != PCI_DEVICE_ID_INTEL_QUARK_X1000)) {
return EFI_UNSUPPORTED;
+ }
status = uefi_call_wrapper(pci_io->Pci.Read, 5, pci_io,
EfiPciIoWidthUint32, WDTBA_REG,
1, &wdt_base);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
- if (!(wdt_base & WDTBA_ENABLED))
+ if (!(wdt_base & WDTBA_ENABLED)) {
return EFI_UNSUPPORTED;
+ }
wdt_base &= WDTBA_ADDRMASK;
@@ -103,21 +109,24 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
value = ((timeout * 1000000000ULL) >> 15) / 30;
status = write_timer_regs(pci_io, wdt_base, TIMER1_REG, value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = 0;
status = write_timer_regs(pci_io, wdt_base, TIMER2_REG, value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = CONFIG_RESET_ENABLE;
status = uefi_call_wrapper(pci_io->Io.Write, 6, pci_io,
EfiPciIoWidthUint8,
EFI_PCI_IO_PASS_THROUGH_BAR,
wdt_base + CONFIG_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = LOCK_WDT_ENABLE | LOCK_WDT_LOCK;
status = uefi_call_wrapper(pci_io->Io.Write, 6, pci_io,
diff --git a/drivers/watchdog/i6300esb.c b/drivers/watchdog/i6300esb.c
index 11c3260..10babd4 100644
--- a/drivers/watchdog/i6300esb.c
+++ b/drivers/watchdog/i6300esb.c
@@ -33,8 +33,9 @@ static EFI_STATUS unlock_timer_regs(EFI_PCI_IO *pci_io)
status = uefi_call_wrapper(pci_io->Mem.Write, 6, pci_io,
EfiPciIoWidthUint32, 0, ESB_RELOAD_REG,
1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = 0x86;
return uefi_call_wrapper(pci_io->Mem.Write, 6, pci_io,
@@ -50,32 +51,37 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
UINT32 value;
if (!pci_io || pci_vendor_id != PCI_VENDOR_ID_INTEL ||
- pci_device_id != PCI_DEVICE_ID_INTEL_ESB_9)
+ pci_device_id != PCI_DEVICE_ID_INTEL_ESB_9) {
return EFI_UNSUPPORTED;
+ }
Print(L"Detected i6300ESB watchdog\n");
status = unlock_timer_regs(pci_io);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = ((timeout * 1000000000ULL) >> 15) / 30;
status = uefi_call_wrapper(pci_io->Mem.Write, 6, pci_io,
EfiPciIoWidthUint32, 0, ESB_TIMER1_REG,
1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
status = unlock_timer_regs(pci_io);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = 0;
status = uefi_call_wrapper(pci_io->Mem.Write, 6, pci_io,
EfiPciIoWidthUint32, 0, ESB_TIMER2_REG,
1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value = ESB_LOCK_WDT_ENABLE | ESB_LOCK_WDT_LOCK;
status = uefi_call_wrapper(pci_io->Pci.Write, 5, pci_io,
diff --git a/drivers/watchdog/itco.c b/drivers/watchdog/itco.c
index 7c93afb..35be0c3 100644
--- a/drivers/watchdog/itco.c
+++ b/drivers/watchdog/itco.c
@@ -42,8 +42,9 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
if (!pci_io || pci_vendor_id != PCI_VENDOR_ID_INTEL ||
(pci_device_id != PCI_DEVICE_ID_INTEL_BAYTRAIL &&
- pci_device_id != PCI_DEVICE_ID_INTEL_WPT_LP))
+ pci_device_id != PCI_DEVICE_ID_INTEL_WPT_LP)) {
return EFI_UNSUPPORTED;
+ }
Print(L"Detected Intel TCO watchdog\n");
@@ -51,8 +52,9 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
status = uefi_call_wrapper(pci_io->Pci.Read, 5, pci_io,
EfiPciIoWidthUint32, PMBASE_REG,
1, &pmbase);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
pmbase &= PMBASE_ADDRMASK;
tcobase = (pmbase & PMBASE_ADDRMASK) + 0x60;
@@ -60,8 +62,9 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
status = uefi_call_wrapper(pci_io->Pci.Read, 5, pci_io,
EfiPciIoWidthUint32, PMCBASE_REG,
1, &pmcbase);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
pmcbase &= PMCBASE_ADDRMASK;
/* Enable TCO SMIs */
@@ -69,31 +72,35 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
EfiPciIoWidthUint32,
EFI_PCI_IO_PASS_THROUGH_BAR,
pmbase + SMI_EN_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value |= TCO_EN;
status = uefi_call_wrapper(pci_io->Io.Write, 6, pci_io,
EfiPciIoWidthUint32,
EFI_PCI_IO_PASS_THROUGH_BAR,
pmbase + SMI_EN_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
/* Set timer value */
status = uefi_call_wrapper(pci_io->Io.Read, 6, pci_io,
EfiPciIoWidthUint16,
EFI_PCI_IO_PASS_THROUGH_BAR,
tcobase + TCO_TMR_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value &= 0xfc00;
value |= ((timeout * 10) / 6) & 0x3ff;
status = uefi_call_wrapper(pci_io->Io.Write, 6, pci_io,
EfiPciIoWidthUint16,
EFI_PCI_IO_PASS_THROUGH_BAR,
tcobase + TCO_TMR_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
/* Force reloading of timer value */
value = 1;
@@ -101,31 +108,35 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id,
EfiPciIoWidthUint16,
EFI_PCI_IO_PASS_THROUGH_BAR,
tcobase + TCO_RLD_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
/* Clear NO_REBOOT flag */
status = uefi_call_wrapper(pci_io->Mem.Read, 6, pci_io,
EfiPciIoWidthUint32,
EFI_PCI_IO_PASS_THROUGH_BAR,
pmcbase + PMC_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value &= ~PMC_NO_REBOOT;
status = uefi_call_wrapper(pci_io->Mem.Write, 6, pci_io,
EfiPciIoWidthUint32,
EFI_PCI_IO_PASS_THROUGH_BAR,
pmcbase + PMC_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
/* Clear HLT flag to start timer */
status = uefi_call_wrapper(pci_io->Io.Read, 6, pci_io,
EfiPciIoWidthUint16,
EFI_PCI_IO_PASS_THROUGH_BAR,
tcobase + TCO1_CNT_REG, 1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
value &= ~TCO_TMR_HLT;
status = uefi_call_wrapper(pci_io->Io.Write, 6, pci_io,
EfiPciIoWidthUint16,
diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 0aef867..0351330 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -425,23 +425,26 @@ int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
return 0;
}
-BGENV *bgenv_create_new()
+BGENV *bgenv_create_new(void)
{
BGENV *env_latest;
BGENV *env_new;
env_latest = bgenv_open_latest();
- if (!env_latest)
+ if (!env_latest) {
goto create_new_io_error;
+ }
int new_rev = env_latest->data->revision + 1;
- if (!bgenv_close(env_latest))
+ if (!bgenv_close(env_latest)) {
goto create_new_io_error;
+ }
env_new = bgenv_open_oldest();
- if (!env_new)
+ if (!env_new) {
goto create_new_io_error;
+ }
/* zero fields */
memset(env_new->data, 0, sizeof(BG_ENVDATA));
diff --git a/env/env_config_file.c b/env/env_config_file.c
index 8f3a562..69a707a 100644
--- a/env/env_config_file.c
+++ b/env/env_config_file.c
@@ -40,8 +40,7 @@ FILE *open_config_file(CONFIG_PART *cfgpart, char *mode)
int close_config_file(FILE *config_file_handle)
{
- if (config_file_handle)
- {
+ if (config_file_handle) {
return fclose(config_file_handle);
}
return EINVAL;
diff --git a/env/env_disk_utils.c b/env/env_disk_utils.c
index 0a1ff09..4807ad1 100644
--- a/env/env_disk_utils.c
+++ b/env/env_disk_utils.c
@@ -23,18 +23,20 @@ char *get_mountpoint(char *devpath)
struct mntent *part = NULL;
FILE *mtab = NULL;
- if ((mtab = setmntent("/proc/mounts", "r")) == NULL)
+ mtab = setmntent("/proc/mounts", "r");
+ if (!mtab) {
return NULL;
+ }
while ((part = getmntent(mtab)) != NULL) {
if ((part->mnt_fsname != NULL) &&
(strcmp(part->mnt_fsname, devpath)) == 0) {
char *mntpoint;
- if (!(mntpoint =
- malloc(strlen(part->mnt_dir) + 1))) {
+ mntpoint = malloc(strlen(part->mnt_dir) + 1);
+ if (!mntpoint) {
break;
- };
+ }
strncpy(mntpoint, part->mnt_dir,
strlen(part->mnt_dir) + 1);
return mntpoint;
diff --git a/env/uservars.c b/env/uservars.c
index 4952624..eff1cf8 100644
--- a/env/uservars.c
+++ b/env/uservars.c
@@ -269,8 +269,9 @@ uint32_t bgenv_user_free(uint8_t *udata)
while (*udata) {
bgenv_map_uservar(udata, NULL, NULL, NULL, &rsize, NULL);
spaceleft -= rsize;
- if (spaceleft == 0)
+ if (spaceleft == 0) {
break;
+ }
udata = bgenv_next_uservar(udata);
}
diff --git a/main.c b/main.c
index 5bf38df..b71f811 100644
--- a/main.c
+++ b/main.c
@@ -34,8 +34,9 @@ static EFI_STATUS probe_watchdog(EFI_LOADED_IMAGE *loaded_image,
probe = loaded_image->ImageBase + *entry;
if (probe(pci_io, pci_vendor_id, pci_device_id, timeout) ==
- EFI_SUCCESS)
+ EFI_SUCCESS) {
return EFI_SUCCESS;
+ }
}
return EFI_UNSUPPORTED;
@@ -51,13 +52,14 @@ static EFI_STATUS scan_devices(EFI_LOADED_IMAGE *loaded_image, UINTN timeout)
status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol,
&PciIoProtocol, NULL, &size, devices);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
return status;
+ }
count = size / sizeof(EFI_HANDLE);
-
- if (count == 0)
+ if (count == 0) {
return probe_watchdog(loaded_image, NULL, 0, 0, timeout);
+ }
do {
EFI_HANDLE device = devices[count - 1];
@@ -68,18 +70,20 @@ static EFI_STATUS scan_devices(EFI_LOADED_IMAGE *loaded_image, UINTN timeout)
&PciIoProtocol, (VOID **)&pci_io,
this_image, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
error_exit(L"Could not open PciIoProtocol while "
L"probing watchdogs.",
status);
+ }
status = uefi_call_wrapper(pci_io->Pci.Read, 5, pci_io,
EfiPciIoWidthUint32, PCI_VENDOR_ID,
1, &value);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
error_exit(L"Could not read from PCI device while "
L"probing watchdogs.",
status);
+ }
status = probe_watchdog(loaded_image, pci_io, (UINT16)value,
value >> 16, timeout);
@@ -111,10 +115,11 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
uefi_call_wrapper(BS->OpenProtocol, 6, this_image,
&LoadedImageProtocol, (VOID **)&loaded_image,
this_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
error_exit(L"Could not open LoadedImageProtocol to get image "
L"information.",
status);
+ }
status = get_volumes(&volumes, &volume_count);
if (EFI_ERROR(status)) {
@@ -146,29 +151,33 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
payload_dev_path = FileDevicePathFromConfig(
loaded_image->DeviceHandle, bg_loader_params.payload_path);
- if (!payload_dev_path)
+ if (!payload_dev_path) {
error_exit(
L"Could not convert payload file path to device path.",
EFI_OUT_OF_RESOURCES);
+ }
status = scan_devices(loaded_image, bg_loader_params.timeout);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
error_exit(L"Could not probe watchdog.", status);
+ }
/* Load and start image */
status = uefi_call_wrapper(BS->LoadImage, 6, TRUE, this_image,
payload_dev_path, NULL, 0, &payload_handle);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
error_exit(L"Could not load specified kernel image.", status);
+ }
status =
uefi_call_wrapper(BS->OpenProtocol, 6, payload_handle,
&LoadedImageProtocol, (VOID **)&loaded_image,
this_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR(status))
+ if (EFI_ERROR(status)) {
error_exit(L"Could not open LoadedImageProtocol to set kernel "
L"load options.",
status);
+ }
loaded_image->LoadOptions = bg_loader_params.payload_options;
loaded_image->LoadOptionsSize =
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index f257361..df2f182 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -69,8 +69,9 @@ static bool inhibit_global_store = false;
static void journal_free_action(struct env_action *action)
{
- if (!action)
+ if (!action) {
return;
+ }
free(action->data);
free(action->key);
free(action);
diff --git a/tools/ebgpart.c b/tools/ebgpart.c
index 41194a5..262b1c5 100644
--- a/tools/ebgpart.c
+++ b/tools/ebgpart.c
@@ -494,8 +494,9 @@ pedprobe_error:
static void ped_partition_destroy(PedPartition *p)
{
- if (!p)
+ if (!p) {
return;
+ }
if (p->fs_type) {
free(p->fs_type->name);
free(p->fs_type);
@@ -505,8 +506,9 @@ static void ped_partition_destroy(PedPartition *p)
static void ped_device_destroy(PedDevice *d)
{
- if (!d)
+ if (!d) {
return;
+ }
free(d->model);
free(d->path);
PedPartition *p = d->part_list;
diff --git a/tools/tests/fake_devices.c b/tools/tests/fake_devices.c
index 2aa149b..5e03471 100644
--- a/tools/tests/fake_devices.c
+++ b/tools/tests/fake_devices.c
@@ -22,8 +22,9 @@ int num_fake_devices;
void allocate_fake_devices(int n)
{
fake_devices = (PedDevice *)calloc(n, sizeof(PedDevice));
- if (!fake_devices)
+ if (!fake_devices) {
exit(1);
+ }
num_fake_devices = n;
for (char i = 0; i < n; i++) {
if (asprintf(&fake_devices[i].model, "%s", "Fake Device")
@@ -83,11 +84,10 @@ void remove_fake_partitions(int n)
PedPartition *next;
while(pp) {
next = pp->next;
- if (!pp->fs_type)
- goto skip_fstype;
- free(pp->fs_type->name);
- free(pp->fs_type);
-skip_fstype:
+ if (pp->fs_type) {
+ free(pp->fs_type->name);
+ free(pp->fs_type);
+ }
free(pp);
pp = next;
}
@@ -110,8 +110,9 @@ void free_fake_devices()
PedDevice *ped_device_get_next_custom_fake(const PedDevice *dev)
{
- if (!dev)
+ if (!dev) {
return fake_devices;
+ }
return dev->next;
}
diff --git a/tools/tests/test_ebgenv_api_internal.c b/tools/tests/test_ebgenv_api_internal.c
index d826578..868218d 100644
--- a/tools/tests/test_ebgenv_api_internal.c
+++ b/tools/tests/test_ebgenv_api_internal.c
@@ -167,8 +167,9 @@ START_TEST(ebgenv_api_internal_bgenv_write)
BGENV *dummy_env;
dummy_env = calloc(1, sizeof(BGENV));
- if (!dummy_env)
+ if (!dummy_env) {
goto bgew_error;
+ }
RESET_FAKE(write_env);
write_env_fake.custom_fake = write_env_custom_fake;
@@ -190,12 +191,14 @@ START_TEST(ebgenv_api_internal_bgenv_write)
* and envrionment data succeeds
*/
dummy_env->desc = calloc(1, sizeof(CONFIG_PART));
- if (!dummy_env->desc)
+ if (!dummy_env->desc) {
goto bgew_error;
+ }
dummy_env->data = calloc(1, sizeof(BG_ENVDATA));
- if (!dummy_env->data)
+ if (!dummy_env->data) {
goto bgew_error;
+ }
res = bgenv_write(dummy_env);
ck_assert(write_env_fake.call_count == 1);
diff --git a/tools/tests/test_probe_config_file.c b/tools/tests/test_probe_config_file.c
index f4a9b9d..63e9a25 100644
--- a/tools/tests/test_probe_config_file.c
+++ b/tools/tests/test_probe_config_file.c
@@ -49,15 +49,15 @@ char *get_mountpoint_custom_fake(char *devpath)
char *tmpdir = NULL;
char *tmpfile = NULL;
- if (asprintf(&tmpdir, "%s", fake_mountpoint) == -1)
- {
+ if (asprintf(&tmpdir, "%s", fake_mountpoint) == -1) {
tmpdir = NULL;
goto fake_mountpoint_error;
}
tmpdir = mkdtemp(tmpdir);
- if (!tmpdir)
+ if (!tmpdir) {
goto fake_mountpoint_error;
+ }
if (asprintf(&buff, "%s", tmpdir) == -1) {
buff = NULL;
@@ -83,13 +83,14 @@ char *get_mountpoint_custom_fake(char *devpath)
struct fake_env_file_path *fefp;
fefp = malloc(sizeof(struct fake_env_file_path));
- if (!fefp)
+ if (!fefp) {
goto fake_mountpoint_error;
+ }
char *buffer_copy;
if (asprintf(&buffer_copy, "%s", buff) == -1) {
goto fake_mountpoint_error;
- };
+ }
if (fefp && buffer_copy) {
fefp->path = buffer_copy;
@@ -109,8 +110,7 @@ bool __wrap_probe_config_file(CONFIG_PART *cp)
bool ret;
probe_config_file_call_count++;
- if (asprintf(&cp->mountpoint, "tmpdir") == -1)
- {
+ if (asprintf(&cp->mountpoint, "tmpdir") == -1) {
cp->not_mounted = true;
cp->mountpoint = NULL;
return false;
--
2.12.3