Allow a NULL pointer as argument to usb_get_next_event(), and don't

allocate a "struct usb_event" on stack in usb_add_event().
This gives just enough breathing space that the box doesn't die
immediately from stack overflow when I insert a
ohci0 at cardbus0 dev 0 function 0: Acer Labs M5237 USB 1.1 Host Controller
This commit is contained in:
drochner 2005-09-09 12:04:30 +00:00
parent aada101c5e
commit fd6c232a7a
1 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb.c,v 1.82 2005/06/21 14:01:12 ws Exp $ */
/* $NetBSD: usb.c,v 1.83 2005/09/09 12:04:30 drochner Exp $ */
/*
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.82 2005/06/21 14:01:12 ws Exp $");
__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.83 2005/09/09 12:04:30 drochner Exp $");
#include "ohci.h"
#include "uhci.h"
@ -703,7 +703,8 @@ usb_get_next_event(struct usb_event *ue)
return (0);
}
#endif
*ue = ueq->ue;
if (ue)
*ue = ueq->ue;
SIMPLEQ_REMOVE_HEAD(&usb_events, next);
free(ueq, M_USBDEV);
usb_nevents--;
@ -734,7 +735,6 @@ Static void
usb_add_event(int type, struct usb_event *uep)
{
struct usb_event_q *ueq;
struct usb_event ue;
struct timeval thetime;
int s;
@ -749,7 +749,7 @@ usb_add_event(int type, struct usb_event *uep)
if (++usb_nevents >= USB_MAX_EVENTS) {
/* Too many queued events, drop an old one. */
DPRINTFN(-1,("usb: event dropped\n"));
(void)usb_get_next_event(&ue);
(void)usb_get_next_event(0);
}
SIMPLEQ_INSERT_TAIL(&usb_events, ueq, next);
wakeup(&usb_events);