Subject: kern/5597: /sys/dev/ic/com.c - zero argument to comintr()
To: None <gnats-bugs@gnats.netbsd.org>
From: Lucio De Re <lucio@proxima.alt.za>
List: netbsd-bugs
Date: 06/16/1998 15:38:56
>Number:         5597
>Category:       kern
>Synopsis:       Failure in com.c to accept a zero argument to comintr()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 16 06:50:00 1998
>Last-Modified:
>Originator:     Lucio De Re
>Organization:
	Proxima Research & Development
>Release:        NetBSD 1.3.2
>Environment:
	
	PC-Clone, NetBSD-1.3.2, i386
System: NetBSD twiddle 1.3 NetBSD 1.3 (MYRTLE) #2: Mon Mar 16 01:59:17 PST 1998 lucio@twiddle:/usr/src/sys/arch/i386/compile/MYRTLE i386


>Description:
	I applied a small patch to the 1.3.2 version of /sys/dev/ic/com.c
	that allows the "sc" argument to comintr() to be zero.  The need
	for this arose in implementing a slightly different multi-port
	handler for the BOCA ioAT-66 6-port card, which allows a clever
	driver to poll only interrupting ports.  Under some conditions,
	this may cause an interupt handler to be installed that has no
	reserved data area, in which case we want the interrupt handler
	to return immediately.

	The original comintr() code attempted to initialise local variables
	from the passed argument, my change postpones the assignment to
	after the argument has been validated.  The minor performance
	degradation will hopefully be insignificant.
>How-To-Repeat:
	---
>Fix:
	The following patch applies the change to the 1.3.2 com.c module:

===================================================================
RCS file: /usr/src/sys/dev/ic/RCS/com.c,v
retrieving revision 1.1
diff -c -r1.1 /var/source/sys/NetBSD/1.3.2/usr/src/sys/dev/ic/com.c
*** /usr/src/sys/dev/ic/com.c	1998/06/16 13:04:12	1.1
--- /usr/src/sys/dev/ic/com.c	1998/06/16 13:05:04
***************
*** 1552,1563 ****
  	void *arg;
  {
  	struct com_softc *sc = arg;
! 	bus_space_tag_t iot = sc->sc_iot;
! 	bus_space_handle_t ioh = sc->sc_ioh;
  	u_char *put, *end;
  	u_int cc;
  	u_char lsr, iir;
  
  	iir = bus_space_read_1(iot, ioh, com_iir);
  	if (ISSET(iir, IIR_NOPEND))
  		return (0);
--- 1552,1567 ----
  	void *arg;
  {
  	struct com_softc *sc = arg;
! 	bus_space_tag_t iot;
! 	bus_space_handle_t ioh;
  	u_char *put, *end;
  	u_int cc;
  	u_char lsr, iir;
  
+ 	if (!sc)
+ 		return(0);
+ 	iot = sc->sc_iot;
+ 	ioh = sc->sc_ioh;
  	iir = bus_space_read_1(iot, ioh, com_iir);
  	if (ISSET(iir, IIR_NOPEND))
  		return (0);
>Audit-Trail:
>Unformatted: