alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Vinod Koul <vinod.koul@intel.com>
To: alsa-devel@alsa-project.org
Cc: Vinod Koul <vinod.koul@intel.com>
Subject: [PATCH 3/4] compress: cache the config values passed
Date: Mon, 18 Feb 2013 19:45:14 +0530	[thread overview]
Message-ID: <1361196915-12121-3-git-send-email-vinod.koul@intel.com> (raw)
In-Reply-To: <1361196915-12121-1-git-send-email-vinod.koul@intel.com>

The library should not rely on users pointer for config data, so cache it for
use afterwards

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
---
 compress.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/compress.c b/compress.c
index d98517d..b035e4a 100644
--- a/compress.c
+++ b/compress.c
@@ -211,25 +211,28 @@ struct compress *compress_open(unsigned int card, unsigned int device,
 		return &bad_compress;
 	}
 
-	compress->config = config;
+	compress->config = calloc(1, sizeof(*config));
+	if (!compress->config)
+		goto input_fail;
+	memcpy(compress->config, config, sizeof(*compress->config));
 
 	snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
 
 	compress->flags = flags;
 	if (!((flags & COMPRESS_OUT) || (flags & COMPRESS_IN))) {
 		oops(&bad_compress, -EINVAL, "can't deduce device direction from given flags");
-		goto input_fail;
+		goto config_fail;
 	}
 	if (flags & COMPRESS_OUT) {
 		/* this should be removed once we have capture tested */
 		oops(&bad_compress, -EINVAL, "this version doesnt support capture");
-		goto input_fail;
+		goto config_fail;
 	}
 
 	compress->fd = open(fn, O_WRONLY);
 	if (compress->fd < 0) {
 		oops(&bad_compress, errno, "cannot open device '%s'", fn);
-		goto input_fail;
+		goto config_fail;
 	}
 #if 0
 	/* FIXME need to turn this On when DSP supports
@@ -252,6 +255,8 @@ struct compress *compress_open(unsigned int card, unsigned int device,
 codec_fail:
 	close(compress->fd);
 	compress->fd = -1;
+config_fail:
+	free(compress->config);
 input_fail:
 	free(compress);
 	return &bad_compress;
@@ -266,6 +271,7 @@ void compress_close(struct compress *compress)
 		close(compress->fd);
 	compress->running = 0;
 	compress->fd = -1;
+	free(compress->config);
 	free(compress);
 }
 
@@ -301,7 +307,6 @@ int compress_write(struct compress *compress, char *buf, unsigned int size)
 	fds.fd = compress->fd;
 	fds.events = POLLOUT;
 
-
 	/*TODO: treat auto start here first */
 	while (size) {
 		if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
-- 
1.7.0.4

  parent reply	other threads:[~2013-02-18 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-18 14:15 [PATCH 1/4] compress: make variable 'running' as unsigned Vinod Koul
2013-02-18 14:15 ` [PATCH 2/4] compress: remove unused variables Vinod Koul
2013-02-18 14:15 ` Vinod Koul [this message]
2013-02-18 14:15 ` [PATCH 4/4] compress: fix arithmetic exception in compress_get_hpointer Vinod Koul
2013-02-21 10:21 ` [PATCH 1/4] compress: make variable 'running' as unsigned Vinod Koul

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=1361196915-12121-3-git-send-email-vinod.koul@intel.com \
    --to=vinod.koul@intel.com \
    --cc=alsa-devel@alsa-project.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).