aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2012-04-06 15:32:30 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-05-14 12:07:44 -0400
commit6fb39c50a04aca7a6bb6c5b0a10204fa7fbe749c (patch)
tree1305733f0a61087bab0fc2d5b7af30353ccb20a6
parent4b25524c7b329f6d7a3f6d14b0f036fd6091def2 (diff)
[media] af9035: various small changes for af9035_ctrl_msg()
Fix USB buffer len to maximum possible. Various log writing fixes, remove extra new lines and excessive type casts. Rename and type change some variables. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/dvb/dvb-usb/af9035.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/media/dvb/dvb-usb/af9035.c b/drivers/media/dvb/dvb-usb/af9035.c
index e1d6e6efa77b..a68ae5385790 100644
--- a/drivers/media/dvb/dvb-usb/af9035.c
+++ b/drivers/media/dvb/dvb-usb/af9035.c
@@ -57,17 +57,16 @@ static u16 af9035_checksum(const u8 *buf, size_t len)
57 57
58static int af9035_ctrl_msg(struct usb_device *udev, struct usb_req *req) 58static int af9035_ctrl_msg(struct usb_device *udev, struct usb_req *req)
59{ 59{
60#define BUF_LEN 63 60#define BUF_LEN 64
61#define REQ_HDR_LEN 4 /* send header size */ 61#define REQ_HDR_LEN 4 /* send header size */
62#define ACK_HDR_LEN 3 /* rece header size */ 62#define ACK_HDR_LEN 3 /* rece header size */
63#define CHECKSUM_LEN 2 63#define CHECKSUM_LEN 2
64#define USB_TIMEOUT 2000 64#define USB_TIMEOUT 2000
65 65
66 int ret, act_len; 66 int ret, msg_len, act_len;
67 u8 buf[BUF_LEN]; 67 u8 buf[BUF_LEN];
68 u32 msg_len;
69 static u8 seq; /* packet sequence number */ 68 static u8 seq; /* packet sequence number */
70 u16 checksum, tmpsum; 69 u16 checksum, tmp_checksum;
71 70
72 /* buffer overflow check */ 71 /* buffer overflow check */
73 if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) || 72 if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) ||
@@ -89,14 +88,14 @@ static int af9035_ctrl_msg(struct usb_device *udev, struct usb_req *req)
89 88
90 /* calc and add checksum */ 89 /* calc and add checksum */
91 checksum = af9035_checksum(buf, buf[0] - 1); 90 checksum = af9035_checksum(buf, buf[0] - 1);
92 buf[buf[0]-1] = (checksum >> 8); 91 buf[buf[0] - 1] = (checksum >> 8);
93 buf[buf[0]-0] = (checksum & 0xff); 92 buf[buf[0] - 0] = (checksum & 0xff);
94 93
95 msg_len = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN ; 94 msg_len = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN ;
96 95
97 /* send req */ 96 /* send req */
98 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len, 97 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len,
99 &act_len, USB_TIMEOUT); 98 &act_len, USB_TIMEOUT);
100 if (ret < 0) 99 if (ret < 0)
101 err("bulk message failed=%d (%d/%d)", ret, msg_len, act_len); 100 err("bulk message failed=%d (%d/%d)", ret, msg_len, act_len);
102 else 101 else
@@ -112,29 +111,29 @@ static int af9035_ctrl_msg(struct usb_device *udev, struct usb_req *req)
112 /* receive ack and data if read req */ 111 /* receive ack and data if read req */
113 msg_len = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN; 112 msg_len = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN;
114 ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len, 113 ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,
115 &act_len, USB_TIMEOUT); 114 &act_len, USB_TIMEOUT);
116 if (ret < 0) { 115 if (ret < 0) {
117 err("recv bulk message failed=%d", ret); 116 err("recv bulk message failed=%d", ret);
118 ret = -EIO; 117 ret = -EIO;
119 goto err_mutex_unlock; 118 goto err_mutex_unlock;
120 } 119 }
120
121 if (act_len != msg_len) { 121 if (act_len != msg_len) {
122 err("recv bulk message truncated (%d != %u)\n", 122 err("recv bulk message truncated (%d != %d)", act_len, msg_len);
123 act_len, (unsigned int)msg_len);
124 ret = -EIO; 123 ret = -EIO;
125 goto err_mutex_unlock; 124 goto err_mutex_unlock;
126 } 125 }
127 126
128 /* verify checksum */ 127 /* verify checksum */
129 checksum = af9035_checksum(buf, act_len - 2); 128 checksum = af9035_checksum(buf, act_len - 2);
130 tmpsum = (buf[act_len - 2] << 8) | buf[act_len - 1]; 129 tmp_checksum = (buf[act_len - 2] << 8) | buf[act_len - 1];
131 if (tmpsum != checksum) { 130 if (tmp_checksum != checksum) {
132 err("%s: command=%02X checksum mismatch (%04X != %04X)\n", 131 err("%s: command=%02x checksum mismatch (%04x != %04x)",
133 __func__, req->cmd, 132 __func__, req->cmd, tmp_checksum, checksum);
134 (unsigned int)tmpsum, (unsigned int)checksum);
135 ret = -EIO; 133 ret = -EIO;
136 goto err_mutex_unlock; 134 goto err_mutex_unlock;
137 } 135 }
136
138 /* check status */ 137 /* check status */
139 if (buf[2]) { 138 if (buf[2]) {
140 pr_debug("%s: command=%02x failed fw error=%d\n", __func__, 139 pr_debug("%s: command=%02x failed fw error=%d\n", __func__,
@@ -400,7 +399,7 @@ static int af9035_download_firmware(struct usb_device *udev,
400 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ; 399 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
401 u8 hdr_core; 400 u8 hdr_core;
402 u16 hdr_addr, hdr_data_len, hdr_checksum; 401 u16 hdr_addr, hdr_data_len, hdr_checksum;
403 #define MAX_DATA 57 402 #define MAX_DATA 58
404 #define HDR_SIZE 7 403 #define HDR_SIZE 7
405 404
406 /* 405 /*