compress: make variable 'running' as unsigned
PATCH 1/4 compress: make variable 'running' as unsigned
as we never expect this to be negative
Signed-off-by Vinod Koul <[email protected]>
--- compress.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
compress.c +1 -1
@@ -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, ...)
Signature · 1 line
1.7.0.4
PATCH 2/4 compress: remove unused variables
Signed-off-by Vinod Koul <[email protected]>
--- compress.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
compress.c +0 -3
@@ -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);
Signature · 1 line
1.7.0.4
PATCH 3/4 compress: cache the config values passed
In reply to Vinod KoulThe library should not rely on users pointer for config data, so cache it for use afterwards
Signed-off-by Vinod Koul <[email protected]>
--- compress.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-)
compress.c +10 -5
@@ -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))
Signature · 1 line
1.7.0.4
PATCH 4/4 compress: fix arithmetic exception in compress_get_hpointer
In reply to Vinod KoulFrom: Xuemin Su <[email protected]>
In compress_get_hpointer, check for invalid sample rate to prevent devide-by-zero exceptions
Signed-off-by Xuemin Su <[email protected]>
Signed-off-by He Bo <[email protected]>
Signed-off-by Vinod Koul <[email protected]>
--- compress.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
compress.c +2 -0
@@ -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;
Signature · 1 line
1.7.0.4
Vinod Koul
AppliedQuoted 3 lines · Vinod Koul
as we never expect this to be negative
Signed-off-by Vinod Koul <[email protected]>
Applied, all...
Quoted 20 lines
--- compress.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)compress.c +1
-1@@ -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, ...)Signature · 1 line
1.7.0.4