Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Feb 2014 11:54:53 +0100
From:      Hans Petter Selasky <hps@bitfrost.no>
To:        Kohji Okuno <okuno.kohji@jp.panasonic.com>
Cc:        jmg@funkthat.com, freebsd-current@freebsd.org
Subject:   Re: kqueue for usb_dev
Message-ID:  <530F197D.6040004@bitfrost.no>
In-Reply-To: <20140227.193914.1745107579233813450.okuno.kohji@jp.panasonic.com>
References:  <530EFEAD.2090502@bitfrost.no> <530F02CA.2030206@bitfrost.no> <20140227.190128.1827840697797583715.okuno.kohji@jp.panasonic.com> <20140227.193914.1745107579233813450.okuno.kohji@jp.panasonic.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------010206010003030103080803
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

On 02/27/14 11:39, Kohji Okuno wrote:
> Hi HPS and John-Mark,
>
> After I changed as the following, the kernel panic does not happen.
> What do you think about this change?
>
> +       knlist_clear(&f->selinfo.si_note, 0);
>          knlist_destroy(&f->selinfo.si_note);
>
> Regards,
>   Kohji Okuno
>

Can you try the attached patch instead?

--HPS


--------------010206010003030103080803
Content-Type: text/x-diff;
 name="usb_dev_knlist.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="usb_dev_knlist.diff"

=== usb_dev.c
==================================================================
--- usb_dev.c	(revision 262555)
+++ usb_dev.c	(local)
@@ -561,8 +561,8 @@
 	return (0);
 }
 
-void
-usb_fifo_free(struct usb_fifo *f)
+static void
+usb_fifo_destroy(struct usb_fifo *f)
 {
 	uint8_t n;
 
@@ -618,7 +618,16 @@
 
 	/* take care of closing the device here, if any */
 	usb_fifo_close(f, 0);
+}
 
+static void
+usb_fifo_free(struct usb_fifo *f)
+{
+	if (f == NULL) {
+		/* be NULL safe */
+		return;
+	}
+
 	cv_destroy(&f->cv_io);
 	cv_destroy(&f->cv_drain);
 
@@ -1867,6 +1876,8 @@
 	f_rx = usb_fifo_alloc(priv_mtx);
 
 	if ((f_tx == NULL) || (f_rx == NULL)) {
+		usb_fifo_destroy(f_tx);
+		usb_fifo_destroy(f_rx);
 		usb_fifo_free(f_tx);
 		usb_fifo_free(f_rx);
 		return (ENOMEM);
@@ -1989,6 +2000,13 @@
 	if (f_sc == NULL) {
 		return;
 	}
+	usb_fifo_destroy(f_sc->fp[USB_FIFO_TX]);
+	usb_fifo_destroy(f_sc->fp[USB_FIFO_RX]);
+
+	usb_destroy_dev(f_sc->dev);
+
+	f_sc->dev = NULL;
+
 	usb_fifo_free(f_sc->fp[USB_FIFO_TX]);
 	usb_fifo_free(f_sc->fp[USB_FIFO_RX]);
 
@@ -1995,10 +2013,6 @@
 	f_sc->fp[USB_FIFO_TX] = NULL;
 	f_sc->fp[USB_FIFO_RX] = NULL;
 
-	usb_destroy_dev(f_sc->dev);
-
-	f_sc->dev = NULL;
-
 	DPRINTFN(2, "detached %p\n", f_sc);
 }
 
=== usbdi.h
==================================================================
--- usbdi.h	(revision 262555)
+++ usbdi.h	(local)
@@ -614,6 +614,5 @@
 void	*usb_fifo_softc(struct usb_fifo *fifo);
 void	usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t);
 void	usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t);
-void	usb_fifo_free(struct usb_fifo *f);
 #endif /* _KERNEL */
 #endif /* _USB_USBDI_H_ */

--------------010206010003030103080803--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?530F197D.6040004>