1k objects on the stack are a bad idea. While it's likely safe in this

context, it's also safe to allocate the memory and free it instead.

Noticed by: Eugene Grosbein's script
This commit is contained in:
Warner Losh 2017-12-12 20:22:09 +00:00
parent 61b214f338
commit d6f64df912
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=326809

View File

@ -583,7 +583,7 @@ int
cardbus_parse_cis(device_t cbdev, device_t child,
struct tuple_callbacks *callbacks, void *argp)
{
uint8_t tupledata[MAXTUPLESIZE];
uint8_t *tupledata;
int tupleid = CISTPL_NULL;
int len;
int expect_linktarget;
@ -591,10 +591,11 @@ cardbus_parse_cis(device_t cbdev, device_t child,
struct resource *res;
int rid;
bzero(tupledata, MAXTUPLESIZE);
tupledata = malloc(MAXTUPLESIZE, M_DEVBUF, M_WAITOK | M_ZERO);
expect_linktarget = TRUE;
if ((start = pci_read_config(child, PCIR_CIS, 4)) == 0) {
DEVPRINTF((cbdev, "Warning: CIS pointer is 0: (no CIS)\n"));
free(tupledata, M_DEVBUF);
return (0);
}
DEVPRINTF((cbdev, "CIS pointer is %#x\n", start));
@ -602,6 +603,7 @@ cardbus_parse_cis(device_t cbdev, device_t child,
res = cardbus_read_tuple_init(cbdev, child, &start, &rid);
if (res == NULL) {
device_printf(cbdev, "Unable to allocate resources for CIS\n");
free(tupledata, M_DEVBUF);
return (ENXIO);
}
@ -610,6 +612,7 @@ cardbus_parse_cis(device_t cbdev, device_t child,
&tupleid, &len, tupledata) != 0) {
device_printf(cbdev, "Failed to read CIS.\n");
cardbus_read_tuple_finish(cbdev, child, rid, res);
free(tupledata, M_DEVBUF);
return (ENXIO);
}
@ -617,6 +620,7 @@ cardbus_parse_cis(device_t cbdev, device_t child,
device_printf(cbdev, "Expecting link target, got 0x%x\n",
tupleid);
cardbus_read_tuple_finish(cbdev, child, rid, res);
free(tupledata, M_DEVBUF);
return (EINVAL);
}
expect_linktarget = decode_tuple(cbdev, child, tupleid, len,
@ -625,10 +629,12 @@ cardbus_parse_cis(device_t cbdev, device_t child,
device_printf(cbdev, "Parsing failed with %d\n",
expect_linktarget);
cardbus_read_tuple_finish(cbdev, child, rid, res);
free(tupledata, M_DEVBUF);
return (expect_linktarget);
}
} while (tupleid != CISTPL_END);
cardbus_read_tuple_finish(cbdev, child, rid, res);
free(tupledata, M_DEVBUF);
return (0);
}