Skip to content

Commit

Permalink
ntb_tool: Fix infinite loop bug when writing spad/peer_spad file
Browse files Browse the repository at this point in the history
If you tried to write two spads in one line, as per the example:

root@peer# echo '0 0x01010101 1 0x7f7f7f7f' > $DBG_DIR/peer_spad

then the CPU would freeze in an infinite loop.

This wasn't immediately obvious but 'pos' was not incrementing the
buffer, so after reading the second pair of values, 'pos' would once
again be 3 and it would re-read the second pair of values ad infinitum.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Acked-by: Allen Hubbe <Allen.Hubbe@emc.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>
  • Loading branch information
lsgunth authored and jonmason committed Jun 26, 2016
1 parent 33688ab commit bfc43eb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/ntb/test/ntb_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static ssize_t tool_spadfn_write(struct tool_ctx *tc,
{
int spad_idx;
u32 spad_val;
char *buf;
char *buf, *buf_ptr;
int pos, n;
ssize_t rc;

Expand All @@ -288,14 +288,15 @@ static ssize_t tool_spadfn_write(struct tool_ctx *tc,
}

buf[size] = 0;

n = sscanf(buf, "%d %i%n", &spad_idx, &spad_val, &pos);
buf_ptr = buf;
n = sscanf(buf_ptr, "%d %i%n", &spad_idx, &spad_val, &pos);
while (n == 2) {
buf_ptr += pos;
rc = spad_write_fn(tc->ntb, spad_idx, spad_val);
if (rc)
break;

n = sscanf(buf + pos, "%d %i%n", &spad_idx, &spad_val, &pos);
n = sscanf(buf_ptr, "%d %i%n", &spad_idx, &spad_val, &pos);
}

if (n < 0)
Expand Down

0 comments on commit bfc43eb

Please sign in to comment.