diff options
author | Chris Pascoe <c.pascoe@itee.uq.edu.au> | 2007-11-19 22:29:59 +1000 |
---|---|---|
committer | Chris Pascoe <c.pascoe@itee.uq.edu.au> | 2007-11-19 22:29:59 +1000 |
commit | 9f4f9e69cfa1eb86ebac72b9d472ed4dafcba7c9 (patch) | |
tree | dd3e00e9d7155be835e9b4aa288a2e6f88077883 /linux/drivers/media/video/tuner-xc2028.c | |
parent | c80e4db976cc9af44f7029e9c55b878bda8d88fa (diff) | |
download | mediapointer-dvb-s2-9f4f9e69cfa1eb86ebac72b9d472ed4dafcba7c9.tar.gz mediapointer-dvb-s2-9f4f9e69cfa1eb86ebac72b9d472ed4dafcba7c9.tar.bz2 |
xc2028: don't duplicate max_len in priv
From: Chris Pascoe <c.pascoe@itee.uq.edu.au>
There is no need to duplicate the max_len field from the ctrl structure
in the private data. If we use it directly from priv->ctrl, we can memcpy
the structure (apart from strings) to reduce maintenance as it grows.
Enforce a minimum max_len length of 8 data bytes (+ 1 address byte) as seems
to be required by the tuner.
Also, use kstrdup instead of open coding the string duplication.
Signed-off-by: Chris Pascoe <c.pascoe@itee.uq.edu.au>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'linux/drivers/media/video/tuner-xc2028.c')
-rw-r--r-- | linux/drivers/media/video/tuner-xc2028.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/linux/drivers/media/video/tuner-xc2028.c b/linux/drivers/media/video/tuner-xc2028.c index 8105d1975..1017b1d10 100644 --- a/linux/drivers/media/video/tuner-xc2028.c +++ b/linux/drivers/media/video/tuner-xc2028.c @@ -86,9 +86,6 @@ struct xc2028_data { 6M, 7M or 8M */ int need_load_generic; /* The generic firmware were loaded? */ - - int max_len; /* Max firmware chunk */ - enum tuner_mode mode; struct i2c_client *i2c_client; @@ -441,7 +438,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, { struct xc2028_data *priv = fe->tuner_priv; int pos, rc; - unsigned char *p, *endp, buf[priv->max_len]; + unsigned char *p, *endp, buf[priv->ctrl.max_len]; tuner_dbg("%s called\n", __FUNCTION__); @@ -520,8 +517,8 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, /* Sends message chunks */ while (size > 0) { - int len = (size < priv->max_len - 1) ? - size : priv->max_len - 1; + int len = (size < priv->ctrl.max_len - 1) ? + size : priv->ctrl.max_len - 1; memcpy(buf + 1, p, len); @@ -898,32 +895,30 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg) { struct xc2028_data *priv = fe->tuner_priv; struct xc2028_ctrl *p = priv_cfg; + int rc = 0; tuner_dbg("%s called\n", __FUNCTION__); mutex_lock(&priv->lock); - priv->ctrl.type = p->type; - - if (p->fname) { - kfree(priv->ctrl.fname); + kfree(priv->ctrl.fname); + free_firmware(priv); - priv->ctrl.fname = kmalloc(strlen(p->fname) + 1, GFP_KERNEL); - if (priv->ctrl.fname == NULL) { - mutex_unlock(&priv->lock); - return -ENOMEM; - } + memcpy(&priv->ctrl, p, sizeof(priv->ctrl)); + priv->ctrl.fname = NULL; - free_firmware(priv); - strcpy(priv->ctrl.fname, p->fname); + if (p->fname) { + priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL); + if (priv->ctrl.fname == NULL) + rc = -ENOMEM; } - if (p->max_len > 0) - priv->max_len = p->max_len; + if (priv->ctrl.max_len < 9) + priv->ctrl.max_len = 13; mutex_unlock(&priv->lock); - return 0; + return rc; } static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = { @@ -989,7 +984,7 @@ void *xc2028_attach(struct dvb_frontend *fe, struct xc2028_config *cfg) priv->i2c_props.adap = cfg->i2c_adap; priv->video_dev = video_dev; priv->tuner_callback = cfg->callback; - priv->max_len = 13; + priv->ctrl.max_len = 13; mutex_init(&priv->lock); |