Module Name:    src
Committed By:   mlelstv
Date:           Sun Jul 14 13:55:43 UTC 2019

Modified Files:
        src/sys/external/bsd/dwc2/dist: dwc2_hcd.c

Log Message:
Fix error path, kmem_free doesn't allow NULL pointers.
Fix compilation with CONFIG_USB_DWC2_TRACK_MISSED_SOFS.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/external/bsd/dwc2/dist/dwc2_hcd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/dwc2/dist/dwc2_hcd.c
diff -u src/sys/external/bsd/dwc2/dist/dwc2_hcd.c:1.22 src/sys/external/bsd/dwc2/dist/dwc2_hcd.c:1.23
--- src/sys/external/bsd/dwc2/dist/dwc2_hcd.c:1.22	Mon Aug 27 17:13:07 2018
+++ src/sys/external/bsd/dwc2/dist/dwc2_hcd.c	Sun Jul 14 13:55:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dwc2_hcd.c,v 1.22 2018/08/27 17:13:07 riastradh Exp $	*/
+/*	$NetBSD: dwc2_hcd.c,v 1.23 2019/07/14 13:55:43 mlelstv Exp $	*/
 
 /*
  * hcd.c - DesignWare HS OTG Controller host-mode routines
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dwc2_hcd.c,v 1.22 2018/08/27 17:13:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc2_hcd.c,v 1.23 2019/07/14 13:55:43 mlelstv Exp $");
 
 #include <sys/types.h>
 #include <sys/kmem.h>
@@ -2424,13 +2424,16 @@ int dwc2_hcd_init(struct dwc2_hsotg *hso
 error3:
 	dwc2_hcd_release(hsotg);
 error2:
-	kmem_free(hsotg->core_params, sizeof(*hsotg->core_params));
+	if (hsotg->core_params != NULL)
+		kmem_free(hsotg->core_params, sizeof(*hsotg->core_params));
 
 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
-	kmem_free(hsotg->last_frame_num_array,
-	      sizeof(*hsotg->last_frame_num_array) * FRAME_NUM_ARRAY_SIZE);
-	kmem_free(hsotg->frame_num_array,
-		  sizeof(*hsotg->frame_num_array) * FRAME_NUM_ARRAY_SIZE);
+	if (hsotg->last_frame_num_array != NULL)
+		kmem_free(hsotg->last_frame_num_array,
+		      sizeof(*hsotg->last_frame_num_array) * FRAME_NUM_ARRAY_SIZE);
+	if (hsotg->frame_num_array != NULL)
+		kmem_free(hsotg->frame_num_array,
+			  sizeof(*hsotg->frame_num_array) * FRAME_NUM_ARRAY_SIZE);
 #endif
 
 	dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval);
@@ -2460,7 +2463,7 @@ void dwc2_hcd_remove(struct dwc2_hsotg *
 	dwc2_hcd_release(hsotg);
 
 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
-	kfree(hsotg->last_frame_num_array);
-	kfree(hsotg->frame_num_array);
+	kmem_free(hsotg->last_frame_num_array, sizeof(*hsotg->last_frame_num_array) * FRAME_NUM_ARRAY_SIZE);
+	kmem_free(hsotg->frame_num_array, sizeof(*hsotg->frame_num_array) * FRAME_NUM_ARRAY_SIZE);
 #endif
 }

Reply via email to