All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
To: vinod.koul@intel.com
Cc: alsa-devel@alsa-project.org
Subject: [PATCH TINYCOMPRESS 13/14] compress: Prevent divide-by-zero faults	in get_hpointer()
Date: Sun, 10 Feb 2013 00:22:16 +0000	[thread overview]
Message-ID: <20130210002216.GM31139@opensource.wolfsonmicro.com> (raw)

Do not assume that the returned snd_compr_avail contains a
snd_compr_tstamp with a valid sampling_rate. Check for zero
before attempting to use it.

diff --git a/compress.c b/compress.c
index cfd0219..c0e81a3 100644
--- a/compress.c
+++ b/compress.c
@@ -297,10 +297,15 @@ int compress_get_hpointer(struct compress *compress,
 	if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &kavail))
 		return oops(compress, errno, "cannot get avail");
 	*avail = (unsigned int)kavail.avail;
-	time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
-	tstamp->tv_sec = time;
-	time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate;
-	tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate;
+	if (kavail.tstamp.sampling_rate != 0) {
+		time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
+		tstamp->tv_sec = time;
+		time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate;
+		tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate;
+	} else {
+		tstamp->tv_sec = 0;
+		tstamp->tv_nsec = 0;
+	}
 	return 0;
 }
 
-- 
1.7.2.5

             reply	other threads:[~2013-02-10  0:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-10  0:22 Richard Fitzgerald [this message]
2013-02-22 16:09 ` [PATCH TINYCOMPRESS 13/14] compress: Prevent divide-by-zero faults in get_hpointer() Richard Fitzgerald

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=20130210002216.GM31139@opensource.wolfsonmicro.com \
    --to=rf@opensource.wolfsonmicro.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=vinod.koul@intel.com \
    /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.