* [PATCH 2/4] compress: remove unused variables
2013-02-18 14:15 [PATCH 1/4] compress: make variable 'running' as unsigned Vinod Koul
@ 2013-02-18 14:15 ` Vinod Koul
2013-02-18 14:15 ` [PATCH 3/4] compress: cache the config values passed Vinod Koul
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2013-02-18 14:15 UTC (permalink / raw)
To: alsa-devel; +Cc: Vinod Koul
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
---
compress.c | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)
diff --git a/compress.c b/compress.c
index a8964f4..d98517d 100644
--- a/compress.c
+++ b/compress.c
@@ -204,7 +204,6 @@ struct compress *compress_open(unsigned int card, unsigned int device,
struct compress *compress;
struct snd_compr_params params;
char fn[256];
- int rc;
compress = calloc(1, sizeof(struct compress));
if (!compress || !config) {
@@ -397,12 +396,10 @@ int compress_drain(struct compress *compress)
bool is_codec_supported(unsigned int card, unsigned int device,
unsigned int flags, struct snd_codec *codec)
{
- struct snd_compr_params params;
unsigned int dev_flag;
bool ret;
int fd;
char fn[256];
- int rc;
snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] compress: cache the config values passed
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
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
3 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2013-02-18 14:15 UTC (permalink / raw)
To: alsa-devel; +Cc: Vinod Koul
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] compress: fix arithmetic exception in compress_get_hpointer
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 ` [PATCH 3/4] compress: cache the config values passed Vinod Koul
@ 2013-02-18 14:15 ` Vinod Koul
2013-02-21 10:21 ` [PATCH 1/4] compress: make variable 'running' as unsigned Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2013-02-18 14:15 UTC (permalink / raw)
To: alsa-devel; +Cc: Vinod Koul, Xuemin Su, He Bo
From: Xuemin Su <xuemin.su@intel.com>
In compress_get_hpointer, check for invalid sample
rate to prevent devide-by-zero exceptions
Signed-off-by: Xuemin Su <xuemin.su@intel.com>
Signed-off-by: He Bo <bo.he@intel.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
---
compress.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/compress.c b/compress.c
index b035e4a..27c03d9 100644
--- a/compress.c
+++ b/compress.c
@@ -286,6 +286,8 @@ int compress_get_hpointer(struct compress *compress,
if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &kavail))
return oops(compress, errno, "cannot get avail");
+ if (0 == kavail.tstamp.sampling_rate)
+ return oops(compress, errno, "invalid paramter");
*avail = (unsigned int)kavail.avail;
time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
tstamp->tv_sec = time;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/4] compress: make variable 'running' as unsigned
2013-02-18 14:15 [PATCH 1/4] compress: make variable 'running' as unsigned Vinod Koul
` (2 preceding siblings ...)
2013-02-18 14:15 ` [PATCH 4/4] compress: fix arithmetic exception in compress_get_hpointer Vinod Koul
@ 2013-02-21 10:21 ` Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2013-02-21 10:21 UTC (permalink / raw)
To: alsa-devel
On Mon, Feb 18, 2013 at 07:45:12PM +0530, Vinod Koul wrote:
> as we never expect this to be negative
>
> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Applied, all...
> ---
> compress.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/compress.c b/compress.c
> index 19d618a..a8964f4 100644
> --- a/compress.c
> +++ b/compress.c
> @@ -83,7 +83,7 @@ struct compress {
> __u64 buffer_size;
> char error[COMPR_ERR_MAX];
> struct compr_config *config;
> - int running:1;
> + unsigned int running:1;
> };
>
> static int oops(struct compress *compress, int e, const char *fmt, ...)
> --
> 1.7.0.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread