DragonFly BSD
DragonFly submit List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: small ndis fix


From: Andrew Atrens <atrens@xxxxxxxxxxxxxxxxxx>
Date: Wed, 17 Nov 2004 13:44:25 -0500

Joerg Sonnenberger wrote:
> Even better, the checks are always true, because malloc with M_WAITOK
> can't return NULL :)

Okay :) ...



--- kern_ndis.c.old	2004-11-17 13:37:47.000000000 -0500
+++ kern_ndis.c	2004-11-17 13:41:53.000000000 -0500
@@ -258,10 +258,6 @@
 
 	for (i = 0; i < ndis_jobs; i++) {
 		r = malloc(sizeof(struct ndis_req), M_DEVBUF, M_WAITOK);
-		if (r == NULL) {
-			error = ENOMEM;
-			break;
-		}
 		STAILQ_INSERT_HEAD(&ndis_free, r, link);
 	}
 
@@ -370,8 +366,6 @@
 
 	for (i = 0; i < cnt; i++) {
 		r = malloc(sizeof(struct ndis_req), M_DEVBUF, M_WAITOK);
-		if (r == NULL)
-			return(ENOMEM);
 		lwkt_gettoken(&tokref, &ndis_thr_token);
 		STAILQ_INSERT_HEAD(&ndis_free, r, link);
 		ndis_jobs++;
@@ -852,9 +846,6 @@
 	    (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1)),
 	    M_DEVBUF, M_WAITOK|M_NULLOK|M_ZERO);
 
-	if (rl == NULL)
-		return(ENOMEM);
-
 	rl->cprl_version = 5;
 	rl->cprl_version = 1;
 	rl->cprl_count = sc->ndis_rescnt;
@@ -880,10 +871,6 @@
 		SLIST_FOREACH(brle, brl, link) {
 			n = malloc(sizeof(struct resource_list_entry),
 			    M_TEMP, M_WAITOK|M_NULLOK);
-			if (n == NULL) {
-				error = ENOMEM;
-				goto bad;
-			}
 			bcopy((char *)brle, (char *)n,
 			    sizeof(struct resource_list_entry));
 			SLIST_INSERT_HEAD(&brl_rev, n, link);
@@ -928,8 +915,6 @@
 
 	block->nmb_rlist = rl;
 
-bad:
-
 	while (!SLIST_EMPTY(&brl_rev)) {
 		n = SLIST_FIRST(&brl_rev);
 		SLIST_REMOVE_HEAD(&brl_rev, link);
@@ -1083,8 +1068,6 @@
 	ndis_get_info(arg, OID_GEN_SUPPORTED_LIST, NULL, &len);
 
 	o = malloc(len, M_DEVBUF, M_WAITOK);
-	if (o == NULL)
-		return(ENOMEM);
 
 	rval = ndis_get_info(arg, OID_GEN_SUPPORTED_LIST, o, &len);
 
@@ -1241,9 +1224,6 @@
 	sc->ndis_tmaps = malloc(sizeof(bus_dmamap_t) * sc->ndis_maxpkts,
 	    M_DEVBUF, M_WAITOK|M_ZERO);
 
-	if (sc->ndis_tmaps == NULL)
-		return(ENOMEM);
-
 	for (i = 0; i < sc->ndis_maxpkts; i++) {
 		error = bus_dmamap_create(sc->ndis_ttag, 0,
 		    &sc->ndis_tmaps[i]);
--- subr_ndis.c.old	2004-11-17 08:50:54.000000000 -0500
+++ subr_ndis.c	2004-11-17 13:37:32.000000000 -0500
@@ -322,9 +322,6 @@
 
 	if (*unicode == NULL)
 		*unicode = malloc(strlen(ascii) * 2, M_DEVBUF, M_WAITOK);
-
-	if (*unicode == NULL)
-		return(ENOMEM);
 	ustr = *unicode;
 	for (i = 0; i < strlen(ascii); i++) {
 		*ustr = (uint16_t)ascii[i];
@@ -345,8 +342,6 @@
 
 	if (*ascii == NULL)
 		*ascii = malloc((ulen / 2) + 1, M_DEVBUF, M_WAITOK|M_ZERO);
-	if (*ascii == NULL)
-		return(ENOMEM);
 	astr = *ascii;
 	for (i = 0; i < ulen / 2; i++) {
 		*astr = (uint8_t)unicode[i];
@@ -1560,12 +1555,6 @@
 	*pool = malloc(sizeof(ndis_packet) *
 	    ((descnum + NDIS_POOL_EXTRA) + 1),
 	    M_DEVBUF, M_WAITOK|M_ZERO);
-
-	if (pool == NULL) {
-		*status = NDIS_STATUS_RESOURCES;
-		return;
-	}
-
 	cur = (ndis_packet *)*pool;
 	cur->np_private.npp_flags = 0x1; /* mark the head of the list */
 	cur->np_private.npp_totlen = 0; /* init deletetion flag */
@@ -1783,12 +1772,6 @@
 	*pool = malloc(sizeof(ndis_buffer) *
 	    ((descnum + NDIS_POOL_EXTRA) + 1),
 	    M_DEVBUF, M_WAITOK|M_ZERO);
-
-	if (pool == NULL) {
-		*status = NDIS_STATUS_RESOURCES;
-		return;
-	}
-
 	cur = (ndis_buffer *)*pool;
 	cur->nb_flags = 0x1; /* mark the head of the list */
 	cur->nb_bytecount = 0; /* init usage count */
@@ -2066,8 +2049,6 @@
 	if (dstr == NULL || sstr == NULL)
 		return(NDIS_STATUS_FAILURE);
 	str = malloc(sstr->nas_len + 1, M_DEVBUF, M_WAITOK);
-	if (str == NULL)
-		return(NDIS_STATUS_FAILURE);
 	strncpy(str, sstr->nas_buf, sstr->nas_len);
 	*(str + sstr->nas_len) = '\0';
 	if (ndis_ascii_to_unicode(str, &dstr->nus_buf)) {
@@ -2557,10 +2538,6 @@
 	free(afilename, M_DEVBUF);
 
 	fh = malloc(sizeof(ndis_fh), M_TEMP, M_WAITOK);
-	if (fh == NULL) {
-		*status = NDIS_STATUS_RESOURCES;
-		return;
-	}
 
 	NDINIT2(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_SYSSPACE, path, 
 		td, proc0.p_ucred);
@@ -2617,11 +2594,6 @@
 
 	fh->nf_map = malloc(fh->nf_maplen, M_DEVBUF, M_WAITOK);
 
-	if (fh->nf_map == NULL) {
-		*status = NDIS_STATUS_RESOURCES;
-		return;
-	}
-
 	error = vn_rdwr(UIO_READ, fh->nf_vp, fh->nf_map, fh->nf_maplen, 0,
 	    UIO_SYSSPACE, 0, proc0.p_ucred, &resid, td);
 
--- subr_ntoskrnl.c.old	2004-11-17 13:39:13.000000000 -0500
+++ subr_ntoskrnl.c	2004-11-17 13:39:39.000000000 -0500
@@ -1466,8 +1466,6 @@
 	nt_objref		*nr;
 
 	nr = malloc(sizeof(nt_objref), M_DEVBUF, M_WAITOK|M_ZERO);
-	if (nr == NULL)
-		return(NDIS_STATUS_FAILURE);
 
 	INIT_LIST_HEAD((&nr->no_dh.dh_waitlisthead));
 	nr->no_obj = handle;
@@ -1538,8 +1536,6 @@
 	thread_t		td;
 
 	tc = malloc(sizeof(thread_context), M_TEMP, M_WAITOK);
-	if (tc == NULL)
-		return(NDIS_STATUS_FAILURE);
 
 	tc->tc_thrctx = thrctx;
 	tc->tc_thrfunc = thrfunc;


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]