Subject: wd.c patch to reduce kernel stack usage
To: None <bouyer@netbsd.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 06/27/2002 04:16:21
----Next_Part(Thu_Jun_27_04:16:21_2002_507)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

hi.

is attached patch ok?
(in order to reduce kernel stack usage.)

---
YAMAMOTO Takashi<yamt@mwd.biglobe.ne.jp>

----Next_Part(Thu_Jun_27_04:16:21_2002_507)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="wd.diff"

Index: wd.c
===================================================================
RCS file: /cvs/cvsroot/syssrc/sys/dev/ata/wd.c,v
retrieving revision 1.220
diff -u -p -r1.220 wd.c
--- wd.c	2002/01/13 17:24:30	1.220
+++ wd.c	2002/06/26 16:12:40
@@ -130,6 +130,8 @@ extern int wdcdebug_wd_mask; /* init'ed 
 #define WDCDEBUG_PRINT(args, level)
 #endif
 
+#define	WD_MAX_ERROR_LEN	256
+
 struct wd_softc {
 	/* General disk infos */
 	struct device sc_dev;
@@ -589,14 +591,13 @@ wddone(v)
 {
 	struct wd_softc *wd = v;
 	struct buf *bp = wd->sc_bp;
-	char buf[256], *errbuf = buf;
+	char *buf = 0, *errbuf;
 	WDCDEBUG_PRINT(("wddone %s\n", wd->sc_dev.dv_xname),
 	    DEBUG_XFERS);
 
 	if (bp == NULL)
 		return;
 	bp->b_resid = wd->sc_wdc_bio.bcount;
-	errbuf[0] = '\0';
 	switch (wd->sc_wdc_bio.error) {
 	case ERR_DMA:
 		errbuf = "DMA error";
@@ -612,11 +613,19 @@ wddone(v)
 		if (wd->sc_wdc_bio.r_error != 0 &&
 		    (wd->sc_wdc_bio.r_error & ~(WDCE_MC | WDCE_MCR)) == 0)
 			goto noerror;
-		wdperror(wd->drvp, wd->sc_wdc_bio.r_error, errbuf);
+		buf = malloc(WD_MAX_ERROR_LEN, M_DEVBUF, M_NOWAIT);
+		if (buf) {
+			errbuf = buf;
+			wdperror(wd->drvp, wd->sc_wdc_bio.r_error, errbuf);
+		}
+		else
+			errbuf = ""; /* XXX */
 retry:		/* Just reset and retry. Can we do more ? */
 		wd->atabus->ata_reset_channel(wd->drvp);
 		diskerr(bp, "wd", errbuf, LOG_PRINTF,
 		    wd->sc_wdc_bio.blkdone, wd->sc_dk.dk_label);
+		if (buf)
+			free(buf, M_DEVBUF);
 		if (wd->retries++ < WDIORETRIES) {
 			printf(", retrying\n");
 			callout_reset(&wd->sc_restart_ch, RECOVERYTIME,

----Next_Part(Thu_Jun_27_04:16:21_2002_507)----