summaryrefslogtreecommitdiffstats
path: root/drivers/ntb
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2016-05-27 16:38:31 -0400
committerJon Mason <jdmason@kudzu.us>2016-08-05 10:05:31 -0400
commitc792eba12cd200e67d08e20a22763ff1970a685b (patch)
tree287e02e1f7945fbb24826f002177be36513a2e69 /drivers/ntb
parent523d939ef98fd712632d93a5a2b588e477a7565e (diff)
ntb_tool: Fix infinite loop bug when writing spad/peer_spad file
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>
Diffstat (limited to 'drivers/ntb')
-rw-r--r--drivers/ntb/test/ntb_tool.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
index 6f5dc6ca673d..209ef7ceb98a 100644
--- a/drivers/ntb/test/ntb_tool.c
+++ b/drivers/ntb/test/ntb_tool.c
@@ -268,7 +268,7 @@ static ssize_t tool_spadfn_write(struct tool_ctx *tc,
268{ 268{
269 int spad_idx; 269 int spad_idx;
270 u32 spad_val; 270 u32 spad_val;
271 char *buf; 271 char *buf, *buf_ptr;
272 int pos, n; 272 int pos, n;
273 ssize_t rc; 273 ssize_t rc;
274 274
@@ -288,14 +288,15 @@ static ssize_t tool_spadfn_write(struct tool_ctx *tc,
288 } 288 }
289 289
290 buf[size] = 0; 290 buf[size] = 0;
291 291 buf_ptr = buf;
292 n = sscanf(buf, "%d %i%n", &spad_idx, &spad_val, &pos); 292 n = sscanf(buf_ptr, "%d %i%n", &spad_idx, &spad_val, &pos);
293 while (n == 2) { 293 while (n == 2) {
294 buf_ptr += pos;
294 rc = spad_write_fn(tc->ntb, spad_idx, spad_val); 295 rc = spad_write_fn(tc->ntb, spad_idx, spad_val);
295 if (rc) 296 if (rc)
296 break; 297 break;
297 298
298 n = sscanf(buf + pos, "%d %i%n", &spad_idx, &spad_val, &pos); 299 n = sscanf(buf_ptr, "%d %i%n", &spad_idx, &spad_val, &pos);
299 } 300 }
300 301
301 if (n < 0) 302 if (n < 0)