From owner-svn-src-all@freebsd.org Fri Sep 8 14:54:08 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B89F2E1C294; Fri, 8 Sep 2017 14:54:08 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 87FFD82425; Fri, 8 Sep 2017 14:54:08 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v88Es739081210; Fri, 8 Sep 2017 14:54:07 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v88Es77u081209; Fri, 8 Sep 2017 14:54:07 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709081454.v88Es77u081209@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 8 Sep 2017 14:54:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323312 - head/sys/dev/e1000 X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/dev/e1000 X-SVN-Commit-Revision: 323312 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Sep 2017 14:54:08 -0000 Author: kib Date: Fri Sep 8 14:54:07 2017 New Revision: 323312 URL: https://svnweb.freebsd.org/changeset/base/323312 Log: 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 Modified: head/sys/dev/e1000/if_em.c Modified: head/sys/dev/e1000/if_em.c ============================================================================== --- head/sys/dev/e1000/if_em.c Fri Sep 8 14:35:17 2017 (r323311) +++ head/sys/dev/e1000/if_em.c Fri Sep 8 14:54:07 2017 (r323312) @@ -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); @@ -604,6 +608,8 @@ static int em_get_regs(SYSCTL_HANDLER_ARGS) sbuf_printf(sb, "\tTDFT\t %08x\n", regs_buff[19]); 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 {