msm: ba: Fix some potential risks

Avoid memory leaks and prevent to dereference null pointer

Change-Id: I907ea987b0f3d6971116e116841482fa364ef7b8
Signed-off-by: Jingtao Chen <jingtaoc@codeaurora.org>
This commit is contained in:
Jingtao Chen 2017-06-14 15:11:37 +08:00 committed by Gerrit - the friendly Code Review server
parent d87f10c472
commit bb4ea9d9e7
4 changed files with 33 additions and 31 deletions

View file

@ -618,7 +618,7 @@ int msm_ba_save_restore_input(void *instance, enum msm_ba_save_restore_ip sr)
} }
EXPORT_SYMBOL(msm_ba_save_restore_input); EXPORT_SYMBOL(msm_ba_save_restore_input);
void msm_ba_release_subdev_node(struct video_device *vdev) static void msm_ba_release_subdev_node(struct video_device *vdev)
{ {
struct v4l2_subdev *sd = video_get_drvdata(vdev); struct v4l2_subdev *sd = video_get_drvdata(vdev);

View file

@ -509,20 +509,20 @@ static const struct v4l2_ctrl_ops msm_ba_ctrl_ops = {
.s_ctrl = msm_ba_op_s_ctrl, .s_ctrl = msm_ba_op_s_ctrl,
}; };
const struct v4l2_ctrl_ops *msm_ba_get_ctrl_ops(void)
{
return &msm_ba_ctrl_ops;
}
static struct v4l2_ctrl **msm_ba_get_super_cluster(struct msm_ba_inst *inst, static struct v4l2_ctrl **msm_ba_get_super_cluster(struct msm_ba_inst *inst,
int *size) int *size)
{ {
int c = 0; int c = 0;
int sz = 0; int sz = 0;
struct v4l2_ctrl **cluster = kmalloc(sizeof(struct v4l2_ctrl *) * struct v4l2_ctrl **cluster = NULL;
if (!size || !inst)
return NULL;
cluster = kmalloc(sizeof(struct v4l2_ctrl *) *
BA_NUM_CTRLS, GFP_KERNEL); BA_NUM_CTRLS, GFP_KERNEL);
if (!size || !cluster || !inst) if (!cluster)
return NULL; return NULL;
for (c = 0; c < BA_NUM_CTRLS; c++) for (c = 0; c < BA_NUM_CTRLS; c++)
@ -539,10 +539,12 @@ static struct v4l2_ctrl **msm_ba_get_super_cluster(struct msm_ba_inst *inst,
int msm_ba_ctrl_init(struct msm_ba_inst *inst) int msm_ba_ctrl_init(struct msm_ba_inst *inst)
{ {
int idx = 0; int idx = 0;
struct v4l2_ctrl_config ctrl_cfg = {0}; struct v4l2_ctrl_config ctrl_cfg;
int rc = 0; int rc = 0;
int cluster_size = 0; int cluster_size = 0;
memset(&ctrl_cfg, 0x00, sizeof(struct v4l2_ctrl_config));
if (!inst) { if (!inst) {
dprintk(BA_ERR, "%s - invalid instance", __func__); dprintk(BA_ERR, "%s - invalid instance", __func__);
return -EINVAL; return -EINVAL;

View file

@ -37,7 +37,7 @@ struct ba_ctxt *msm_ba_get_ba_context(void)
return gp_ba_ctxt; return gp_ba_ctxt;
} }
void msm_ba_set_ba_context(struct ba_ctxt *ba_ctxt) static void msm_ba_set_ba_context(struct ba_ctxt *ba_ctxt)
{ {
gp_ba_ctxt = ba_ctxt; gp_ba_ctxt = ba_ctxt;
} }
@ -83,7 +83,7 @@ static int msm_ba_v4l2_querycap(struct file *filp, void *fh,
return msm_ba_querycap((void *)ba_inst, cap); return msm_ba_querycap((void *)ba_inst, cap);
} }
int msm_ba_v4l2_enum_input(struct file *file, void *fh, static int msm_ba_v4l2_enum_input(struct file *file, void *fh,
struct v4l2_input *input) struct v4l2_input *input)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -91,7 +91,7 @@ int msm_ba_v4l2_enum_input(struct file *file, void *fh,
return msm_ba_enum_input((void *)ba_inst, input); return msm_ba_enum_input((void *)ba_inst, input);
} }
int msm_ba_v4l2_g_input(struct file *file, void *fh, static int msm_ba_v4l2_g_input(struct file *file, void *fh,
unsigned int *index) unsigned int *index)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -99,7 +99,7 @@ int msm_ba_v4l2_g_input(struct file *file, void *fh,
return msm_ba_g_input((void *)ba_inst, index); return msm_ba_g_input((void *)ba_inst, index);
} }
int msm_ba_v4l2_s_input(struct file *file, void *fh, static int msm_ba_v4l2_s_input(struct file *file, void *fh,
unsigned int index) unsigned int index)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -107,7 +107,7 @@ int msm_ba_v4l2_s_input(struct file *file, void *fh,
return msm_ba_s_input((void *)ba_inst, index); return msm_ba_s_input((void *)ba_inst, index);
} }
int msm_ba_v4l2_enum_output(struct file *file, void *fh, static int msm_ba_v4l2_enum_output(struct file *file, void *fh,
struct v4l2_output *output) struct v4l2_output *output)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -115,7 +115,7 @@ int msm_ba_v4l2_enum_output(struct file *file, void *fh,
return msm_ba_enum_output((void *)ba_inst, output); return msm_ba_enum_output((void *)ba_inst, output);
} }
int msm_ba_v4l2_g_output(struct file *file, void *fh, static int msm_ba_v4l2_g_output(struct file *file, void *fh,
unsigned int *index) unsigned int *index)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -123,7 +123,7 @@ int msm_ba_v4l2_g_output(struct file *file, void *fh,
return msm_ba_g_output((void *)ba_inst, index); return msm_ba_g_output((void *)ba_inst, index);
} }
int msm_ba_v4l2_s_output(struct file *file, void *fh, static int msm_ba_v4l2_s_output(struct file *file, void *fh,
unsigned int index) unsigned int index)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -131,7 +131,7 @@ int msm_ba_v4l2_s_output(struct file *file, void *fh,
return msm_ba_s_output((void *)ba_inst, index); return msm_ba_s_output((void *)ba_inst, index);
} }
int msm_ba_v4l2_enum_fmt(struct file *file, void *fh, static int msm_ba_v4l2_enum_fmt(struct file *file, void *fh,
struct v4l2_fmtdesc *f) struct v4l2_fmtdesc *f)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -139,7 +139,7 @@ int msm_ba_v4l2_enum_fmt(struct file *file, void *fh,
return msm_ba_enum_fmt((void *)ba_inst, f); return msm_ba_enum_fmt((void *)ba_inst, f);
} }
int msm_ba_v4l2_s_fmt(struct file *file, void *fh, static int msm_ba_v4l2_s_fmt(struct file *file, void *fh,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -147,7 +147,7 @@ int msm_ba_v4l2_s_fmt(struct file *file, void *fh,
return msm_ba_s_fmt((void *)ba_inst, f); return msm_ba_s_fmt((void *)ba_inst, f);
} }
int msm_ba_v4l2_g_fmt(struct file *file, void *fh, static int msm_ba_v4l2_g_fmt(struct file *file, void *fh,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -155,7 +155,7 @@ int msm_ba_v4l2_g_fmt(struct file *file, void *fh,
return msm_ba_g_fmt((void *)ba_inst, f); return msm_ba_g_fmt((void *)ba_inst, f);
} }
int msm_ba_v4l2_s_ctrl(struct file *file, void *fh, static int msm_ba_v4l2_s_ctrl(struct file *file, void *fh,
struct v4l2_control *a) struct v4l2_control *a)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -163,7 +163,7 @@ int msm_ba_v4l2_s_ctrl(struct file *file, void *fh,
return msm_ba_s_ctrl((void *)ba_inst, a); return msm_ba_s_ctrl((void *)ba_inst, a);
} }
int msm_ba_v4l2_g_ctrl(struct file *file, void *fh, static int msm_ba_v4l2_g_ctrl(struct file *file, void *fh,
struct v4l2_control *a) struct v4l2_control *a)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -171,7 +171,7 @@ int msm_ba_v4l2_g_ctrl(struct file *file, void *fh,
return msm_ba_g_ctrl((void *)ba_inst, a); return msm_ba_g_ctrl((void *)ba_inst, a);
} }
int msm_ba_v4l2_s_ext_ctrl(struct file *file, void *fh, static int msm_ba_v4l2_s_ext_ctrl(struct file *file, void *fh,
struct v4l2_ext_controls *a) struct v4l2_ext_controls *a)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -179,7 +179,7 @@ int msm_ba_v4l2_s_ext_ctrl(struct file *file, void *fh,
return msm_ba_s_ext_ctrl((void *)ba_inst, a); return msm_ba_s_ext_ctrl((void *)ba_inst, a);
} }
int msm_ba_v4l2_streamon(struct file *file, void *fh, static int msm_ba_v4l2_streamon(struct file *file, void *fh,
enum v4l2_buf_type i) enum v4l2_buf_type i)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -187,7 +187,7 @@ int msm_ba_v4l2_streamon(struct file *file, void *fh,
return msm_ba_streamon((void *)ba_inst, i); return msm_ba_streamon((void *)ba_inst, i);
} }
int msm_ba_v4l2_streamoff(struct file *file, void *fh, static int msm_ba_v4l2_streamoff(struct file *file, void *fh,
enum v4l2_buf_type i) enum v4l2_buf_type i)
{ {
struct msm_ba_inst *ba_inst = get_ba_inst(file, fh); struct msm_ba_inst *ba_inst = get_ba_inst(file, fh);
@ -260,7 +260,7 @@ static unsigned int msm_ba_v4l2_poll(struct file *filp,
return msm_ba_poll((void *)ba_inst, filp, pt); return msm_ba_poll((void *)ba_inst, filp, pt);
} }
void msm_ba_release_video_device(struct video_device *pvdev) static void msm_ba_release_video_device(struct video_device *pvdev)
{ {
} }
@ -369,9 +369,8 @@ static int msm_ba_device_init(struct platform_device *pdev,
if ((ret_dev_ctxt == NULL) || if ((ret_dev_ctxt == NULL) ||
(*ret_dev_ctxt != NULL) || (*ret_dev_ctxt != NULL) ||
(pdev == NULL)) { (pdev == NULL)) {
dprintk(BA_ERR, "%s(%d) Invalid params %p %p %p", dprintk(BA_ERR, "%s(%d) Invalid params",
__func__, __LINE__, __func__, __LINE__);
ret_dev_ctxt, *ret_dev_ctxt, pdev);
return -EINVAL; return -EINVAL;
} }
@ -507,7 +506,7 @@ static int msm_ba_remove(struct platform_device *pdev)
return rc; return rc;
} }
int msm_ba_create(void) static int msm_ba_create(void)
{ {
struct ba_ctxt *ba_ctxt; struct ba_ctxt *ba_ctxt;
int rc = 0; int rc = 0;
@ -539,7 +538,7 @@ int msm_ba_create(void)
return rc; return rc;
} }
int msm_ba_destroy(void) static int msm_ba_destroy(void)
{ {
struct ba_ctxt *ba_ctxt; struct ba_ctxt *ba_ctxt;
int rc = 0; int rc = 0;

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. /* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and * it under the terms of the GNU General Public License version 2 and
@ -68,6 +68,7 @@ int msm_ba_s_ext_ctrl(void *instance, struct v4l2_ext_controls *a);
int msm_ba_g_ctrl(void *instance, struct v4l2_control *a); int msm_ba_g_ctrl(void *instance, struct v4l2_control *a);
int msm_ba_streamon(void *instance, enum v4l2_buf_type i); int msm_ba_streamon(void *instance, enum v4l2_buf_type i);
int msm_ba_streamoff(void *instance, enum v4l2_buf_type i); int msm_ba_streamoff(void *instance, enum v4l2_buf_type i);
long msm_ba_private_ioctl(void *instance, int cmd, void *arg);
int msm_ba_save_restore_input(void *instance, enum msm_ba_save_restore_ip sr); int msm_ba_save_restore_input(void *instance, enum msm_ba_save_restore_ip sr);
int msm_ba_poll(void *instance, struct file *filp, int msm_ba_poll(void *instance, struct file *filp,
struct poll_table_struct *pt); struct poll_table_struct *pt);