From owner-svn-src-head@freebsd.org Tue Dec 12 20:22:11 2017 Return-Path: Delivered-To: svn-src-head@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 0D8BDE83755; Tue, 12 Dec 2017 20:22:11 +0000 (UTC) (envelope-from imp@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 CEBC470E3B; Tue, 12 Dec 2017 20:22:10 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBCKM9qi050770; Tue, 12 Dec 2017 20:22:09 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBCKM9Kd050769; Tue, 12 Dec 2017 20:22:09 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201712122022.vBCKM9Kd050769@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Tue, 12 Dec 2017 20:22:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326809 - head/sys/dev/cardbus X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/dev/cardbus X-SVN-Commit-Revision: 326809 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Dec 2017 20:22:11 -0000 Author: imp Date: Tue Dec 12 20:22:09 2017 New Revision: 326809 URL: https://svnweb.freebsd.org/changeset/base/326809 Log: 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 Modified: head/sys/dev/cardbus/cardbus_cis.c Modified: head/sys/dev/cardbus/cardbus_cis.c ============================================================================== --- head/sys/dev/cardbus/cardbus_cis.c Tue Dec 12 20:15:57 2017 (r326808) +++ head/sys/dev/cardbus/cardbus_cis.c Tue Dec 12 20:22:09 2017 (r326809) @@ -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); }