Received: by 10.223.185.116 with SMTP id b49csp1007468wrg; Tue, 20 Feb 2018 11:30:51 -0800 (PST) X-Google-Smtp-Source: AH8x225c567zJZfWrXZ1/lV2fOE8MztbSvCLlXUfVWx53FEFSDpoquW12XPAnG38c3iL2Fyg76kD X-Received: by 10.101.73.197 with SMTP id t5mr558068pgs.426.1519155051060; Tue, 20 Feb 2018 11:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519155051; cv=none; d=google.com; s=arc-20160816; b=tdTevB0MhwBnPuJvr+ExVZd8uYCXKINGMmw5I4JvXuT2iD+sUXH8IXQeqygSqvK9sr vlAxr4dj/Y6cHJwjPTn5VphucF9WGJYU6vdsna8UZJQmar95AtkQsQFjF5zwA5uDbxOH MI53OM8GZq5HJ7xzZQo8PC8O08h+Hq/PPqvVgidng8dUQ9V56iDDs5Qlm1moBMqXTlFW xdIX1RxNibj8WCRlJbQ99BjIb/LNzcldI2tf0UshvGUh/3P5xmjK8f7rerxi5qlQzCTz 41D3b9XW/FTmXvXLF+tk5vpR5v7kbgE7TlLURuOYYWDFLd5NqX5+vf5VVBGhYidGu0pz Dogg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=bklIrboADsYTbvsPBqotNoVyCT52gx6ikF8UbTD/L34=; b=boJAWj+q++7jJKyDWpTShqG44URr0TyiOplgcpRgohzEolaUmtqzMtd5rmKnfpqhjV 9ftjcQeyS7qTUMSBbmD89I4mubuqhzAQXPkAyGM1f4d+9ytfRaVUK2WPI6i9vVIEXy2u HNeOf2CCam2mgOXr6P/rwZAOidK2A4/WpJbGbbPJpVSVGAxr49w43XogrPEh5GW9TRQI PghJ9TnBk7MRR1Mj3EmjWo8s9quEpyZVpk5zs+ZTbLpZQrK5bhATyaN6rtQm85KNC1rE EQTqBQPyT16buliMK3vl4fFqzMLGE+eqpKwNQUQgwAOL7fQBM+RaPNpCI9Loj/9nrftO cWgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 206si885215pgb.647.2018.02.20.11.30.36; Tue, 20 Feb 2018 11:30:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752201AbeBTT33 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 20 Feb 2018 14:29:29 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:44401 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751785AbeBTT32 (ORCPT ); Tue, 20 Feb 2018 14:29:28 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id 6D58C2071C; Tue, 20 Feb 2018 20:20:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [91.160.177.164]) by mail.free-electrons.com (Postfix) with ESMTPSA id 1526720376; Tue, 20 Feb 2018 20:20:10 +0100 (CET) Date: Tue, 20 Feb 2018 20:20:08 +0100 From: Boris Brezillon To: Shreeya Patel Cc: boris.brezillon@free-electrons.com, richard@nod.at, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, cyrille.pitchen@wedev4u.fr, maximlevitsky@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, ezequiel@vanguardiasur.com.ar, outreachy-kernel@googlegroups.com Subject: Re: [PATCH NAND v2] mtd: nand: Replace printk() with appropriate pr_*macro() Message-ID: <20180220202008.4a67d0e9@bbrezillon> In-Reply-To: <1519148238.14621.3.camel@gmail.com> References: <1519046025-9412-1-git-send-email-shreeya.patel23498@gmail.com> <20180219155115.3d9d1bd5@bbrezillon> <1519146401.12276.4.camel@gmail.com> <20180220181647.6f2367b6@bbrezillon> <1519148238.14621.3.camel@gmail.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 20 Feb 2018 23:07:18 +0530 Shreeya Patel wrote: > On Tue, 2018-02-20 at 18:16 +0100, Boris Brezillon wrote: > > On Tue, 20 Feb 2018 22:36:41 +0530 > > Shreeya Patel wrote: > > > > > > > > On Mon, 2018-02-19 at 15:51 +0100, Boris Brezillon wrote: > > > > > > > > Hi Shreeya, > > > > > > > > On Mon, 19 Feb 2018 18:43:45 +0530 > > > > Shreeya Patel wrote: > > > >    > > > > > > > > > > > > > > > The log levels embedded with the name are more concise than > > > > > printk. > > > > > Replace printks having a log level with the appropriate > > > > > pr_*macro. > > > > > > > > > > Signed-off-by: Shreeya Patel > > > > > --- > > > > > > > > > > Changes in v2: > > > > >   -Merge previous patches of the patchset regarding replacement > > > > > of printk with pr_*macro, into single patch. > > > > > > > > > > > > > > >  drivers/mtd/nand/cs553x_nand.c   |  9 ++--- > > > > >  drivers/mtd/nand/diskonchip.c    | 76 +++++++++++++++++++++--- > > > > > ---- > > > > > ------------ > > > > >  drivers/mtd/nand/fsl_elbc_nand.c |  2 +- > > > > >  drivers/mtd/nand/fsl_ifc_nand.c  |  2 +- > > > > >  drivers/mtd/nand/mxc_nand.c      |  2 +- > > > > >  drivers/mtd/nand/nand_bch.c      | 12 +++---- > > > > >  drivers/mtd/nand/nandsim.c       | 10 +++--- > > > > >  drivers/mtd/nand/r852.c          |  2 +- > > > > >  drivers/mtd/nand/r852.h          |  6 ++-- > > > > >  drivers/mtd/nand/sm_common.c     |  5 ++- > > > > >  10 files changed, 65 insertions(+), 61 deletions(-) > > > > >    > > > > [...] > > > >    > > > > > > > > > > > > > > >   > > > > > diff --git a/drivers/mtd/nand/diskonchip.c > > > > > b/drivers/mtd/nand/diskonchip.c > > > > > index c3aa53c..b97d88c 100644 > > > > > --- a/drivers/mtd/nand/diskonchip.c > > > > > +++ b/drivers/mtd/nand/diskonchip.c   > > > > [...] > > > >    > > > > > > > > > > > > > > > @@ -438,7 +438,7 @@ static void __init > > > > > doc2000_count_chips(struct > > > > > mtd_info *mtd) > > > > >   break; > > > > >   } > > > > >   doc->chips_per_floor = i; > > > > > - printk(KERN_DEBUG "Detected %d chips per floor.\n", > > > > > i); > > > > > + pr_info("Detected %d chips per floor.\n", i);   > > > > Should be pr_debug() here. > > > >    > > > > > > > > > > > > > > >  } > > > > >     > > > > [...] > > > >    > > > > > > > > > > > > > > > diff --git a/drivers/mtd/nand/nandsim.c > > > > > b/drivers/mtd/nand/nandsim.c > > > > > index 246b439..4e5f817 100644 > > > > > --- a/drivers/mtd/nand/nandsim.c > > > > > +++ b/drivers/mtd/nand/nandsim.c > > > > > @@ -184,15 +184,15 @@ MODULE_PARM_DESC(bch,  "En > > > > > able > > > > > BCH ecc and set how many bits should " > > > > >   > > > > >  /* Simulator's output macros (logging, debugging, warning, > > > > > error) > > > > > */ > > > > >  #define NS_LOG(args...) \ > > > > > - do { if (log) printk(KERN_DEBUG NS_OUTPUT_PREFIX " > > > > > log: " > > > > > args); } while(0) > > > > > + do { if (log) pr_debug(NS_OUTPUT_PREFIX " log: " > > > > > args); } > > > > > while(0)   > > > > You could define pr_fmt() to avoid passing NS_OUTPUT_PREFIX. > > > > Something > > > > like: > > > > > > > > #define pr_fmt(fmt) "[nandsim]" fmt > > > > > > > > (remember to put this definition before include directives). > > > > > > > > Then, all you have to do is > > > > > > > > do { if (log) pr_debug(" log: " args); } while(0) > > > >    > > > > > > > > > > > > > > >  #define NS_DBG(args...) \ > > > > > - do { if (dbg) printk(KERN_DEBUG NS_OUTPUT_PREFIX " > > > > > debug: > > > > > " args); } while(0) > > > > > + do { if (dbg) pr_debug(NS_OUTPUT_PREFIX " debug: " > > > > > args); > > > > > } while(0) > > > > >  #define NS_WARN(args...) \ > > > > > - do { printk(KERN_WARNING NS_OUTPUT_PREFIX " warning: " > > > > > args); } while(0) > > > > > + do { pr_warn(NS_OUTPUT_PREFIX " warning: " args); } > > > > > while(0) > > > > >  #define NS_ERR(args...) \ > > > > > - do { printk(KERN_ERR NS_OUTPUT_PREFIX " error: " > > > > > args); } > > > > > while(0) > > > > > + do { pr_err(NS_OUTPUT_PREFIX " error: " args); } > > > > > while(0) > > > > >  #define NS_INFO(args...) \ > > > > > - do { printk(KERN_INFO NS_OUTPUT_PREFIX " " args); } > > > > > while(0) > > > > > + do { pr_info(NS_OUTPUT_PREFIX " " args); } while(0) > > > > >   > > > > >  /* Busy-wait delay macros (microseconds, milliseconds) */ > > > > >  #define NS_UDELAY(us) \ > > > > > diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c > > > > > index fc9287a..3d54c6a 100644 > > > > > --- a/drivers/mtd/nand/r852.c > > > > > +++ b/drivers/mtd/nand/r852.c > > > > > @@ -935,7 +935,7 @@ static int  r852_probe(struct pci_dev > > > > > *pci_dev, > > > > > const struct pci_device_id *id) > > > > >   &dev->card_detect_work, 0); > > > > >   > > > > >   > > > > > - printk(KERN_NOTICE DRV_NAME ": driver loaded > > > > > successfully\n"); > > > > > + pr_notice(DRV_NAME ": driver loaded > > > > > successfully\n");   > > > > Same here: > > > > > > > > #define pr_fmt(fmt) DRV_NAME fmt   > > > I am facing the following errors here. > > > > > > > > > > > > In file included from drivers/mtd/nand/r852.c:22:0: > > > drivers/mtd/nand/r852.h:148:0: warning: "pr_fmt" redefined > > >  #define pr_fmt(fmt)  (DRV_NAME fmt) > > >  ^ > > > In file included from ./include/linux/kernel.h:14:0, > > >                  from drivers/mtd/nand/r852.c:10: > > > ./include/linux/printk.h:287:0: note: this is the location of the > > > previous definition > > >  #define pr_fmt(fmt) fmt > > That's because you didn't define pr_fmt() before all the #include > > directives in this driver. See the '#indef pr_fmt' statement in > > printk.h > > which is preventing redefinition of this symbol if the file including > > printk.h (either directly or indirectly) already defines it. > > Yes, and that is why I did undef before defining it again in the r852.c > file. > Shouldn't it work in this manner? It should compile (I'd need to see the diff to figure out why it fails to compile in your case), but not necessarily do what you want. When you use #undef/#define to redefine a macro the new definition applies to everything that uses it in the code *after* the point it's been redefined. One problem I can think of (but there probably are others) is when some intermediate header files use pr_xxx() inside macros/inline functions. In this case, you probably want the prefix to be applied and that can only be done if you've defined your own pr_fmt() before including printk.h. Another reason to define pr_fmt() before including printk.h is that it requires one line instead of 2 if you go for the #undef/#define solution. -- Boris Brezillon, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com