--- /opt/kernel/linux-2.4.4/drivers/block/pktcdvd.c	Mon Apr 30 16:05:30 2001
+++ linux/drivers/block/pktcdvd.c	Mon Apr 30 15:16:50 2001
@@ -395,6 +395,12 @@
 	unlock_buffer(bh);
 }
 
+static void pkt_end_io_dummy(struct buffer_head *bh, int uptodate)
+{
+	pkt_end_io_read(bh, uptodate);
+}
+
+
 #if 0
 static struct buffer_head *pkt_get_page_hash(unsigned long block)
 {
@@ -514,8 +520,6 @@
 	bh->b_next = NULL;
 	spin_unlock_irq(&pd->lock);
 
-	init_buffer(bh, pkt_end_io_read, pd);
-
 	bh->b_next_free = NULL;
 	bh->b_prev_free = NULL;
 	bh->b_this_page = NULL;
@@ -531,6 +535,7 @@
 
 got_it:
 	blk_started_io(bh->b_size >> 9);
+	bh->b_end_io = pkt_end_io_dummy;
 	bh->b_rsector = sector;
 	bh->b_rdev = pd->dev;
 	return bh;
@@ -605,7 +610,7 @@
 	pd->stats.bh_e++;
 }
 
-static int pkt_init_rq(struct pktcdvd_device *pd, struct request *rq)
+static int pkt_init_rq(struct pktcdvd_device *pd, struct request *rq, int inc)
 {
 	struct buffer_head *bh;
 	unsigned int cnt, nr_segments, print;
@@ -619,10 +624,10 @@
 		struct buffer_head *nbh = bh->b_reqnext;
 
 		bh->b_rdev = pd->pkt_dev;
-		if (bh->b_end_io != pkt_end_io_write) {
+		bh->b_end_io = pkt_end_io_write;
+
+		if (inc)
 			atomic_inc(&bh->b_count);
-			bh->b_end_io = pkt_end_io_write;
-		}
 
 		/*
 		 * the buffer better be uptodate, mapped, and locked!
@@ -791,8 +796,8 @@
 
 		index = (bh->b_rsector & (pd->settings.size - 1)) / secs;
 
-		atomic_inc(&bh->b_count);
 		bhs[index] = bh;
+		atomic_inc(&bh->b_count);
 		bh = bh->b_reqnext;
 
 		/*
@@ -812,8 +817,10 @@
 
 		bh = pkt_get_buffer(pd, sector, CD_FRAMESIZE);
 
-		if (!buffer_uptodate(bh))
+		if (!buffer_uptodate(bh)) {
+			bh->b_end_io = pkt_end_io_read;
 			pkt_read_bh(pd, bh);
+		}
 
 		bhs[index] = bh;
 		rq->nr_sectors += bh->b_size >> 9;
@@ -832,10 +839,8 @@
 		/*
 		 * pin down private buffers (ie, force I/O to complete)
 		 */
-		if (bh->b_list == PKT_BUF_LIST) {
+		if (bh->b_end_io == pkt_end_io_read)
 			lock_buffer(bh);
-			atomic_dec(&bh->b_count);
-		}
 
 		if (!buffer_locked(bh))
 			BUG();
@@ -872,7 +877,7 @@
 	rq->sector = rq->hard_sector = start_s;
 
 	VPRINTK("unlocked last %lu\n", rq->bhtail->b_rsector);
-	if (pkt_init_rq(pd, rq)) {
+	if (pkt_init_rq(pd, rq, 0)) {
 		for (index = 0; index < PACKET_MAX_SIZE; index++) {
 			bh = bhs[index];
 			printk("[%d] %lu %d (%p -> %p)\n", index, bh->b_rsector,
@@ -900,6 +905,7 @@
 kill_it:
 	for (index = 0; index < PACKET_MAX_SIZE; index++) {
 		bh = bhs[index];
+		brelse(bh);
 		buffer_IO_error(bh);
 		if (bh->b_list == PKT_BUF_LIST)
 			pkt_put_buffer(bh);
@@ -921,7 +927,7 @@
 	 * count matches it's good.
 	 */
 	if (rq->nr_sectors == pd->settings.size) {
-		pkt_init_rq(pd, rq);
+		pkt_init_rq(pd, rq, 1);
 		pkt_account_rq(pd, 0, rq->nr_sectors, rq->current_nr_sectors);
 		return 0;
 	}