Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756144AbYLFJoJ (ORCPT ); Sat, 6 Dec 2008 04:44:09 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751058AbYLFJnz (ORCPT ); Sat, 6 Dec 2008 04:43:55 -0500 Received: from mx2.suse.de ([195.135.220.15]:56973 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbYLFJnx (ORCPT ); Sat, 6 Dec 2008 04:43:53 -0500 Date: Sat, 06 Dec 2008 10:43:50 +0100 Message-ID: From: Takashi Iwai To: Andrew Morton Cc: Willy Tarreau , Nick Andrew , Linux Kernel Mailing List , Linus Torvalds , Tejun Heo Subject: Re: [RFC] Recursive printk In-Reply-To: <20081205234105.430a7b5e.akpm@linux-foundation.org> References: <20081206065922.29149.63380.stgit@marcab.local.tull.net> <20081205232016.366765e2.akpm@linux-foundation.org> <20081206073304.GE24654@1wt.eu> <20081205234105.430a7b5e.akpm@linux-foundation.org> User-Agent: Wanderlust/2.12.0 (Your Wildest Dreams) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (=?ISO-8859-4?Q?Sanj=F2?=) APEL/10.6 Emacs/22.3 (x86_64-suse-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1630 Lines: 42 At Fri, 5 Dec 2008 23:41:05 -0800, Andrew Morton wrote: > > On Sat, 6 Dec 2008 08:33:05 +0100 Willy Tarreau 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 -- 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/