lkml.org 
[lkml]   [2008]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [RFC] Recursive printk
    At Fri, 5 Dec 2008 23:41:05 -0800,
    Andrew Morton wrote:
    >
    > On Sat, 6 Dec 2008 08:33:05 +0100 Willy Tarreau <w@1wt.eu> wrote:
    >
    > > On Fri, Dec 05, 2008 at 11:20:16PM -0800, Andrew Morton wrote:
    > > > > void snd_verbose_printk(const char *file, int line, const char *format, ...)
    > > > > {
    > > > > va_list args;
    > > > >
    > > > > if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
    > > > > char tmp[] = "<0>";
    > > > > tmp[1] = format[1];
    > > > > printk("%sALSA %s:%d: ", tmp, file, line);
    > > > > format += 3;
    > > >
    > > > That's racy. Two threads can fight over tmp[1]. It should do:
    > > >
    > > > printk("<%c>ALSA %s:%d: ", format[1], tmp, file, line);
    > > >
    > > > (I didn't know that you can even modify literal strings - shouldn't
    > > > they be in read-only storage?)
    > >
    > > no Andrew, this tmp[] is declared on the stack, and gcc emits code to
    > > copy the constant "<0>" onto the stack every time this code is called
    >
    > Good heavens, so it does. It is unusual for C to cater to such stupid
    > code by generating such inefficient code. A bit of a trap, really.

    Indeed the tmp string isn't needed to be there.
    Simply
    printk("<%c>ALSA %s:%d: ", format[1], file, line);
    should suffice. Though, the efficiency doesn't matter so much in this
    case...


    Takashi


    \
     
     \ /
      Last update: 2008-12-06 10:47    [W:0.044 / U:0.520 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site