mirror of https://gitee.com/openkylin/linux.git
staging: bcm2835-audio: use conditional only for error case
* Refactor conditional to check if memory allocation has failed and immediately return (-ENOMEM); if block for success case is removed. * Return the error value -EBUSY when queue_work() fails. Signed-off-by: Aishwarya Pant <aishpant@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
5e00b25853
commit
8f1fff07b0
|
@ -131,77 +131,74 @@ static void my_wq_function(struct work_struct *work)
|
|||
|
||||
int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
LOG_DBG(" .. IN\n");
|
||||
if (alsa_stream->my_wq) {
|
||||
struct bcm2835_audio_work *work;
|
||||
|
||||
work = kmalloc(sizeof(*work), GFP_ATOMIC);
|
||||
/*--- Queue some work (item 1) ---*/
|
||||
if (work) {
|
||||
INIT_WORK(&work->my_work, my_wq_function);
|
||||
work->alsa_stream = alsa_stream;
|
||||
work->cmd = BCM2835_AUDIO_START;
|
||||
if (queue_work(alsa_stream->my_wq, &work->my_work))
|
||||
ret = 0;
|
||||
} else {
|
||||
if (!work) {
|
||||
LOG_ERR(" .. Error: NULL work kmalloc\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
INIT_WORK(&work->my_work, my_wq_function);
|
||||
work->alsa_stream = alsa_stream;
|
||||
work->cmd = BCM2835_AUDIO_START;
|
||||
if (!queue_work(alsa_stream->my_wq, &work->my_work)) {
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
LOG_DBG(" .. OUT %d\n", ret);
|
||||
return ret;
|
||||
LOG_DBG(" .. OUT\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
LOG_DBG(" .. IN\n");
|
||||
if (alsa_stream->my_wq) {
|
||||
struct bcm2835_audio_work *work;
|
||||
|
||||
work = kmalloc(sizeof(*work), GFP_ATOMIC);
|
||||
/*--- Queue some work (item 1) ---*/
|
||||
if (work) {
|
||||
INIT_WORK(&work->my_work, my_wq_function);
|
||||
work->alsa_stream = alsa_stream;
|
||||
work->cmd = BCM2835_AUDIO_STOP;
|
||||
if (queue_work(alsa_stream->my_wq, &work->my_work))
|
||||
ret = 0;
|
||||
} else {
|
||||
if (!work) {
|
||||
LOG_ERR(" .. Error: NULL work kmalloc\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
INIT_WORK(&work->my_work, my_wq_function);
|
||||
work->alsa_stream = alsa_stream;
|
||||
work->cmd = BCM2835_AUDIO_STOP;
|
||||
if (!queue_work(alsa_stream->my_wq, &work->my_work)) {
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
LOG_DBG(" .. OUT %d\n", ret);
|
||||
return ret;
|
||||
LOG_DBG(" .. OUT\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
|
||||
unsigned int count, void *src)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
LOG_DBG(" .. IN\n");
|
||||
if (alsa_stream->my_wq) {
|
||||
struct bcm2835_audio_work *work;
|
||||
|
||||
work = kmalloc(sizeof(*work), GFP_ATOMIC);
|
||||
/*--- Queue some work (item 1) ---*/
|
||||
if (work) {
|
||||
INIT_WORK(&work->my_work, my_wq_function);
|
||||
work->alsa_stream = alsa_stream;
|
||||
work->cmd = BCM2835_AUDIO_WRITE;
|
||||
work->src = src;
|
||||
work->count = count;
|
||||
if (queue_work(alsa_stream->my_wq, &work->my_work))
|
||||
ret = 0;
|
||||
} else {
|
||||
if (!work) {
|
||||
LOG_ERR(" .. Error: NULL work kmalloc\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
INIT_WORK(&work->my_work, my_wq_function);
|
||||
work->alsa_stream = alsa_stream;
|
||||
work->cmd = BCM2835_AUDIO_WRITE;
|
||||
work->src = src;
|
||||
work->count = count;
|
||||
if (!queue_work(alsa_stream->my_wq, &work->my_work)) {
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
LOG_DBG(" .. OUT %d\n", ret);
|
||||
return ret;
|
||||
LOG_DBG(" .. OUT\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void my_workqueue_init(struct bcm2835_alsa_stream *alsa_stream)
|
||||
|
|
Loading…
Reference in New Issue