All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stuart Brady <sdbrady@ntlworld.com>
To: parisc-linux@lists.parisc-linux.org
Subject: [parisc-linux] [PATCH] Harmony - buffer underrun crash fix
Date: Tue, 25 May 2004 21:43:02 +0100	[thread overview]
Message-ID: <20040525204302.GA975@calypso> (raw)
In-Reply-To: <20040524081200.3d14256b.varenet@esiee.fr>

On Mon, May 24, 2004 at 08:12:00AM +0200, Thibaut VARENE wrote:

> There's been a suspected buffer overflow in the code for years, and it's
> a known "feature" that the driver may randomly panic the kernel. Patch
> welcome.

Thanks.  I had assumed that this was black magic and I'd never be able
to fix it, but thanks to your encouragement, I've taken a look and I now
have a fix for the crash, as well as a sample skipping problem that I
was previously unaware of:

Index: harmony.c
===================================================================
RCS file: /var/cvs/linux-2.4/drivers/sound/harmony.c,v
retrieving revision 1.28
diff -u -r1.28 harmony.c
--- harmony.c	22 Jun 2002 09:05:59 -0000	1.28
+++ harmony.c	25 May 2004 19:15:21 -0000
@@ -537,6 +537,7 @@
 	int count = 0;
 	int frame_size;
 	int buf_to_fill;
+	int fresh_buffer;
 
 	if (!harmony.format_initialized) 
 	   harmony_format_auto_detect(buffer, total_count);
@@ -556,12 +557,16 @@
 		
 		
 		buf_to_fill = (harmony.first_filled_play+harmony.nb_filled_play); 
-		if (harmony.play_offset)
+		if (harmony.play_offset) {
 			buf_to_fill--;
+			buf_to_fill += MAX_BUFS;
+		}
 		buf_to_fill %= MAX_BUFS;
-
+		
+		fresh_buffer = (harmony.play_offset == 0);
+		
 		/* Figure out the size of the frame */
-		if ((total_count-count) > HARMONY_BUF_SIZE - harmony.play_offset) {
+		if ((total_count-count) >= HARMONY_BUF_SIZE - harmony.play_offset) {
 			frame_size = HARMONY_BUF_SIZE - harmony.play_offset;
 		} else {
 			frame_size = total_count - count;
@@ -578,7 +583,7 @@
 		CHECK_WBACK_INV_OFFSET(played_buf, (HARMONY_BUF_SIZE*buf_to_fill + harmony.play_offset), 
 				frame_size);
 	
-		if (!harmony.play_offset)
+		if (fresh_buffer)
 			harmony.nb_filled_play++;
 		
 		count += frame_size;

Lines 560-563 fix the crash, which was caused by buf_to_fill taking the
value -1 (since -1 % MAX_BUFS == -1).

Lines 540, 566, 586/587 should fix a bug where samples were skipped.

The change to line 569 prevents harmony_silence from being called
whenever the final frame that is to be copied completely fills a buffer.

I'm a bit of a newbie here... can a harmony_interrupt occur whilst we're
in harmony_audio_write?
-- 
Stuart Brady
_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

  parent reply	other threads:[~2004-05-25 20:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-22  9:20 [parisc-linux] [PATCH] Harmony driver - Reject AFMT_S16_LE (Little Endian) Stuart Brady
2004-02-22 10:30 ` Stuart Brady
2004-02-22 16:25 ` [parisc-linux] ad1889 driver/docs for c3k/j5k audio Grant Grundler
2004-05-29  0:06   ` [parisc-linux] " Stuart Brady
2004-05-29  0:25     ` Randolph Chung
2004-02-23  3:56 ` [parisc-linux] [PATCH] Harmony driver - Reject AFMT_S16_LE & Implement SNDCTL_DSP_CHANNELS Stuart Brady
2004-05-11  5:24   ` Grant Grundler
2004-05-11 13:07     ` Matthew Wilcox
2004-05-11 14:39       ` [parisc-linux] [PATCH] Harmony driver - Reject AFMT_S16_LE &Implement SNDCTL_DSP_CHANNELS Paul
2004-05-23 23:42     ` [parisc-linux] [PATCH] Harmony driver - Reject AFMT_S16_LE & Implement SNDCTL_DSP_CHANNELS Stuart Brady
2004-05-24 17:30       ` Ruediger Scholz
     [not found]       ` <20040524081200.3d14256b.varenet@esiee.fr>
2004-05-25 20:43         ` Stuart Brady [this message]
     [not found] <20040526075502.F0E503658F9@mail.esiee.fr>
2004-05-26 18:40 ` [parisc-linux] [PATCH] Harmony - buffer underrun crash fix Thibaut VARENE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040525204302.GA975@calypso \
    --to=sdbrady@ntlworld.com \
    --cc=parisc-linux@lists.parisc-linux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.