Skip to content

Commit 0644244

Browse files
teiglandswhiteho
authored andcommitted
[DLM] break from snprintf loop
When the debug buffer has filled up, break from the loop and return the correct number of bytes that have been written. Signed-off-by: David Teigland <teigland@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent f6db1b8 commit 0644244

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎fs/dlm/debug_fs.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,19 @@ static ssize_t waiters_read(struct file *file, char __user *userbuf,
310310
{
311311
struct dlm_ls *ls = file->private_data;
312312
struct dlm_lkb *lkb;
313-
size_t len = DLM_DEBUG_BUF_LEN, pos = 0, rv;
313+
size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv;
314314

315315
mutex_lock(&debug_buf_lock);
316316
mutex_lock(&ls->ls_waiters_mutex);
317317
memset(debug_buf, 0, sizeof(debug_buf));
318318

319319
list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
320-
pos += snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
321-
lkb->lkb_id, lkb->lkb_wait_type,
322-
lkb->lkb_nodeid, lkb->lkb_resource->res_name);
320+
ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
321+
lkb->lkb_id, lkb->lkb_wait_type,
322+
lkb->lkb_nodeid, lkb->lkb_resource->res_name);
323+
if (ret >= len - pos)
324+
break;
325+
pos += ret;
323326
}
324327
mutex_unlock(&ls->ls_waiters_mutex);
325328

0 commit comments

Comments
 (0)