From owner-p4-projects@FreeBSD.ORG Tue Feb 10 18:27:35 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E1EA01065673; Tue, 10 Feb 2009 18:27:34 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9FE351065670 for ; Tue, 10 Feb 2009 18:27:34 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 8D6818FC14 for ; Tue, 10 Feb 2009 18:27:34 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n1AIRY91045306 for ; Tue, 10 Feb 2009 18:27:34 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n1AIRYmo045304 for perforce@freebsd.org; Tue, 10 Feb 2009 18:27:34 GMT (envelope-from hselasky@FreeBSD.org) Date: Tue, 10 Feb 2009 18:27:34 GMT Message-Id: <200902101827.n1AIRYmo045304@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 157501 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Feb 2009 18:27:36 -0000 http://perforce.freebsd.org/chv.cgi?CH=157501 Change 157501 by hselasky@hselasky_laptop001 on 2009/02/10 18:26:52 USB CORE: Make sure that USB process functions simply return if the process has been drained. Remove two unused functions. Affected files ... .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.c#19 edit .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.h#10 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.c#19 (text+ko) ==== @@ -84,9 +84,9 @@ while (1) { - if (up->up_gone) { + if (up->up_gone) break; - } + /* * NOTE to reimplementors: dequeueing a command from the * "used" queue and executing it must be atomic, with regard @@ -213,10 +213,10 @@ void usb2_proc_free(struct usb2_process *up) { - if (!(up->up_mtx)) { - /* not initialised */ + /* check if not initialised */ + if (up->up_mtx == NULL) return; - } + usb2_proc_drain(up); usb2_cv_destroy(&up->up_cv); @@ -246,6 +246,10 @@ uint32_t d; uint8_t t; + /* check if gone, return dummy value */ + if (up->up_gone) + return (_pm0); + mtx_assert(up->up_mtx, MA_OWNED); t = 0; @@ -319,9 +323,11 @@ uint8_t usb2_proc_is_gone(struct usb2_process *up) { + if (up->up_gone) + return (1); + mtx_assert(up->up_mtx, MA_OWNED); - - return (up->up_gone ? 1 : 0); + return (0); } /*------------------------------------------------------------------------* @@ -337,6 +343,10 @@ struct usb2_proc_msg *pm0 = _pm0; struct usb2_proc_msg *pm1 = _pm1; + /* check if gone */ + if (up->up_gone) + return; + mtx_assert(up->up_mtx, MA_OWNED); if (up->up_curtd == curthread) { @@ -372,13 +382,13 @@ void usb2_proc_drain(struct usb2_process *up) { - if (!(up->up_mtx)) { - /* not initialised */ + /* check if not initialised */ + if (up->up_mtx == NULL) return; - } - if (up->up_mtx != &Giant) { + /* handle special case with Giant */ + if (up->up_mtx != &Giant) mtx_assert(up->up_mtx, MA_NOTOWNED); - } + mtx_lock(up->up_mtx); /* Set the gone flag */ @@ -398,7 +408,8 @@ if (cold) { USB_THREAD_SUSPEND(up->up_ptr); - printf("WARNING: A USB process has been left suspended!\n"); + printf("WARNING: A USB process has " + "been left suspended!\n"); break; } usb2_cv_wait(&up->up_cv, up->up_mtx); @@ -413,64 +424,3 @@ } mtx_unlock(up->up_mtx); } - -/*------------------------------------------------------------------------* - * usb2_proc_cwait - * - * This function will suspend the current process until - * "usb2_proc_signal()" or "usb2_proc_drain()" is called. The - * "timeout" parameter defines the maximum wait time in system - * ticks. If "timeout" is zero that means no timeout. - * - * NOTE: This function can only be called from within an USB process. - * - * Return values: - * USB_PROC_WAIT_TIMEOUT: Timeout - * USB_PROC_WAIT_NORMAL: Success - * Else: USB process is tearing down - *------------------------------------------------------------------------*/ -uint8_t -usb2_proc_cwait(struct usb2_process *up, int timeout) -{ - int error; - - mtx_assert(up->up_mtx, MA_OWNED); - - if (up->up_gone) { - return (USB_PROC_WAIT_DRAIN); - } - up->up_csleep = 1; - - if (timeout == 0) { - usb2_cv_wait(&up->up_cv, up->up_mtx); - error = 0; - } else { - error = usb2_cv_timedwait(&up->up_cv, up->up_mtx, timeout); - } - - up->up_csleep = 0; - - if (up->up_gone) { - return (USB_PROC_WAIT_DRAIN); - } - if (error == EWOULDBLOCK) { - return (USB_PROC_WAIT_TIMEOUT); - } - return (0); -} - -/*------------------------------------------------------------------------* - * usb2_proc_csignal - * - * This function will wakeup the given USB process. - *------------------------------------------------------------------------*/ -void -usb2_proc_csignal(struct usb2_process *up) -{ - mtx_assert(up->up_mtx, MA_OWNED); - - if (up->up_csleep) { - up->up_csleep = 0; - usb2_cv_signal(&up->up_cv); - } -} ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.h#10 (text+ko) ==== @@ -77,11 +77,9 @@ /* prototypes */ -uint8_t usb2_proc_cwait(struct usb2_process *up, int timeout); uint8_t usb2_proc_is_gone(struct usb2_process *up); int usb2_proc_create(struct usb2_process *up, struct mtx *p_mtx, const char *pmesg, uint8_t prio); -void usb2_proc_csignal(struct usb2_process *up); void usb2_proc_drain(struct usb2_process *up); void usb2_proc_mwait(struct usb2_process *up, void *pm0, void *pm1); void usb2_proc_free(struct usb2_process *up);