serial-dmm: style nit (init vs assign, memmove(3))
Move the initial assignment to the 'offset' variable to the very spot where it gets evaluated and subsequently manipulated. Replace a DIY copy loop with the corresponding memmove(3) call.
This commit is contained in:
parent
e4fb1a821d
commit
51e1f5661c
|
@ -116,7 +116,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
|
|||
{
|
||||
struct dmm_info *dmm;
|
||||
struct dev_context *devc;
|
||||
int len, i, offset = 0;
|
||||
int len, offset;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
|
||||
dmm = (struct dmm_info *)sdi->driver;
|
||||
|
@ -136,6 +136,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
|
|||
devc->buflen += len;
|
||||
|
||||
/* Now look for packets in that data. */
|
||||
offset = 0;
|
||||
while ((devc->buflen - offset) >= dmm->packet_size) {
|
||||
if (dmm->packet_valid(devc->buf + offset)) {
|
||||
handle_packet(devc->buf + offset, sdi, info);
|
||||
|
@ -154,8 +155,8 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
|
|||
}
|
||||
|
||||
/* If we have any data left, move it to the beginning of our buffer. */
|
||||
for (i = 0; i < devc->buflen - offset; i++)
|
||||
devc->buf[i] = devc->buf[offset + i];
|
||||
if (devc->buflen > offset)
|
||||
memmove(devc->buf, devc->buf + offset, devc->buflen - offset);
|
||||
devc->buflen -= offset;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue