From ab330bc7c7dc42ee9081e1e7c853c99c04feab26 Mon Sep 17 00:00:00 2001 From: Omair Mohammed Abdullah Date: Tue, 8 Nov 2011 16:24:46 +0530 Subject: [PATCH] [REBASED on main (r3branch)from r2-stable branch] audio: sst: Fix for errors revealed by klocwork BZ: 17975 Fixes errors in driver revealed by klocwork and other static analysis tools Change-Id: I661df04fd1fae138a6c21842ff5699bc28d046bf old-Change-Id: Iea1f15842e6c7f39a90a7c038e4d9817131f29a6 Signed-off-by: Omair Mohammed Abdullah Reviewed-on: http://android.intel.com:8080/29537 Reviewed-by: M, Arulselvan Tested-by: M, Arulselvan Reviewed-by: buildbot Tested-by: buildbot --- sound/pci/sst/intel_sst.c | 2 +- sound/pci/sst/intel_sst_app_interface.c | 4 +--- sound/pci/sst/intel_sst_common.h | 4 +--- sound/pci/sst/intel_sst_dsp.c | 7 ++++++- sound/pci/sst/intel_sst_fw_ipc.h | 4 ++-- sound/pci/sst/intel_sst_ipc.c | 6 +++--- sound/pci/sst/intel_sst_stream.c | 5 +++-- sound/pci/sst/intel_sst_stream_encoded.c | 5 ----- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/sound/pci/sst/intel_sst.c b/sound/pci/sst/intel_sst.c index f459be9..3d875e0 100644 --- a/sound/pci/sst/intel_sst.c +++ b/sound/pci/sst/intel_sst.c @@ -604,7 +604,7 @@ static const struct dev_pm_ops intel_sst_pm = { /* PCI Routines */ static struct pci_device_id intel_sst_ids[] = { { PCI_VDEVICE(INTEL, SST_MRST_PCI_ID), 3}, - { PCI_VDEVICE(INTEL, SST_MFLD_PCI_ID), 6}, + { PCI_VDEVICE(INTEL, SST_MFLD_PCI_ID), 5}, { 0, } }; MODULE_DEVICE_TABLE(pci, intel_sst_ids); diff --git a/sound/pci/sst/intel_sst_app_interface.c b/sound/pci/sst/intel_sst_app_interface.c index 3ab69a3..240258e 100644 --- a/sound/pci/sst/intel_sst_app_interface.c +++ b/sound/pci/sst/intel_sst_app_interface.c @@ -979,9 +979,7 @@ static int sst_ioctl_tuning_params(unsigned int cmd, unsigned long arg) if (copy_from_user(¶ms, (void __user *)arg, sizeof(params))) return -EFAULT; - if (params.size > SST_MAILBOX_SIZE) - return -ENOMEM; - pr_debug("Parameter %d, Stream %d, Size %d\n", params.type, + pr_debug("sst: Parameter %d, Stream %d, Size %d\n", params.type, params.str_id, params.size); if (sst_create_large_msg(&msg)) return -ENOMEM; diff --git a/sound/pci/sst/intel_sst_common.h b/sound/pci/sst/intel_sst_common.h index 9459dab..c37ffc1 100644 --- a/sound/pci/sst/intel_sst_common.h +++ b/sound/pci/sst/intel_sst_common.h @@ -382,7 +382,6 @@ struct sst_dma { * @list_spin_lock : sst driver spin lock block * @scard_ops : sst card ops * @pci : sst pci device struture - * @active_streams : sst active streams * @sst_lock : sst device lock * @stream_lock : sst stream lock * @unique_id : sst unique id @@ -429,7 +428,6 @@ struct intel_sst_drv { spinlock_t list_spin_lock; /* mutex for IPC list locking */ struct snd_pmic_ops *scard_ops; struct pci_dev *pci; - int active_streams[MAX_NUM_STREAMS]; void *mmap_mem; struct mutex sst_lock; struct mutex stream_lock; @@ -581,7 +579,7 @@ static inline void sst_fill_header(union ipc_header *header, static inline unsigned int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx) { sst_drv_ctx->unique_id++; - if (sst_drv_ctx->unique_id >= MAX_NUM_STREAMS) + if (sst_drv_ctx->unique_id > MAX_NUM_STREAMS) sst_drv_ctx->unique_id = 1; return sst_drv_ctx->unique_id; } diff --git a/sound/pci/sst/intel_sst_dsp.c b/sound/pci/sst/intel_sst_dsp.c index b0faa11..cae1fce 100644 --- a/sound/pci/sst/intel_sst_dsp.c +++ b/sound/pci/sst/intel_sst_dsp.c @@ -142,7 +142,7 @@ static int sst_start_medfield(void) static int sst_parse_module(struct fw_module_header *module) { struct dma_block_info *block; - struct sst_firmware_list *node; + struct sst_firmware_list *node = NULL; u32 count, offset; unsigned long ram; @@ -229,6 +229,10 @@ static int sst_alloc_dma_chan(struct sst_dma *dma) return -ENODEV; } dma->ch = dma_request_channel(mask, chan_filter, dma); + if (!dma->ch) { + pr_err("unable to request dma channel\n"); + return -EIO; + } slave->dma_slave.direction = DMA_FROM_DEVICE; slave->hs_mode = 0; @@ -241,6 +245,7 @@ static int sst_alloc_dma_chan(struct sst_dma *dma) retval = dmaengine_slave_config(dma->ch, &slave->dma_slave); if (retval) { pr_err("unable to set slave config, err %d\n", retval); + dma_release_channel(dma->ch); return -EIO; } return retval; diff --git a/sound/pci/sst/intel_sst_fw_ipc.h b/sound/pci/sst/intel_sst_fw_ipc.h index e34f14b..97d2330 100644 --- a/sound/pci/sst/intel_sst_fw_ipc.h +++ b/sound/pci/sst/intel_sst_fw_ipc.h @@ -31,8 +31,8 @@ */ #define MAX_NUM_STREAMS_MRST 3 -#define MAX_NUM_STREAMS_MFLD 6 -#define MAX_NUM_STREAMS 6 +#define MAX_NUM_STREAMS_MFLD 5 +#define MAX_NUM_STREAMS 5 #define MAX_DBG_RW_BYTES 80 #define MAX_NUM_SCATTER_BUFFERS 8 #define MAX_LOOP_BACK_DWORDS 8 diff --git a/sound/pci/sst/intel_sst_ipc.c b/sound/pci/sst/intel_sst_ipc.c index f42b385..d5c894b 100644 --- a/sound/pci/sst/intel_sst_ipc.c +++ b/sound/pci/sst/intel_sst_ipc.c @@ -354,7 +354,7 @@ void sst_process_reply(struct work_struct *work) mailbox_params = (struct snd_ppp_params *)msg->mailbox; get_params = kzalloc(sizeof(*get_params), GFP_KERNEL); if (!get_params) { - pr_debug("mem alloc failed\n"); + pr_err("sst: mem alloc failed\n"); break; } memcpy_fromio(get_params, mailbox_params, @@ -362,9 +362,8 @@ void sst_process_reply(struct work_struct *work) get_params->params = kzalloc(mailbox_params->size, GFP_KERNEL); if (!get_params->params) { - pr_debug("mem alloc failed\n"); + pr_err("sst: mem alloc failed\n"); kfree(get_params); - pr_err("out of memory for ALG PARAMS block"); break; } params = msg->mailbox; @@ -706,6 +705,7 @@ void sst_process_reply(struct work_struct *work) } else { pr_err("Msg %x reply error %x\n", msg->header.part.msg_id, msg->header.part.data); + break; } sst_wake_up_alloc_block(sst_drv_ctx, FW_DWNL_ID, retval, NULL); break; diff --git a/sound/pci/sst/intel_sst_stream.c b/sound/pci/sst/intel_sst_stream.c index a8fbc57..780faef 100644 --- a/sound/pci/sst/intel_sst_stream.c +++ b/sound/pci/sst/intel_sst_stream.c @@ -49,8 +49,9 @@ */ static int sst_check_device_type(u32 device, u32 num_chan, u32 *pcm_slot) { - if (device >= MAX_NUM_STREAMS_MFLD) { - pr_debug("device type invalid %d\n", device); + /* device id range starts from 1 */ + if (device > MAX_NUM_STREAMS_MFLD) { + pr_debug("sst: device type invalid %d\n", device); return -EINVAL; } if (sst_drv_ctx->streams[device].status == STREAM_UN_INIT) { diff --git a/sound/pci/sst/intel_sst_stream_encoded.c b/sound/pci/sst/intel_sst_stream_encoded.c index 884a58a..56c8bec 100644 --- a/sound/pci/sst/intel_sst_stream_encoded.c +++ b/sound/pci/sst/intel_sst_stream_encoded.c @@ -435,11 +435,6 @@ int sst_target_device_select(struct snd_sst_target_device *target) pr_debug("Target Device Select\n"); - if (target->device_route < 0 || target->device_route > 2) { - pr_err("device route is invalid\n"); - return -EINVAL; - } - if (target->device_route != 0) { pr_err("Unsupported config\n"); return -EIO; -- 2.7.4