Edward O'Callaghan submitted this change.

View Change


Approvals: build bot (Jenkins): Verified Sam McNally: Looks good to me, approved
dmi.c: Pass is_laptop by ref into dmi

Prefix the remaining global cases with `g_` to avoid shadowing
issues and for easy greping.

Change-Id: I3d5ad6c0623269492d775a99a947fd6fe26c5f91
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/71622
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Sam McNally <sammc@google.com>
---
M board_enable.c
M dmi.c
M include/programmer.h
M internal.c
4 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/board_enable.c b/board_enable.c
index f0df211..0531fab 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -2282,7 +2282,7 @@
static int p2_not_a_laptop(void)
{
/* label this board as not a laptop */
- is_laptop = 0;
+ g_is_laptop = 0;
msg_pdbg("Laptop detection overridden by P2 board enable.\n");
return 0;
}
@@ -2292,7 +2292,7 @@
*/
static int p2_whitelist_laptop(void)
{
- is_laptop = 1;
+ g_is_laptop = 1;
g_laptop_ok = true;
msg_pdbg("Whitelisted laptop detected.\n");
return 0;
diff --git a/dmi.c b/dmi.c
index beeb10f..94e47fb 100644
--- a/dmi.c
+++ b/dmi.c
@@ -151,11 +151,11 @@
return newbuf;
}

-static void dmi_chassis_type(uint8_t code)
+static int dmi_chassis_type(uint8_t code)
{
unsigned int i;
code &= 0x7f; /* bits 6:0 are chassis type, 7th bit is the lock bit */
- is_laptop = 2;
+ int is_laptop = 2;
for (i = 0; i < ARRAY_SIZE(dmi_chassis_types); i++) {
if (code == dmi_chassis_types[i].type) {
msg_pdbg("DMI string chassis-type: \"%s\"\n", dmi_chassis_types[i].name);
@@ -163,9 +163,10 @@
break;
}
}
+ return is_laptop;
}

-static void dmi_table(uint32_t base, uint16_t len, uint16_t num)
+static void dmi_table(uint32_t base, uint16_t len, uint16_t num, int *is_laptop)
{
unsigned int i = 0, j = 0;

@@ -198,7 +199,7 @@

if(data[0] == 3) {
if (data + 5 < limit)
- dmi_chassis_type(data[5]);
+ *is_laptop = dmi_chassis_type(data[5]);
else /* the table is broken, but laptop detection is optional, hence continue. */
msg_pwarn("DMI table is broken (chassis_type out of bounds)!\n");
} else
@@ -232,7 +233,7 @@
}

#if SM_SUPPORT
-static int smbios_decode(uint8_t *buf)
+static int smbios_decode(uint8_t *buf, int *is_laptop)
{
/* TODO: other checks mentioned in the conformance guidelines? */
if (!dmi_checksum(buf, buf[0x05]) ||
@@ -240,23 +241,23 @@
!dmi_checksum(buf + 0x10, 0x0F))
return 0;

- dmi_table(mmio_readl(buf + 0x18), mmio_readw(buf + 0x16), mmio_readw(buf + 0x1C));
+ dmi_table(mmio_readl(buf + 0x18), mmio_readw(buf + 0x16), mmio_readw(buf + 0x1C), is_laptop);

return 1;
}
#endif

-static int legacy_decode(uint8_t *buf)
+static int legacy_decode(uint8_t *buf, int *is_laptop)
{
if (!dmi_checksum(buf, 0x0F))
return 1;

- dmi_table(mmio_readl(buf + 0x08), mmio_readw(buf + 0x06), mmio_readw(buf + 0x0C));
+ dmi_table(mmio_readl(buf + 0x08), mmio_readw(buf + 0x06), mmio_readw(buf + 0x0C), is_laptop);

return 0;
}

-static int dmi_fill(void)
+static int dmi_fill(int *is_laptop)
{
size_t fp;
uint8_t *dmi_mem;
@@ -274,12 +275,12 @@
for (fp = 0; fp <= 0xFFF0; fp += 16) {
#if SM_SUPPORT
if (memcmp(dmi_mem + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
- if (smbios_decode(dmi_mem + fp)) // FIXME: length check
+ if (smbios_decode(dmi_mem + fp), is_laptop) // FIXME: length check
goto out;
} else
#endif
if (memcmp(dmi_mem + fp, "_DMI_", 5) == 0)
- if (legacy_decode(dmi_mem + fp) == 0) {
+ if (legacy_decode(dmi_mem + fp, is_laptop) == 0) {
ret = 0;
goto out;
}
@@ -350,7 +351,7 @@
return result;
}

-static int dmi_fill(void)
+static int dmi_fill(int *is_laptop)
{
unsigned int i;
char *chassis_type;
@@ -367,10 +368,10 @@
return 0; /* chassis-type handling is optional anyway */

msg_pdbg("DMI string chassis-type: \"%s\"\n", chassis_type);
- is_laptop = 2;
+ *is_laptop = 2;
for (i = 0; i < ARRAY_SIZE(dmi_chassis_types); i++) {
if (strcasecmp(chassis_type, dmi_chassis_types[i].name) == 0) {
- is_laptop = dmi_chassis_types[i].is_laptop;
+ *is_laptop = dmi_chassis_types[i].is_laptop;
break;
}
}
@@ -391,7 +392,7 @@
return 0;
}

-void dmi_init(void)
+void dmi_init(int *is_laptop)
{
/* Register shutdown function before we allocate anything. */
if (register_shutdown(dmi_shutdown, NULL)) {
@@ -399,11 +400,11 @@
return;
}

- /* dmi_fill fills the dmi_strings array, and if possible sets the global is_laptop variable. */
- if (dmi_fill() != 0)
+ /* dmi_fill fills the dmi_strings array, and if possible set the is_laptop parameter. */
+ if (dmi_fill(is_laptop) != 0)
return;

- switch (is_laptop) {
+ switch (*is_laptop) {
case 1:
msg_pdbg("Laptop detected via DMI.\n");
break;
diff --git a/include/programmer.h b/include/programmer.h
index 304a216..ab482e6 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -244,7 +244,7 @@

/* dmi.c */
#if defined(__i386__) || defined(__x86_64__)
-void dmi_init(void);
+void dmi_init(int *is_laptop);
bool dmi_is_supported(void);
int dmi_match(const char *pattern);
#endif // defined(__i386__) || defined(__x86_64__)
@@ -263,7 +263,7 @@
#endif

#if CONFIG_INTERNAL == 1
-extern int is_laptop;
+extern int g_is_laptop;
extern bool g_laptop_ok;
extern bool force_boardmismatch;
void probe_superio(void);
diff --git a/internal.c b/internal.c
index 0c23326..5d836e5 100644
--- a/internal.c
+++ b/internal.c
@@ -27,7 +27,7 @@
#include "hwaccess_x86_io.h"
#endif

-int is_laptop = 0;
+int g_is_laptop = 0;
bool g_laptop_ok = false;

bool force_boardmismatch = false;
@@ -108,12 +108,11 @@
return 0;
}

-// FIXME: remove '_' suffix from parameters once global shadowing is fixed.
-static void report_nonwl_laptop_detected(int is_laptop_, bool laptop_ok)
+static void report_nonwl_laptop_detected(int is_laptop, bool laptop_ok)
{
- if (is_laptop_ && !laptop_ok) {
+ if (is_laptop && !laptop_ok) {
msg_pinfo("========================================================================\n");
- if (is_laptop_ == 1) {
+ if (is_laptop == 1) {
msg_pinfo("You seem to be running flashrom on an unknown laptop. Some\n"
"internal buses have been disabled for safety reasons.\n\n");
} else {
@@ -204,9 +203,9 @@
}
}

- is_laptop = 2; /* Assume that we don't know by default. */
+ g_is_laptop = 2; /* Assume that we don't know by default. */

- dmi_init();
+ dmi_init(&g_is_laptop);

/* In case Super I/O probing would cause pretty explosions. */
board_handle_before_superio(force_boardenable);
@@ -229,7 +228,7 @@
* this isn't a laptop. Board-enables may override this,
* non-legacy buses (SPI and opaque atm) are probed anyway.
*/
- if (is_laptop && !(g_laptop_ok || force_laptop || (not_a_laptop && is_laptop == 2)))
+ if (g_is_laptop && !(g_laptop_ok || force_laptop || (not_a_laptop && g_is_laptop == 2)))
internal_buses_supported = BUS_NONE;

/* try to enable it. Failure IS an option, since not all motherboards
@@ -258,7 +257,7 @@
internal_par_init(internal_buses_supported);

/* Report if a non-whitelisted laptop is detected that likely uses a legacy bus. */
- report_nonwl_laptop_detected(is_laptop, g_laptop_ok);
+ report_nonwl_laptop_detected(g_is_laptop, g_laptop_ok);

ret = 0;


To view, visit change 71622. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3d5ad6c0623269492d775a99a947fd6fe26c5f91
Gerrit-Change-Number: 71622
Gerrit-PatchSet: 7
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Sam McNally <sammc@google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Angel Pons <th3fanbus@gmail.com>
Gerrit-CC: Thomas Heijligen <src@posteo.de>
Gerrit-MessageType: merged