Edward O'Callaghan has uploaded this change for review.
amd_imc.c: Cleanup C89ism and redundant NULL check
A bit of spring cleaning here to freshen up some C89ism's,
drop a redundant NULLality check in a static local function
and canonicalise branch predictions. Also const correct some
static locals while here.
This makes the code overall shorter and more consistent and
succinct.
Change-Id: I1dbae500010fa50a67609efb3cbb5778b684ad04
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M amd_imc.c
1 file changed, 27 insertions(+), 24 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/59/75359/1
diff --git a/amd_imc.c b/amd_imc.c
index d57728e..e50aa48 100644
--- a/amd_imc.c
+++ b/amd_imc.c
@@ -34,21 +34,12 @@
static uint16_t get_sio_port(struct pci_dev *dev)
{
- uint16_t ec_port;
-
- if (!dev) {
- return 0;
- }
-
- ec_port = pci_read_word(dev, 0xa4);
-
/* EcPortActive? */
+ const uint16_t ec_port = pci_read_word(dev, 0xa4);
if (!(ec_port & 0x1))
return 0;
- ec_port &= ~0x1;
-
- return ec_port;
+ return ec_port & ~0x1;
}
/* Wait for up to 10 ms for a response. */
@@ -67,8 +58,6 @@
static uint16_t mbox_get_port(uint16_t sio_port)
{
- uint16_t mbox_port;
-
enter_conf_mode_ec(sio_port);
/* Go to LDN 9, mailbox */
@@ -80,7 +69,7 @@
return 0;
}
- mbox_port = sio_read(sio_port, 0x60) << 8;
+ uint16_t mbox_port = sio_read(sio_port, 0x60) << 8;
mbox_port |= sio_read(sio_port, 0x61);
exit_conf_mode_ec(sio_port);
@@ -90,19 +79,16 @@
/* Returns negative values when IMC is inactive, positive values on errors */
static int imc_send_cmd(struct pci_dev *dev, uint8_t cmd)
{
- uint16_t sio_port;
- uint16_t mbox_port;
-
/* IntegratedEcPresent? */
if (!(pci_read_byte(dev, 0x40) & (1 << 7)))
return -1;
- sio_port = get_sio_port(dev);
+ const uint16_t sio_port = get_sio_port(dev);
if (!sio_port)
return -1;
msg_pdbg2("IMC SIO is at 0x%x.\n", sio_port);
- mbox_port = mbox_get_port(sio_port);
+ const uint16_t mbox_port = mbox_get_port(sio_port);
if (!mbox_port)
return -1;
msg_pdbg2("IMC MBOX is at 0x%x.\n", mbox_port);
@@ -119,9 +105,8 @@
static int imc_resume(void *data)
{
struct pci_dev *dev = data;
- int ret = imc_send_cmd(dev, 0xb5);
-
- if (ret != 0)
+ const int ret = imc_send_cmd(dev, 0xb5);
+ if (ret)
msg_pinfo("Resuming IMC failed.\n");
else
msg_pdbg2("IMC resumed.\n");
@@ -131,7 +116,7 @@
int amd_imc_shutdown(struct pci_dev *dev)
{
/* Try to put IMC to sleep */
- int ret = imc_send_cmd(dev, 0xb4);
+ const int ret = imc_send_cmd(dev, 0xb4);
/* No IMC activity detectable, assume we are fine */
if (ret < 0) {
@@ -139,7 +124,7 @@
return 0;
}
- if (ret != 0) {
+ if (ret) {
msg_perr("Shutting down IMC failed.\n");
return ret;
}
To view, visit change 75359. To unsubscribe, or for help writing mail filters, visit settings.