Messages in this thread | | | From | Bart Van Assche <> | Date | Thu, 25 Aug 2011 19:42:19 +0200 | Subject | Re: [PATCH 3/4] dynamic_debug: use a single printk() to emit msgs |
| |
On Thu, Aug 25, 2011 at 7:34 PM, Jason Baron <jbaron@redhat.com> wrote: > -static int dynamic_emit_prefix(const struct _ddebug *descriptor) > +#define PREFIX_SIZE 64 > +#define LEFT(wrote) ((PREFIX_SIZE - wrote) > 0) ? (PREFIX_SIZE - wrote) : 0 > + > +static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf) > { > - char tid[sizeof(int) + sizeof(int)/2 + 4]; > - char lineno[sizeof(int) + sizeof(int)/2]; > + int pos = 0; > > - if (descriptor->flags & _DPRINTK_FLAGS_INCL_TID) { > + pos += snprintf(buf + pos, LEFT(pos), "%s", KERN_DEBUG); > + if (desc->flags & _DPRINTK_FLAGS_INCL_TID) { > if (in_interrupt()) > - snprintf(tid, sizeof(tid), "%s", "<intr> "); > + pos += snprintf(buf + pos, LEFT(pos), "%s ", > + "<intr>"); > else > - snprintf(tid, sizeof(tid), "[%d] ", > - task_pid_vnr(current)); > - } else { > - tid[0] = 0; > + pos += snprintf(buf + pos, LEFT(pos), "[%d] ", > + task_pid_vnr(current)); > } > + if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME) > + pos += snprintf(buf + pos, LEFT(pos), "%s:", desc->modname); > + if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) > + pos += snprintf(buf + pos, LEFT(pos), "%s:", desc->function); > + if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) > + pos += snprintf(buf + pos, LEFT(pos), "%d ", desc->lineno); > > - if (descriptor->flags & _DPRINTK_FLAGS_INCL_LINENO) > - snprintf(lineno, sizeof(lineno), "%d", descriptor->lineno); > - else > - lineno[0] = 0; > - > - return printk(KERN_DEBUG "%s%s%s%s%s%s", > - tid, > - (descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME) ? > - descriptor->modname : "", > - (descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME) ? > - ":" : "", > - (descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) ? > - descriptor->function : "", > - (descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) ? > - ":" : "", > - lineno); > + return buf; > }
Shouldn't the new implementation guarantee that buf[] is '\0'-terminated if pos >= PREFIX_SIZE ?
Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |