aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-06-19 02:13:35 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-06-20 19:41:38 -0400
commit169d1338ed4ed91412761a77095a13b9992993ba (patch)
tree58deb492b59544715bd0fb7c36913d43807244db /drivers
parentd20411588d2f47ded7b0a02ed1005c7e3ce0df40 (diff)
mei: make mei_write_message more readable
1. reduce hairy casting 2. replace open code with mei_count_empty_write_slots 4. include header size in check for overflow 3. use concise for loop instead of a while loop Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/misc/mei/interface.c49
1 files changed, 18 insertions, 31 deletions
diff --git a/drivers/misc/mei/interface.c b/drivers/misc/mei/interface.c
index 428d21e36416..6c0569177646 100644
--- a/drivers/misc/mei/interface.c
+++ b/drivers/misc/mei/interface.c
@@ -127,52 +127,39 @@ int mei_count_empty_write_slots(struct mei_device *dev)
127 * 127 *
128 * This function returns -EIO if write has failed 128 * This function returns -EIO if write has failed
129 */ 129 */
130int mei_write_message(struct mei_device *dev, 130int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header,
131 struct mei_msg_hdr *header, 131 unsigned char *buf, unsigned long length)
132 unsigned char *write_buffer,
133 unsigned long write_length)
134{ 132{
135 u32 temp_msg = 0; 133 unsigned long rem, dw_cnt;
136 unsigned long bytes_written = 0; 134 u32 *reg_buf = (u32 *)buf;
137 unsigned char buffer_depth, filled_slots, empty_slots; 135 int i;
138 unsigned long dw_to_write; 136 int empty_slots;
139
140 dev->host_hw_state = mei_hcsr_read(dev);
141 137
142 dev_dbg(&dev->pdev->dev,
143 "host_hw_state = 0x%08x.\n",
144 dev->host_hw_state);
145 138
146 dev_dbg(&dev->pdev->dev, 139 dev_dbg(&dev->pdev->dev,
147 "mei_write_message header=%08x.\n", 140 "mei_write_message header=%08x.\n",
148 *((u32 *) header)); 141 *((u32 *) header));
149 142
150 buffer_depth = (unsigned char) ((dev->host_hw_state & H_CBD) >> 24); 143 empty_slots = mei_count_empty_write_slots(dev);
151 filled_slots = _host_get_filled_slots(dev); 144 dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots);
152 empty_slots = buffer_depth - filled_slots;
153 dev_dbg(&dev->pdev->dev,
154 "filled = %hu, empty = %hu.\n",
155 filled_slots, empty_slots);
156
157 dw_to_write = ((write_length + 3) / 4);
158 145
159 if (dw_to_write > empty_slots) 146 dw_cnt = (length + sizeof(*header) + 3) / 4;
147 if (empty_slots < 0 || dw_cnt > empty_slots)
160 return -EIO; 148 return -EIO;
161 149
162 mei_reg_write(dev, H_CB_WW, *((u32 *) header)); 150 mei_reg_write(dev, H_CB_WW, *((u32 *) header));
163 151
164 while (write_length >= 4) { 152 for (i = 0; i < length / 4; i++)
165 mei_reg_write(dev, H_CB_WW, 153 mei_reg_write(dev, H_CB_WW, reg_buf[i]);
166 *(u32 *) (write_buffer + bytes_written));
167 bytes_written += 4;
168 write_length -= 4;
169 }
170 154
171 if (write_length > 0) { 155 rem = length & 0x3;
172 memcpy(&temp_msg, &write_buffer[bytes_written], write_length); 156 if (rem > 0) {
173 mei_reg_write(dev, H_CB_WW, temp_msg); 157 u32 reg = 0;
158 memcpy(&reg, &buf[length - rem], rem);
159 mei_reg_write(dev, H_CB_WW, reg);
174 } 160 }
175 161
162 dev->host_hw_state = mei_hcsr_read(dev);
176 dev->host_hw_state |= H_IG; 163 dev->host_hw_state |= H_IG;
177 mei_hcsr_set(dev); 164 mei_hcsr_set(dev);
178 dev->me_hw_state = mei_mecsr_read(dev); 165 dev->me_hw_state = mei_mecsr_read(dev);