Aarya has uploaded this change for review.

View Change

tree: Retype variable `is_laptop` to enum

Use enum instead of integer for the variable `is_laptop`.

Change-Id: I47b7611a08bdf9992131cab57ee386fd59d147d3
Signed-off-by: Aarya Chaumal <aarya.chaumal@gmail.com>
---
M board_enable.c
M dmi.c
M include/programmer.h
M internal.c
4 files changed, 38 insertions(+), 36 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/34/83834/1
diff --git a/board_enable.c b/board_enable.c
index 6e48a62..b039413 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -2282,7 +2282,7 @@
static int p2_not_a_laptop(struct board_cfg *cfg)
{
/* label this board as not a laptop */
- cfg->is_laptop = 0;
+ cfg->is_laptop = NO;
msg_pdbg("Laptop detection overridden by P2 board enable.\n");
return 0;
}
@@ -2292,7 +2292,7 @@
*/
static int p2_whitelist_laptop(struct board_cfg *cfg)
{
- cfg->is_laptop = 1;
+ cfg->is_laptop = YES;
cfg->laptop_ok = true;
msg_pdbg("Whitelisted laptop detected.\n");
return 0;
diff --git a/dmi.c b/dmi.c
index 94e47fb..ab64438 100644
--- a/dmi.c
+++ b/dmi.c
@@ -74,24 +74,24 @@
*/
static const struct {
uint8_t type;
- uint8_t is_laptop;
+ enum is_laptop is_laptop;
const char *name;
} dmi_chassis_types[] = {
- {0x01, 2, "Other"},
- {0x02, 2, "Unknown"},
- {0x03, 0, "Desktop"},
- {0x04, 0, "Low Profile Desktop"},
- {0x06, 0, "Mini Tower"},
- {0x07, 0, "Tower"},
- {0x08, 1, "Portable"},
- {0x09, 1, "Laptop"},
- {0x0a, 1, "Notebook"},
- {0x0b, 1, "Hand Held"},
- {0x0e, 1, "Sub Notebook"},
- {0x11, 0, "Main Server Chassis"},
- {0x17, 0, "Rack Mount Chassis"},
- {0x18, 0, "Sealed-case PC"}, /* used by Supermicro (X8SIE) */
- {0x19, 0, "Multi-system"}, /* used by Supermicro (X7DWT) */
+ {0x01, UNKNOWN, "Other"},
+ {0x02, UNKNOWN, "Unknown"},
+ {0x03, NO, "Desktop"},
+ {0x04, NO, "Low Profile Desktop"},
+ {0x06, NO, "Mini Tower"},
+ {0x07, NO, "Tower"},
+ {0x08, YES, "Portable"},
+ {0x09, YES, "Laptop"},
+ {0x0a, YES, "Notebook"},
+ {0x0b, YES, "Hand Held"},
+ {0x0e, YES, "Sub Notebook"},
+ {0x11, NO, "Main Server Chassis"},
+ {0x17, NO, "Rack Mount Chassis"},
+ {0x18, NO, "Sealed-case PC"}, /* used by Supermicro (X8SIE) */
+ {0x19, NO, "Multi-system"}, /* used by Supermicro (X7DWT) */
};

#if CONFIG_INTERNAL_DMI == 1
@@ -151,11 +151,11 @@
return newbuf;
}

-static int dmi_chassis_type(uint8_t code)
+static enum is_laptop dmi_chassis_type(uint8_t code)
{
unsigned int i;
code &= 0x7f; /* bits 6:0 are chassis type, 7th bit is the lock bit */
- int is_laptop = 2;
+ enum is_laptop is_laptop = UNKNOWN;
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);
@@ -166,7 +166,7 @@
return is_laptop;
}

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

@@ -233,7 +233,7 @@
}

#if SM_SUPPORT
-static int smbios_decode(uint8_t *buf, int *is_laptop)
+static int smbios_decode(uint8_t *buf, enum is_laptop *is_laptop)
{
/* TODO: other checks mentioned in the conformance guidelines? */
if (!dmi_checksum(buf, buf[0x05]) ||
@@ -247,7 +247,7 @@
}
#endif

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

-static int dmi_fill(int *is_laptop)
+static int dmi_fill(enum is_laptop *is_laptop)
{
size_t fp;
uint8_t *dmi_mem;
@@ -351,7 +351,7 @@
return result;
}

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

msg_pdbg("DMI string chassis-type: \"%s\"\n", chassis_type);
- *is_laptop = 2;
+ *is_laptop = UNKNOWN;
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;
@@ -392,7 +392,7 @@
return 0;
}

-void dmi_init(int *is_laptop)
+void dmi_init(enum is_laptop *is_laptop)
{
/* Register shutdown function before we allocate anything. */
if (register_shutdown(dmi_shutdown, NULL)) {
@@ -405,12 +405,14 @@
return;

switch (*is_laptop) {
- case 1:
+ case YES:
msg_pdbg("Laptop detected via DMI.\n");
break;
- case 2:
+ case UNKNOWN:
msg_pdbg("DMI chassis-type is not specific enough.\n");
break;
+ default:
+ break;
}

g_has_dmi_support = true;
diff --git a/include/programmer.h b/include/programmer.h
index 3b1ebeb..dd13a9e 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -171,7 +171,7 @@
};

struct board_cfg {
- int is_laptop;
+ enum is_laptop is_laptop;
bool laptop_ok;
};

@@ -257,7 +257,7 @@

/* dmi.c */
#if defined(__i386__) || defined(__x86_64__)
-void dmi_init(int *is_laptop);
+void dmi_init(enum is_laptop *is_laptop);
bool dmi_is_supported(void);
int dmi_match(const char *pattern);
#endif // defined(__i386__) || defined(__x86_64__)
diff --git a/internal.c b/internal.c
index faeb463..647f730 100644
--- a/internal.c
+++ b/internal.c
@@ -107,14 +107,14 @@

static void report_nonwl_laptop_detected(const struct board_cfg *bcfg)
{
- const int is_laptop = bcfg->is_laptop;
+ const enum is_laptop is_laptop = bcfg->is_laptop;
const bool laptop_ok = bcfg->laptop_ok;

- if (!is_laptop || laptop_ok)
+ if ((is_laptop != YES) || laptop_ok)
return;

msg_pinfo("========================================================================\n");
- if (is_laptop == 1) {
+ if (is_laptop == YES) {
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 {
@@ -202,7 +202,7 @@
}
}

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

dmi_init(&bcfg.is_laptop);

@@ -227,7 +227,7 @@
* this isn't a laptop. Board-enables may override this,
* non-legacy buses (SPI and opaque atm) are probed anyway.
*/
- if (bcfg.is_laptop && !(bcfg.laptop_ok || force_laptop || (not_a_laptop && bcfg.is_laptop == 2)))
+ if ((bcfg.is_laptop == YES) && !(bcfg.laptop_ok || force_laptop || (not_a_laptop && bcfg.is_laptop == UNKNOWN)))
internal_buses_supported = BUS_NONE;

/* try to enable it. Failure IS an option, since not all motherboards

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

Gerrit-MessageType: newchange
Gerrit-Project: flashrom
Gerrit-Branch: main
Gerrit-Change-Id: I47b7611a08bdf9992131cab57ee386fd59d147d3
Gerrit-Change-Number: 83834
Gerrit-PatchSet: 1
Gerrit-Owner: Aarya <aarya.chaumal@gmail.com>