Fix malloc() uses in em_get_regs().
Do not use malloc(M_NOWAIT), wait is possible there, and the malloc failures where not checked. Do not forget to free malloced memory. Reported and tested by: pho Approved by: sbruno Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
6ff9ce94ce
commit
dc63dc00cb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=323312
@ -534,22 +534,26 @@ static int em_get_regs(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
struct adapter *adapter = (struct adapter *)arg1;
|
||||
struct e1000_hw *hw = &adapter->hw;
|
||||
|
||||
struct sbuf *sb;
|
||||
u32 *regs_buff = (u32 *)malloc(sizeof(u32) * IGB_REGS_LEN, M_DEVBUF, M_NOWAIT);
|
||||
u32 *regs_buff;
|
||||
int rc;
|
||||
|
||||
regs_buff = malloc(sizeof(u32) * IGB_REGS_LEN, M_DEVBUF, M_WAITOK);
|
||||
memset(regs_buff, 0, IGB_REGS_LEN * sizeof(u32));
|
||||
|
||||
rc = sysctl_wire_old_buffer(req, 0);
|
||||
MPASS(rc == 0);
|
||||
if (rc != 0)
|
||||
if (rc != 0) {
|
||||
free(regs_buff, M_DEVBUF);
|
||||
return (rc);
|
||||
}
|
||||
|
||||
sb = sbuf_new_for_sysctl(NULL, NULL, 32*400, req);
|
||||
MPASS(sb != NULL);
|
||||
if (sb == NULL)
|
||||
if (sb == NULL) {
|
||||
free(regs_buff, M_DEVBUF);
|
||||
return (ENOMEM);
|
||||
}
|
||||
|
||||
/* General Registers */
|
||||
regs_buff[0] = E1000_READ_REG(hw, E1000_CTRL);
|
||||
@ -605,6 +609,8 @@ static int em_get_regs(SYSCTL_HANDLER_ARGS)
|
||||
sbuf_printf(sb, "\tTDFHS\t %08x\n", regs_buff[20]);
|
||||
sbuf_printf(sb, "\tTDFPC\t %08x\n\n", regs_buff[21]);
|
||||
|
||||
free(regs_buff, M_DEVBUF);
|
||||
|
||||
#ifdef DUMP_DESCS
|
||||
{
|
||||
if_softc_ctx_t scctx = adapter->shared;
|
||||
|
Loading…
Reference in New Issue
Block a user