mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Eliminate magic numbers indicating maximum column sizes in print.c
Without this the magic numbers need to be kept in sync with the maximum length of the strings printed in the corresponding column. if not, an overflow and a nasty ' '-storm occur on executing flashrom -L. Corresponding to flashrom svn r1318. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
parent
c0aaf95487
commit
7bcacb1bdb
28
flashrom.c
28
flashrom.c
@ -1709,9 +1709,37 @@ int selfcheck(void)
|
|||||||
msg_gerr("Programmer table miscompilation!\n");
|
msg_gerr("Programmer table miscompilation!\n");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
/* It would be favorable if we could also check for correct terminaion
|
||||||
|
* of the follwing arrays, but we don't know their size in here...
|
||||||
|
* For 'flashchips' we check the first element to be non-null. In the
|
||||||
|
* other cases there exist use cases where the first element can be
|
||||||
|
* null. */
|
||||||
|
if (flashchips == NULL || flashchips[0].vendor == NULL) {
|
||||||
|
msg_gerr("Flashchips table miscompilation!\n");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
for (flash = flashchips; flash && flash->name; flash++)
|
for (flash = flashchips; flash && flash->name; flash++)
|
||||||
if (selfcheck_eraseblocks(flash))
|
if (selfcheck_eraseblocks(flash))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
|
#if CONFIG_INTERNAL == 1
|
||||||
|
if (chipset_enables == NULL) {
|
||||||
|
msg_gerr("Chipset enables table does not exist!\n");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
if (board_pciid_enables == NULL) {
|
||||||
|
msg_gerr("Board enables table does not exist!\n");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
if (boards_known == NULL) {
|
||||||
|
msg_gerr("Known boards table does not exist!\n");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
if (laptops_known == NULL) {
|
||||||
|
msg_gerr("Known laptops table does not exist!\n");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
#endif // CONFIG_INTERNAL == 1
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
102
print.c
102
print.c
@ -77,7 +77,8 @@ static int digits(int n)
|
|||||||
static void print_supported_chips(void)
|
static void print_supported_chips(void)
|
||||||
{
|
{
|
||||||
int okcol = 0, pos = 0, i, chipcount = 0;
|
int okcol = 0, pos = 0, i, chipcount = 0;
|
||||||
int maxchiplen = 0, maxvendorlen = 0;
|
int maxvendorlen = strlen("Vendor") + 1;
|
||||||
|
int maxchiplen = strlen("Device") + 1;
|
||||||
const struct flashchip *f;
|
const struct flashchip *f;
|
||||||
|
|
||||||
for (f = flashchips; f->name != NULL; f++) {
|
for (f = flashchips; f->name != NULL; f++) {
|
||||||
@ -92,7 +93,7 @@ static void print_supported_chips(void)
|
|||||||
maxchiplen++;
|
maxchiplen++;
|
||||||
okcol = maxvendorlen + maxchiplen;
|
okcol = maxvendorlen + maxchiplen;
|
||||||
|
|
||||||
printf("\nSupported flash chips (total: %d):\n\n", chipcount);
|
printf("Supported flash chips (total: %d):\n\n", chipcount);
|
||||||
printf("Vendor");
|
printf("Vendor");
|
||||||
for (i = strlen("Vendor"); i < maxvendorlen; i++)
|
for (i = strlen("Vendor"); i < maxvendorlen; i++)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
@ -158,63 +159,94 @@ static void print_supported_chips(void)
|
|||||||
#if CONFIG_INTERNAL == 1
|
#if CONFIG_INTERNAL == 1
|
||||||
static void print_supported_chipsets(void)
|
static void print_supported_chipsets(void)
|
||||||
{
|
{
|
||||||
int i, j, chipsetcount = 0;
|
int i, chipsetcount = 0;
|
||||||
const struct penable *c = chipset_enables;
|
const struct penable *c = chipset_enables;
|
||||||
|
int maxvendorlen = strlen("Vendor") + 1;
|
||||||
|
int maxchipsetlen = strlen("Chipset") + 1;
|
||||||
|
|
||||||
for (i = 0; c[i].vendor_name != NULL; i++)
|
for (c = chipset_enables; c->vendor_name != NULL; c++) {
|
||||||
chipsetcount++;
|
chipsetcount++;
|
||||||
|
maxvendorlen = max(maxvendorlen, strlen(c->vendor_name));
|
||||||
|
maxchipsetlen = max(maxchipsetlen, strlen(c->device_name));
|
||||||
|
}
|
||||||
|
maxvendorlen++;
|
||||||
|
maxchipsetlen++;
|
||||||
|
|
||||||
printf("\nSupported chipsets (total: %d):\n\nVendor: "
|
printf("Supported chipsets (total: %d):\n\n", chipsetcount);
|
||||||
"Chipset: PCI IDs:\n\n", chipsetcount);
|
|
||||||
|
|
||||||
for (i = 0; c[i].vendor_name != NULL; i++) {
|
printf("Vendor");
|
||||||
printf("%s", c[i].vendor_name);
|
for (i = strlen("Vendor"); i < maxvendorlen; i++)
|
||||||
for (j = 0; j < 25 - strlen(c[i].vendor_name); j++)
|
printf(" ");
|
||||||
|
|
||||||
|
printf("Chipset");
|
||||||
|
for (i = strlen("Chipset"); i < maxchipsetlen; i++)
|
||||||
|
printf(" ");
|
||||||
|
|
||||||
|
printf("PCI IDs State\n\n");
|
||||||
|
|
||||||
|
for (c = chipset_enables; c->vendor_name != NULL; c++) {
|
||||||
|
printf("%s", c->vendor_name);
|
||||||
|
for (i = 0; i < maxvendorlen - strlen(c->vendor_name); i++)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
printf("%s", c[i].device_name);
|
printf("%s", c->device_name);
|
||||||
for (j = 0; j < 25 - strlen(c[i].device_name); j++)
|
for (i = 0; i < maxchipsetlen - strlen(c->device_name); i++)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
printf("%04x:%04x%s\n", c[i].vendor_id, c[i].device_id,
|
printf("%04x:%04x%s\n", c->vendor_id, c->device_id,
|
||||||
(c[i].status == OK) ? "" : " (untested)");
|
(c->status == OK) ? "" : " (untested)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_supported_boards_helper(const struct board_info *boards,
|
static void print_supported_boards_helper(const struct board_info *boards,
|
||||||
const char *devicetype)
|
const char *devicetype)
|
||||||
{
|
{
|
||||||
int i, j, boardcount_good = 0, boardcount_bad = 0;
|
int i, boardcount_good = 0, boardcount_bad = 0;
|
||||||
const struct board_pciid_enable *b = board_pciid_enables;
|
const struct board_pciid_enable *e = board_pciid_enables;
|
||||||
|
const struct board_info *b = boards;
|
||||||
|
int maxvendorlen = strlen("Vendor") + 1;
|
||||||
|
int maxboardlen = strlen("Board") + 1;
|
||||||
|
|
||||||
for (i = 0; boards[i].vendor != NULL; i++) {
|
for (b = boards; b->vendor != NULL; b++) {
|
||||||
if (boards[i].working)
|
maxvendorlen = max(maxvendorlen, strlen(b->vendor));
|
||||||
|
maxboardlen = max(maxboardlen, strlen(b->name));
|
||||||
|
if (b->working)
|
||||||
boardcount_good++;
|
boardcount_good++;
|
||||||
else
|
else
|
||||||
boardcount_bad++;
|
boardcount_bad++;
|
||||||
}
|
}
|
||||||
|
maxvendorlen++;
|
||||||
|
maxboardlen++;
|
||||||
|
|
||||||
printf("\nKnown %s (good: %d, bad: %d):"
|
printf("Known %s (good: %d, bad: %d):\n\n",
|
||||||
"\n\nVendor: Board: "
|
devicetype, boardcount_good, boardcount_bad);
|
||||||
"Status: Required option:"
|
|
||||||
"\n\n", devicetype, boardcount_good, boardcount_bad);
|
|
||||||
|
|
||||||
for (i = 0; boards[i].vendor != NULL; i++) {
|
printf("Vendor");
|
||||||
printf("%s", boards[i].vendor);
|
for (i = strlen("Vendor"); i < maxvendorlen; i++)
|
||||||
for (j = 0; j < 25 - strlen(boards[i].vendor); j++)
|
printf(" ");
|
||||||
|
|
||||||
|
printf("Board");
|
||||||
|
for (i = strlen("Board"); i < maxboardlen; i++)
|
||||||
|
printf(" ");
|
||||||
|
|
||||||
|
printf("Status Required option\n\n");
|
||||||
|
|
||||||
|
for (b = boards; b->vendor != NULL; b++) {
|
||||||
|
printf("%s", b->vendor);
|
||||||
|
for (i = 0; i < maxvendorlen - strlen(b->vendor); i++)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
printf("%s", boards[i].name);
|
printf("%s", b->name);
|
||||||
for (j = 0; j < 28 - strlen(boards[i].name); j++)
|
for (i = 0; i < maxboardlen - strlen(b->name); i++)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
printf((boards[i].working) ? "OK " : "BAD ");
|
printf((b->working) ? "OK " : "BAD ");
|
||||||
|
|
||||||
for (j = 0; b[j].vendor_name != NULL; j++) {
|
for (e = board_pciid_enables; e->vendor_name != NULL; e++) {
|
||||||
if (strcmp(b[j].vendor_name, boards[i].vendor)
|
if (strcmp(e->vendor_name, b->vendor)
|
||||||
|| strcmp(b[j].board_name, boards[i].name))
|
|| strcmp(e->board_name, b->name))
|
||||||
continue;
|
continue;
|
||||||
if (b[j].lb_vendor == NULL)
|
if (e->lb_vendor == NULL)
|
||||||
printf("(autodetected)");
|
printf("(autodetected)");
|
||||||
else
|
else
|
||||||
printf("-m %s:%s", b[j].lb_vendor,
|
printf("-m %s:%s", e->lb_vendor,
|
||||||
b[j].lb_part);
|
e->lb_part);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
@ -228,10 +260,12 @@ void print_supported(void)
|
|||||||
printf("\nSupported programmers:\n");
|
printf("\nSupported programmers:\n");
|
||||||
list_programmers_linebreak(0, 80, 0);
|
list_programmers_linebreak(0, 80, 0);
|
||||||
#if CONFIG_INTERNAL == 1
|
#if CONFIG_INTERNAL == 1
|
||||||
printf("\nSupported devices for the %s programmer:\n",
|
printf("\nSupported devices for the %s programmer:\n\n",
|
||||||
programmer_table[PROGRAMMER_INTERNAL].name);
|
programmer_table[PROGRAMMER_INTERNAL].name);
|
||||||
print_supported_chipsets();
|
print_supported_chipsets();
|
||||||
|
printf("\n");
|
||||||
print_supported_boards_helper(boards_known, "boards");
|
print_supported_boards_helper(boards_known, "boards");
|
||||||
|
printf("\n");
|
||||||
print_supported_boards_helper(laptops_known, "laptops");
|
print_supported_boards_helper(laptops_known, "laptops");
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_DUMMY == 1
|
#if CONFIG_DUMMY == 1
|
||||||
|
@ -145,7 +145,7 @@ struct bitbang_spi_master {
|
|||||||
struct penable {
|
struct penable {
|
||||||
uint16_t vendor_id;
|
uint16_t vendor_id;
|
||||||
uint16_t device_id;
|
uint16_t device_id;
|
||||||
int status;
|
int status; /* OK=0 and NT=1 are defines only. Beware! */
|
||||||
const char *vendor_name;
|
const char *vendor_name;
|
||||||
const char *device_name;
|
const char *device_name;
|
||||||
int (*doit) (struct pci_dev *dev, const char *name);
|
int (*doit) (struct pci_dev *dev, const char *name);
|
||||||
@ -174,10 +174,10 @@ struct board_pciid_enable {
|
|||||||
uint16_t second_card_vendor;
|
uint16_t second_card_vendor;
|
||||||
uint16_t second_card_device;
|
uint16_t second_card_device;
|
||||||
|
|
||||||
/* Pattern to match DMI entries */
|
/* Pattern to match DMI entries. May be NULL. */
|
||||||
const char *dmi_pattern;
|
const char *dmi_pattern;
|
||||||
|
|
||||||
/* The vendor / part name from the coreboot table. */
|
/* The vendor / part name from the coreboot table. May be NULL. */
|
||||||
const char *lb_vendor;
|
const char *lb_vendor;
|
||||||
const char *lb_part;
|
const char *lb_part;
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ struct board_pciid_enable {
|
|||||||
|
|
||||||
int max_rom_decode_parallel;
|
int max_rom_decode_parallel;
|
||||||
int status;
|
int status;
|
||||||
int (*enable) (void);
|
int (*enable) (void); /* May be NULL. */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct board_pciid_enable board_pciid_enables[];
|
extern const struct board_pciid_enable board_pciid_enables[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user