Edward O'Callaghan has uploaded this change for review.

View Change

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>
---
M board_enable.c
M dmi.c
M include/programmer.h
M internal.c
4 files changed, 43 insertions(+), 30 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/22/71622/1
diff --git a/board_enable.c b/board_enable.c
index bf26173..a1428ef 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;
laptop_ok = true;
msg_pdbg("Whitelisted laptop detected.\n");
return 0;
diff --git a/dmi.c b/dmi.c
index beeb10f..31c048d 100644
--- a/dmi.c
+++ b/dmi.c
@@ -151,21 +151,21 @@
return newbuf;
}

-static void dmi_chassis_type(uint8_t code)
+static void dmi_chassis_type(uint8_t code, int *is_laptop)
{
unsigned int i;
code &= 0x7f; /* bits 6:0 are chassis type, 7th bit is the lock bit */
- is_laptop = 2;
+ *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);
- is_laptop = dmi_chassis_types[i].is_laptop;
+ *is_laptop = dmi_chassis_types[i].is_laptop;
break;
}
}
}

-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 +198,7 @@

if(data[0] == 3) {
if (data + 5 < limit)
- dmi_chassis_type(data[5]);
+ dmi_chassis_type(data[5], is_laptop);
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 +232,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 +240,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 +274,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 +350,7 @@
return result;
}

-static int dmi_fill(void)
+static int dmi_fill(int *is_laptop)
{
unsigned int i;
char *chassis_type;
@@ -367,10 +367,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 +391,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)) {
@@ -400,10 +400,10 @@
}

/* dmi_fill fills the dmi_strings array, and if possible sets the global is_laptop variable. */
- if (dmi_fill() != 0)
+ 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 bdb7711..df321aa 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -243,7 +243,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__)
@@ -262,7 +262,7 @@
#endif

#if CONFIG_INTERNAL == 1
-extern int is_laptop;
+extern int g_is_laptop;
extern bool laptop_ok;
extern bool force_boardenable;
extern bool force_boardmismatch;
diff --git a/internal.c b/internal.c
index bf41508..4e1ee96 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 laptop_ok = false;

bool force_boardenable = false;
@@ -185,20 +185,20 @@
}

#if defined(__i386__) || defined(__x86_64__)
- is_laptop = 2; /* Assume that we don't know by default. */
- dmi_init();
+ g_is_laptop = 2; /* Assume that we don't know by default. */
+ dmi_init(&g_is_laptop);
#endif

return 0;
}

// FIXME: remove '_' suffix 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_)
{
/* Report if a non-whitelisted laptop is detected that likely uses a legacy bus. */
- 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 {
@@ -287,7 +287,7 @@
* this isn't a laptop. Board-enables may override this,
* non-legacy buses (SPI and opaque atm) are probed anyway.
*/
- if (is_laptop && !(laptop_ok || force_laptop || (not_a_laptop && is_laptop == 2)))
+ if (g_is_laptop && !(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
@@ -316,7 +316,7 @@
if (internal_buses_supported & BUS_NONSPI)
register_par_master(&par_master_internal, internal_buses_supported, NULL);

- report_nonwl_laptop_detected(is_laptop, laptop_ok);
+ report_nonwl_laptop_detected(g_is_laptop, 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: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange