diff options
author | Chris Pascoe <c.pascoe@itee.uq.edu.au> | 2007-11-19 07:29:59 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-25 16:02:27 -0500 |
commit | 0a196b6fa9b42a2bb49733b37565aaaa97ffb07f (patch) | |
tree | aa968a19dd739ecd17bf1a4fe7dac8d603c6ec55 /drivers/media/video/tuner-xc2028.c | |
parent | a44f1c43dfa98e2eb763968890157bfaf9001add (diff) |
V4L/DVB (6642): xc2028: don't duplicate max_len in priv
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 'drivers/media/video/tuner-xc2028.c')
-rw-r--r-- | drivers/media/video/tuner-xc2028.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/drivers/media/video/tuner-xc2028.c b/drivers/media/video/tuner-xc2028.c index c921d6009a8b..e19449603d73 100644 --- a/drivers/media/video/tuner-xc2028.c +++ b/drivers/media/video/tuner-xc2028.c | |||
@@ -75,9 +75,6 @@ struct xc2028_data { | |||
75 | 6M, 7M or 8M */ | 75 | 6M, 7M or 8M */ |
76 | int need_load_generic; /* The generic firmware | 76 | int need_load_generic; /* The generic firmware |
77 | were loaded? */ | 77 | were loaded? */ |
78 | |||
79 | int max_len; /* Max firmware chunk */ | ||
80 | |||
81 | enum tuner_mode mode; | 78 | enum tuner_mode mode; |
82 | struct i2c_client *i2c_client; | 79 | struct i2c_client *i2c_client; |
83 | 80 | ||
@@ -426,7 +423,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, | |||
426 | { | 423 | { |
427 | struct xc2028_data *priv = fe->tuner_priv; | 424 | struct xc2028_data *priv = fe->tuner_priv; |
428 | int pos, rc; | 425 | int pos, rc; |
429 | unsigned char *p, *endp, buf[priv->max_len]; | 426 | unsigned char *p, *endp, buf[priv->ctrl.max_len]; |
430 | 427 | ||
431 | tuner_dbg("%s called\n", __FUNCTION__); | 428 | tuner_dbg("%s called\n", __FUNCTION__); |
432 | 429 | ||
@@ -505,8 +502,8 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, | |||
505 | 502 | ||
506 | /* Sends message chunks */ | 503 | /* Sends message chunks */ |
507 | while (size > 0) { | 504 | while (size > 0) { |
508 | int len = (size < priv->max_len - 1) ? | 505 | int len = (size < priv->ctrl.max_len - 1) ? |
509 | size : priv->max_len - 1; | 506 | size : priv->ctrl.max_len - 1; |
510 | 507 | ||
511 | memcpy(buf + 1, p, len); | 508 | memcpy(buf + 1, p, len); |
512 | 509 | ||
@@ -881,32 +878,30 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg) | |||
881 | { | 878 | { |
882 | struct xc2028_data *priv = fe->tuner_priv; | 879 | struct xc2028_data *priv = fe->tuner_priv; |
883 | struct xc2028_ctrl *p = priv_cfg; | 880 | struct xc2028_ctrl *p = priv_cfg; |
881 | int rc = 0; | ||
884 | 882 | ||
885 | tuner_dbg("%s called\n", __FUNCTION__); | 883 | tuner_dbg("%s called\n", __FUNCTION__); |
886 | 884 | ||
887 | mutex_lock(&priv->lock); | 885 | mutex_lock(&priv->lock); |
888 | 886 | ||
889 | priv->ctrl.type = p->type; | 887 | kfree(priv->ctrl.fname); |
890 | 888 | free_firmware(priv); | |
891 | if (p->fname) { | ||
892 | kfree(priv->ctrl.fname); | ||
893 | 889 | ||
894 | priv->ctrl.fname = kmalloc(strlen(p->fname) + 1, GFP_KERNEL); | 890 | memcpy(&priv->ctrl, p, sizeof(priv->ctrl)); |
895 | if (priv->ctrl.fname == NULL) { | 891 | priv->ctrl.fname = NULL; |
896 | mutex_unlock(&priv->lock); | ||
897 | return -ENOMEM; | ||
898 | } | ||
899 | 892 | ||
900 | free_firmware(priv); | 893 | if (p->fname) { |
901 | strcpy(priv->ctrl.fname, p->fname); | 894 | priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL); |
895 | if (priv->ctrl.fname == NULL) | ||
896 | rc = -ENOMEM; | ||
902 | } | 897 | } |
903 | 898 | ||
904 | if (p->max_len > 0) | 899 | if (priv->ctrl.max_len < 9) |
905 | priv->max_len = p->max_len; | 900 | priv->ctrl.max_len = 13; |
906 | 901 | ||
907 | mutex_unlock(&priv->lock); | 902 | mutex_unlock(&priv->lock); |
908 | 903 | ||
909 | return 0; | 904 | return rc; |
910 | } | 905 | } |
911 | 906 | ||
912 | static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = { | 907 | static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = { |
@@ -967,7 +962,7 @@ void *xc2028_attach(struct dvb_frontend *fe, struct xc2028_config *cfg) | |||
967 | priv->i2c_props.adap = cfg->i2c_adap; | 962 | priv->i2c_props.adap = cfg->i2c_adap; |
968 | priv->video_dev = video_dev; | 963 | priv->video_dev = video_dev; |
969 | priv->tuner_callback = cfg->callback; | 964 | priv->tuner_callback = cfg->callback; |
970 | priv->max_len = 13; | 965 | priv->ctrl.max_len = 13; |
971 | 966 | ||
972 | mutex_init(&priv->lock); | 967 | mutex_init(&priv->lock); |
973 | 968 | ||