Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759466Ab2EIOPf (ORCPT ); Wed, 9 May 2012 10:15:35 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:43763 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756172Ab2EIOPe (ORCPT ); Wed, 9 May 2012 10:15:34 -0400 Date: Wed, 9 May 2012 16:15:28 +0200 From: Ingo Molnar To: Peter Zijlstra Cc: Igor Mammedov , Jiang Liu , linux-kernel@vger.kernel.org, pjt@google.com, tglx@linutronix.de, seto.hidetoshi@jp.fujitsu.com, Andrew Morton , Linus Torvalds Subject: Re: [RFC][PATCH] printk: Add %pb to print bitmaps Message-ID: <20120509141528.GA3623@gmail.com> References: <4FAA452A.1070909@gmail.com> <4FAA588B.5010404@redhat.com> <1336564330.2527.23.camel@twins> <4FAA5BFB.40309@redhat.com> <1336566096.2527.30.camel@twins> <1336566644.2527.33.camel@twins> <1336570043.2527.38.camel@twins> <20120509133607.GA26124@gmail.com> <1336571049.2527.43.camel@twins> <1336571947.2527.47.camel@twins> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1336571947.2527.47.camel@twins> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2010 Lines: 67 * Peter Zijlstra wrote: > On Wed, 2012-05-09 at 15:44 +0200, Peter Zijlstra wrote: > > On Wed, 2012-05-09 at 15:36 +0200, Ingo Molnar wrote: > > > * Peter Zijlstra wrote: > > > > > > > @@ -857,15 +860,19 @@ int kptr_restrict __read_mostly; > > > > * correctness of the format string and va_list arguments. > > > > * - 'K' For a kernel pointer that should be hidden from unprivileged users > > > > * - 'NF' For a netdev_features_t > > > > + * - 'b' For a bitmap, consumes 2 args, second is int > > > > > > hm, won't the second arg confuse gcc's printf format checker? > > > > > > Ah, yes, I suppose I could abuse something like %*pb. Let me try that. > > I guess I should use %.*pb and keep the field_width in case someone > manages to actually make bitmap_scnlistprintf() conform to it. The > precision is unused anyway. That's a cute trick, and it's intuitive as well. > + case 'b': > + { > + int bits, len; > + > + switch (fmt[1]) { > + case 'c': > + bits = nr_cpumask_bits; > + break; > + case 'n': > + bits = MAX_NUMNODES; > + break; > + default: > + bits = spec->precision; > + break; So, if someone specifies an incomplete "%pb" format - fmt[1] will be 0 and we take precision as the length - presumably also 0. We stick that 0 into: > + len = bitmap_scnlistprintf(buf, end - buf, ptr, bits); Will that work? Provided it all tests out fine for you it looks good to me. I'd probably write the switch statement as: switch (fmt[1]) { case 'c': bits = nr_cpumask_bits; break; case 'n': bits = MAX_NUMNODES; break; default: bits = spec->precision; break; } ... but that's a small detail and a matter of taste in any case. Thanks, Ingo -- 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/