Skip to contentSkip to conversation

use printk_once

PATCH Applied Marcin Slusarz 11 participants 35 messages Aug 9, 2009 – Aug 13, 2009

Subsystems (20)
Networking Network drivers x86 SCSI +16 more subsystems
lore
Share & tools
lore
#0 lore raw

cover use printk_once

 arch/alpha/kernel/pci_iommu.c      |    6 +-----
 arch/ia64/kernel/unaligned.c       |    6 ++----
 arch/ia64/sn/kernel/io_common.c    |    8 ++------
 arch/powerpc/kernel/iommu.c        |    6 +-----
 arch/powerpc/kernel/irq.c          |    5 ++---
 arch/powerpc/sysdev/ppc4xx_pci.c   |    9 ++-------
 arch/sh/mm/ioremap_64.c            |    6 +-----
 arch/x86/kernel/irq_32.c           |    5 ++---
 arch/x86/kvm/x86.c                 |    7 +------
 drivers/ata/pata_rz1000.c          |    4 +---
 drivers/block/paride/pcd.c         |   12 ++++--------
 drivers/block/sx8.c                |    4 +---
 drivers/block/viodasd.c            |   12 +++---------
 drivers/char/tty_ioctl.c           |    4 +---
 drivers/char/vt.c                  |    6 +-----
 drivers/ide/ide-proc.c             |    8 +-------
 drivers/infiniband/hw/cxgb3/iwch.c |    4 +---
 drivers/infiniband/hw/mlx4/main.c  |    6 +-----
 drivers/net/mlx4/en_main.c         |    6 +-----
 drivers/net/mv643xx_eth.c          |    4 +---
 drivers/scsi/53c700.c              |    6 +-----
 drivers/scsi/cxgb3i/cxgb3i_init.c  |    7 +------
 lib/vsprintf.c                     |   14 ++------------
 net/ax25/af_ax25.c                 |    6 +-----
 net/dsa/dsa.c                      |    4 +---
 net/ipv4/raw.c                     |    6 ++----
 net/netfilter/xt_recent.c          |   10 +++-------
 net/socket.c                       |    8 ++------
 28 files changed, 43 insertions(+), 146 deletions(-)
#1 lore raw

PATCH 1/14 alpha: use printk_once

Cc Ivan Kokshaysky <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Andrew Morton <[email protected]>
---
 arch/alpha/kernel/pci_iommu.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
arch/alpha/kernel/pci_iommu.c +1 -5
index bfb880a..d15aedf 100644
@@ -268,11 +268,7 @@ pci_map_single_1(struct pci_dev *pdev, void *cpu_addr, size_t size,
 	   assume it doesn't support sg mapping, and, since we tried to
 	   use direct_map above, it now must be considered an error. */
 	if (! alpha_mv.mv_pci_tbi) {
-		static int been_here = 0; /* Only print the message once. */
-		if (!been_here) {
-		    printk(KERN_WARNING "pci_map_single: no HW sg\n");
-		    been_here = 1;
-		}
+		printk_once(KERN_WARNING "pci_map_single: no HW sg\n");
 		return 0;
 	}
 
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH 2/14 ia64: use printk_once

In reply to Marcin Slusarz
---
 arch/ia64/kernel/unaligned.c    |    6 ++----
 arch/ia64/sn/kernel/io_common.c |    8 ++------
 2 files changed, 4 insertions(+), 10 deletions(-)
arch/ia64/kernel/unaligned.c +2 -4
index 6db0859..776dd40 100644
@@ -60,7 +60,6 @@ dump (const char *str, void *vp, size_t len)
  */
 int no_unaligned_warning;
 int unaligned_dump_stack;
-static int noprint_warning;
 
 /*
  * For M-unit:
@@ -1357,9 +1356,8 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
 			/* watch for command names containing %s */
 			printk(KERN_WARNING "%s", buf);
 		} else {
-			if (no_unaligned_warning && !noprint_warning) {
-				noprint_warning = 1;
-				printk(KERN_WARNING "%s(%d) encountered an "
+			if (no_unaligned_warning) {
+				printk_once(KERN_WARNING "%s(%d) encountered an "
 				       "unaligned exception which required\n"
 				       "kernel assistance, which degrades "
 				       "the performance of the application.\n"
arch/ia64/sn/kernel/io_common.c +2 -6
index 25831c4..308e659 100644
@@ -119,7 +119,6 @@ sn_pcidev_info_get(struct pci_dev *dev)
  * Additionally note that the struct sn_flush_device_war also has to be
  * removed from arch/ia64/sn/include/xtalk/hubdev.h
  */
-static u8 war_implemented = 0;
 
 static s64 sn_device_fixup_war(u64 nasid, u64 widget, int device,
 			       struct sn_flush_device_common *common)
@@ -128,11 +127,8 @@ static s64 sn_device_fixup_war(u64 nasid, u64 widget, int device,
 	struct sn_flush_device_war *dev_entry;
 	struct ia64_sal_retval isrv = {0,0,0,0};
 
-	if (!war_implemented) {
-		printk(KERN_WARNING "PROM version < 4.50 -- implementing old "
-		       "PROM flush WAR\n");
-		war_implemented = 1;
-	}
+	printk_once(KERN_WARNING
+		"PROM version < 4.50 -- implementing old PROM flush WAR\n");
 
 	war_list = kzalloc(DEV_PER_WIDGET * sizeof(*war_list), GFP_KERNEL);
 	BUG_ON(!war_list);
Signature · 1 line
1.6.3.3
#3 lore raw

PATCH 3/14 powerpc: use printk_once

In reply to Marcin Slusarz
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
---
 arch/powerpc/kernel/iommu.c      |    6 +-----
 arch/powerpc/kernel/irq.c        |    5 ++---
 arch/powerpc/sysdev/ppc4xx_pci.c |    9 ++-------
 3 files changed, 5 insertions(+), 15 deletions(-)
arch/powerpc/kernel/iommu.c +1 -5
index fd51578..c7fa258 100644
@@ -502,7 +502,6 @@ static void iommu_table_clear(struct iommu_table *tbl)
 struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 {
 	unsigned long sz;
-	static int welcomed = 0;
 	struct page *page;
 
 	/* Set aside 1/4 of the table for large allocations. */
@@ -523,11 +522,8 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 
 	iommu_table_clear(tbl);
 
-	if (!welcomed) {
-		printk(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
+	printk_once(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
 		       novmerge ? "disabled" : "enabled");
-		welcomed = 1;
-	}
 
 	return tbl;
 }
arch/powerpc/kernel/irq.c +2 -3
index f7f376e..05ebd21 100644
@@ -231,7 +231,6 @@ skip:
 void fixup_irqs(cpumask_t map)
 {
 	unsigned int irq;
-	static int warned;
 
 	for_each_irq(irq) {
 		cpumask_t mask;
@@ -246,8 +245,8 @@ void fixup_irqs(cpumask_t map)
 		}
 		if (irq_desc[irq].chip->set_affinity)
 			irq_desc[irq].chip->set_affinity(irq, &mask);
-		else if (irq_desc[irq].action && !(warned++))
-			printk("Cannot set affinity for irq %i\n", irq);
+		else if (irq_desc[irq].action)
+			printk_once("Cannot set affinity for irq %i\n", irq);
 	}
 
 	local_irq_enable();
arch/powerpc/sysdev/ppc4xx_pci.c +2 -7
index 6ff9d71..4282dff 100644
@@ -1243,19 +1243,14 @@ static int ppc4xx_pciex_validate_bdf(struct ppc4xx_pciex_port *port,
 				     struct pci_bus *bus,
 				     unsigned int devfn)
 {
-	static int message;
-
 	/* Endpoint can not generate upstream(remote) config cycles */
 	if (port->endpoint && bus->number != port->hose->first_busno)
 		return PCIBIOS_DEVICE_NOT_FOUND;
 
 	/* Check we are within the mapped range */
 	if (bus->number > port->hose->last_busno) {
-		if (!message) {
-			printk(KERN_WARNING "Warning! Probing bus %u"
-			       " out of range !\n", bus->number);
-			message++;
-		}
+		printk_once(KERN_WARNING
+			"Warning! Probing bus %u out of range!\n", bus->number);
 		return PCIBIOS_DEVICE_NOT_FOUND;
 	}
 
Signature · 1 line
1.6.3.3
Acked-by on v1 3/14
#4 lore raw

Re: [PATCH 03/14] powerpc: use printk_once

Quoted 48 lines · Marcin Slusarz
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
---
 arch/powerpc/kernel/iommu.c      |    6 +-----
 arch/powerpc/kernel/irq.c        |    5 ++---
 arch/powerpc/sysdev/ppc4xx_pci.c |    9 ++-------
 3 files changed, 5 insertions(+), 15 deletions(-)
arch/powerpc/kernel/iommu.c +1 -5
index fd51578..c7fa258 100644
@@ -502,7 +502,6 @@ static void iommu_table_clear(struct iommu_table *tbl)
 struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 {
 	unsigned long sz;
-	static int welcomed = 0;
 	struct page *page;
 
 	/* Set aside 1/4 of the table for large allocations. */
@@ -523,11 +522,8 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 
 	iommu_table_clear(tbl);
 
-	if (!welcomed) {
-		printk(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
+	printk_once(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
 		       novmerge ? "disabled" : "enabled");
-		welcomed = 1;
-	}
 
 	return tbl;
 }
arch/powerpc/kernel/irq.c +0 -1
index f7f376e..05ebd21 100644
@@ -231,7 +231,6 @@ skip:
 void fixup_irqs(cpumask_t map)
 {
 	unsigned int irq;
-	static int warned;
 
 	for_each_irq(irq) {
 		cpumask_t mask;

arch/powerpc/kernel/irq.c void fixup_irqs(cpumask_t map) · line 249

Quoted 7 lines
arch/powerpc/kernel/irq.c +2 -2
@@ -246,8 +245,8 @@ void fixup_irqs(cpumask_t map)
 		}
 		if (irq_desc[irq].chip->set_affinity)
 			irq_desc[irq].chip->set_affinity(irq, &mask);
-		else if (irq_desc[irq].action && !(warned++))
-			printk("Cannot set affinity for irq %i\n", irq);
+		else if (irq_desc[irq].action)
+			printk_once("Cannot set affinity for irq %i\n", irq);

Maybe we should add a loglevel to this printk (and the other one in fix_irqs) while we are here?

Other than that:

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#5 lore raw

Re: [PATCH 03/14] powerpc: use printk_once

Quoted 46 lines · Wolfram Sang
Quoted 45 lines · Marcin Slusarz
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
---
 arch/powerpc/kernel/iommu.c      |    6 +-----
 arch/powerpc/kernel/irq.c        |    5 ++---
 arch/powerpc/sysdev/ppc4xx_pci.c |    9 ++-------
 3 files changed, 5 insertions(+), 15 deletions(-)
arch/powerpc/kernel/iommu.c +1 -5
index fd51578..c7fa258 100644
@@ -502,7 +502,6 @@ static void iommu_table_clear(struct iommu_table *tbl)
 struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 {
 	unsigned long sz;
-	static int welcomed = 0;
 	struct page *page;
 
 	/* Set aside 1/4 of the table for large allocations. */
@@ -523,11 +522,8 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 
 	iommu_table_clear(tbl);
 
-	if (!welcomed) {
-		printk(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
+	printk_once(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
 		       novmerge ? "disabled" : "enabled");
-		welcomed = 1;
-	}
 
 	return tbl;
 }
arch/powerpc/kernel/irq.c +0 -1
index f7f376e..05ebd21 100644
@@ -231,7 +231,6 @@ skip:
 void fixup_irqs(cpumask_t map)
 {
 	unsigned int irq;
-	static int warned;
 
Quoted 13 lines

arch/powerpc/kernel/irq.c void fixup_irqs(cpumask_t map) · line 249

Quoted 10 lines
arch/powerpc/kernel/irq.c +2 -2
 	for_each_irq(irq) {
 		cpumask_t mask;
@@ -246,8 +245,8 @@ void fixup_irqs(cpumask_t map)
 		}
 		if (irq_desc[irq].chip->set_affinity)
 			irq_desc[irq].chip->set_affinity(irq, &mask);
-		else if (irq_desc[irq].action && !(warned++))
-			printk("Cannot set affinity for irq %i\n", irq);
+		else if (irq_desc[irq].action)
+			printk_once("Cannot set affinity for irq %i\n", irq);

Maybe we should add a loglevel to this printk (and the other one in fix_irqs) while we are here?

I think you should drop it, it's stupid. If we actually care about irqs that don't have a set affinity we should keep a count and report that at the end of the loop.

cheers

#6 lore raw

Re: [PATCH 03/14] powerpc: use printk_once

Quoted 60 lines · Michael Ellerman
Quoted 46 lines · Wolfram Sang
Quoted 45 lines · Marcin Slusarz
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
---
 arch/powerpc/kernel/iommu.c      |    6 +-----
 arch/powerpc/kernel/irq.c        |    5 ++---
 arch/powerpc/sysdev/ppc4xx_pci.c |    9 ++-------
 3 files changed, 5 insertions(+), 15 deletions(-)
arch/powerpc/kernel/iommu.c +1 -5
index fd51578..c7fa258 100644
@@ -502,7 +502,6 @@ static void iommu_table_clear(struct iommu_table *tbl)
 struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 {
 	unsigned long sz;
-	static int welcomed = 0;
 	struct page *page;
 
 	/* Set aside 1/4 of the table for large allocations. */
@@ -523,11 +522,8 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 
 	iommu_table_clear(tbl);
 
-	if (!welcomed) {
-		printk(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
+	printk_once(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
 		       novmerge ? "disabled" : "enabled");
-		welcomed = 1;
-	}
 
 	return tbl;
 }
arch/powerpc/kernel/irq.c +0 -1
index f7f376e..05ebd21 100644
@@ -231,7 +231,6 @@ skip:
 void fixup_irqs(cpumask_t map)
 {
 	unsigned int irq;
-	static int warned;
 
Quoted 12 lines

arch/powerpc/kernel/irq.c void fixup_irqs(cpumask_t map) · line 249

Quoted 10 lines
arch/powerpc/kernel/irq.c +2 -2
 	for_each_irq(irq) {
 		cpumask_t mask;
@@ -246,8 +245,8 @@ void fixup_irqs(cpumask_t map)
 		}
 		if (irq_desc[irq].chip->set_affinity)
 			irq_desc[irq].chip->set_affinity(irq, &mask);
-		else if (irq_desc[irq].action && !(warned++))
-			printk("Cannot set affinity for irq %i\n", irq);
+		else if (irq_desc[irq].action)
+			printk_once("Cannot set affinity for irq %i\n", irq);

Maybe we should add a loglevel to this printk (and the other one in fix_irqs) while we are here?

Quoted 3 lines

I think you should drop it, it's stupid. If we actually care about irqs that don't have a set affinity we should keep a count and report that at the end of the loop.

In addition, this change would prevent reporting missing affinity on more than one IRQ if there were such.

Signature · 4 lines
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
#7 lore raw

PATCH 4/14 sh: use printk_once

In reply to Marcin Slusarz
---
 arch/sh/mm/ioremap_64.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
arch/sh/mm/ioremap_64.c +1 -5
index 828c859..b16843d 100644
@@ -94,7 +94,6 @@ static struct resource *shmedia_find_resource(struct resource *root,
 static void __iomem *shmedia_alloc_io(unsigned long phys, unsigned long size,
 				      const char *name, unsigned long flags)
 {
-	static int printed_full;
 	struct xresource *xres;
 	struct resource *res;
 	char *tack;
@@ -108,11 +107,8 @@ static void __iomem *shmedia_alloc_io(unsigned long phys, unsigned long size,
 		tack = xres->xname;
 		res = &xres->xres;
 	} else {
-		if (!printed_full) {
-			printk(KERN_NOTICE "%s: done with statics, "
+		printk_once(KERN_NOTICE "%s: done with statics, "
 			       "switching to kmalloc\n", __func__);
-			printed_full = 1;
-		}
 		tlen = strlen(name);
 		tack = kmalloc(sizeof(struct resource) + tlen + 1, GFP_KERNEL);
 		if (!tack)
Signature · 1 line
1.6.3.3
#9 lore raw

PATCH 5/14 x86: use printk_once

In reply to Marcin Slusarz
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/irq_32.c |    5 ++---
 arch/x86/kvm/x86.c       |    7 +------
 2 files changed, 3 insertions(+), 9 deletions(-)
arch/x86/kernel/irq_32.c +2 -3
index 3b09634..7d35d0f 100644
@@ -218,7 +218,6 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
 void fixup_irqs(void)
 {
 	unsigned int irq;
-	static int warned;
 	struct irq_desc *desc;
 
 	for_each_irq_desc(irq, desc) {
@@ -236,8 +235,8 @@ void fixup_irqs(void)
 		}
 		if (desc->chip->set_affinity)
 			desc->chip->set_affinity(irq, affinity);
-		else if (desc->action && !(warned++))
-			printk("Cannot set affinity for irq %i\n", irq);
+		else if (desc->action)
+			printk_once("Cannot set affinity for irq %i\n", irq);
 	}
 
 #if 0
arch/x86/kvm/x86.c +1 -6
index fe5474a..0572c90 100644
@@ -2261,12 +2261,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 				     unsigned int bytes,
 				     struct kvm_vcpu *vcpu)
 {
-	static int reported;
-
-	if (!reported) {
-		reported = 1;
-		printk(KERN_WARNING "kvm: emulating exchange as write\n");
-	}
+	printk_once(KERN_WARNING "kvm: emulating exchange as write\n");
 #ifndef CONFIG_X86_64
 	/* guests cmpxchg8b have to be emulated atomically */
 	if (bytes == 8) {
Signature · 1 line
1.6.3.3
#10 lore raw

[tip:x86/cleanups] x86: Use printk_once()

Commit-ID:  9f51e24ee8b5a1595b6a5ac0c2be278a16488e75
Gitweb:     http://git.kernel.org/tip/9f51e24ee8b5a1595b6a5ac0c2be278a16488e75
Author:     Marcin Slusarz <[email protected]>
AuthorDate: Sun, 9 Aug 2009 21:54:00 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 9 Aug 2009 22:28:34 +0200

x86: Use printk_once()

Cc "H. Peter Anvin" <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/irq_32.c |    5 ++---
 arch/x86/kvm/x86.c       |    7 +------
 2 files changed, 3 insertions(+), 9 deletions(-)
arch/x86/kernel/irq_32.c +2 -3
index 3b09634..7d35d0f 100644
@@ -218,7 +218,6 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
 void fixup_irqs(void)
 {
 	unsigned int irq;
-	static int warned;
 	struct irq_desc *desc;
 
 	for_each_irq_desc(irq, desc) {
@@ -236,8 +235,8 @@ void fixup_irqs(void)
 		}
 		if (desc->chip->set_affinity)
 			desc->chip->set_affinity(irq, affinity);
-		else if (desc->action && !(warned++))
-			printk("Cannot set affinity for irq %i\n", irq);
+		else if (desc->action)
+			printk_once("Cannot set affinity for irq %i\n", irq);
 	}
 
 #if 0
arch/x86/kvm/x86.c +1 -6
index fe5474a..0572c90 100644
@@ -2261,12 +2261,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 				     unsigned int bytes,
 				     struct kvm_vcpu *vcpu)
 {
-	static int reported;
-
-	if (!reported) {
-		reported = 1;
-		printk(KERN_WARNING "kvm: emulating exchange as write\n");
-	}
+	printk_once(KERN_WARNING "kvm: emulating exchange as write\n");
 #ifndef CONFIG_X86_64
 	/* guests cmpxchg8b have to be emulated atomically */
 	if (bytes == 8) {
#11 lore raw

PATCH 6/14 ata: use printk_once

In reply to Marcin Slusarz
---
 drivers/ata/pata_rz1000.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/ata/pata_rz1000.c +1 -3
index 0c574c0..a5e4dfe 100644
@@ -85,7 +85,6 @@ static int rz1000_fifo_disable(struct pci_dev *pdev)
 
 static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-	static int printed_version;
 	static const struct ata_port_info info = {
 		.flags = ATA_FLAG_SLAVE_POSS,
 		.pio_mask = ATA_PIO4,
@@ -93,8 +92,7 @@ static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *en
 	};
 	const struct ata_port_info *ppi[] = { &info, NULL };
 
-	if (!printed_version++)
-		printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
+	printk_once(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
 
 	if (rz1000_fifo_disable(pdev) == 0)
 		return ata_pci_sff_init_one(pdev, ppi, &rz1000_sht, NULL);
Signature · 1 line
1.6.3.3
#12 lore raw

PATCH 7/14 block: use printk_once

In reply to Marcin Slusarz
---
 drivers/block/paride/pcd.c |   12 ++++--------
 drivers/block/sx8.c        |    4 +---
 drivers/block/viodasd.c    |   12 +++---------
 3 files changed, 8 insertions(+), 20 deletions(-)
drivers/block/paride/pcd.c +4 -8
index 911dfd9..9f3518c 100644
@@ -219,8 +219,6 @@ static int pcd_sector;		/* address of next requested sector */
 static int pcd_count;		/* number of blocks still to do */
 static char *pcd_buf;		/* buffer for request in progress */
 
-static int pcd_warned;		/* Have we logged a phase warning ? */
-
 /* kernel glue structures */
 
 static int pcd_block_open(struct block_device *bdev, fmode_t mode)
@@ -417,12 +415,10 @@ static int pcd_completion(struct pcd_unit *cd, char *buf, char *fun)
 					printk
 					    ("%s: %s: Unexpected phase %d, d=%d, k=%d\n",
 					     cd->name, fun, p, d, k);
-				if ((verbose < 2) && !pcd_warned) {
-					pcd_warned = 1;
-					printk
-					    ("%s: WARNING: ATAPI phase errors\n",
-					     cd->name);
-				}
+				if (verbose < 2)
+					printk_once(
+					    "%s: WARNING: ATAPI phase errors\n",
+					    cd->name);
 				mdelay(1);
 			}
 			if (k++ > PCD_TMO) {
drivers/block/sx8.c +1 -3
index da403b6..f5cd2e8 100644
@@ -1564,15 +1564,13 @@ static int carm_init_shm(struct carm_host *host)
 
 static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-	static unsigned int printed_version;
 	struct carm_host *host;
 	unsigned int pci_dac;
 	int rc;
 	struct request_queue *q;
 	unsigned int i;
 
-	if (!printed_version++)
-		printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
+	printk_once(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
 
 	rc = pci_enable_device(pdev);
 	if (rc)
drivers/block/viodasd.c +3 -9
index 390d69b..b441ce3 100644
@@ -416,15 +416,9 @@ retry:
 		goto retry;
 	}
 	if (we.max_disk > (MAX_DISKNO - 1)) {
-		static int warned;
-
-		if (warned == 0) {
-			warned++;
-			printk(VIOD_KERN_INFO
-				"Only examining the first %d "
-				"of %d disks connected\n",
-				MAX_DISKNO, we.max_disk + 1);
-		}
+		printk_once(VIOD_KERN_INFO
+			"Only examining the first %d of %d disks connected\n",
+			MAX_DISKNO, we.max_disk + 1);
 	}
 
 	/* Send the close event to OS/400.  We DON'T expect a response */
Signature · 1 line
1.6.3.3
#13 lore raw

PATCH 8/14 tty/vt: use printk_once

In reply to Marcin Slusarz
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/char/tty_ioctl.c |    4 +---
 drivers/char/vt.c        |    6 +-----
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/char/tty_ioctl.c +1 -3
index ad6ba4e..8e67d5c 100644
@@ -393,9 +393,7 @@ void tty_termios_encode_baud_rate(struct ktermios *termios,
 		termios->c_cflag |= (BOTHER << IBSHIFT);
 #else
 	if (ifound == -1 || ofound == -1) {
-		static int warned;
-		if (!warned++)
-			printk(KERN_WARNING "tty: Unable to return correct "
+		printk_once(KERN_WARNING "tty: Unable to return correct "
 			  "speed data as your architecture needs updating.\n");
 	}
 #endif
drivers/char/vt.c +1 -5
index 404f4c1..5d77fb3 100644
@@ -2129,11 +2129,7 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
 	currcons = vc->vc_num;
 	if (!vc_cons_allocated(currcons)) {
 	    /* could this happen? */
-	    static int error = 0;
-	    if (!error) {
-		error = 1;
-		printk("con_write: tty %d not allocated\n", currcons+1);
-	    }
+		printk_once("con_write: tty %d not allocated\n", currcons+1);
 	    release_console_sem();
 	    return 0;
 	}
Signature · 1 line
1.6.3.3
#14 lore raw

PATCH 9/14 ide: use printk_once

In reply to Marcin Slusarz
Cc "David S. Miller" <[email protected]>
Cc Bartlomiej Zolnierkiewicz <[email protected]>
---
 drivers/ide/ide-proc.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)
drivers/ide/ide-proc.c +1 -7
index 3242698..6e58e7e 100644
@@ -236,14 +236,8 @@ static const struct ide_proc_devset ide_generic_settings[] = {
 
 static void proc_ide_settings_warn(void)
 {
-	static int warned;
-
-	if (warned)
-		return;
-
-	printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
+	printk_once(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
 			    "obsolete, and will be removed soon!\n");
-	warned = 1;
 }
 
 static int proc_ide_read_settings
Signature · 1 line
1.6.3.3
#16 lore raw

PATCH 10/14 infiniband: use printk_once

In reply to Marcin Slusarz
Cc Roland Dreier <[email protected]>
Cc Sean Hefty <[email protected]>
Cc Hal Rosenstock <[email protected]>
---
 drivers/infiniband/hw/cxgb3/iwch.c |    4 +---
 drivers/infiniband/hw/mlx4/main.c  |    6 +-----
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/infiniband/hw/cxgb3/iwch.c +1 -3
index 26fc0a4..9cc99df 100644
@@ -105,11 +105,9 @@ static void rnic_init(struct iwch_dev *rnicp)
 static void open_rnic_dev(struct t3cdev *tdev)
 {
 	struct iwch_dev *rnicp;
-	static int vers_printed;
 
 	PDBG("%s t3cdev %p\n", __func__,  tdev);
-	if (!vers_printed++)
-		printk(KERN_INFO MOD "Chelsio T3 RDMA Driver - version %s\n",
+	printk_once(KERN_INFO MOD "Chelsio T3 RDMA Driver - version %s\n",
 		       DRV_VERSION);
 	rnicp = (struct iwch_dev *)ib_alloc_device(sizeof(*rnicp));
 	if (!rnicp) {
drivers/infiniband/hw/mlx4/main.c +1 -5
index ae3d759..0b2f77a 100644
@@ -540,15 +540,11 @@ static struct device_attribute *mlx4_class_attributes[] = {
 
 static void *mlx4_ib_add(struct mlx4_dev *dev)
 {
-	static int mlx4_ib_version_printed;
 	struct mlx4_ib_dev *ibdev;
 	int num_ports = 0;
 	int i;
 
-	if (!mlx4_ib_version_printed) {
-		printk(KERN_INFO "%s", mlx4_ib_version);
-		++mlx4_ib_version_printed;
-	}
+	printk_once(KERN_INFO "%s", mlx4_ib_version);
 
 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB)
 		num_ports++;
Signature · 1 line
1.6.3.3
#17 lore raw

Re: [PATCH 10/14] infiniband: use printk_once

Quoted 13 lines
 drivers/infiniband/hw/cxgb3/iwch.c |    4 +---
 drivers/infiniband/hw/mlx4/main.c  |    6 +-----
drivers/infiniband/hw/mlx4/main.c +0 -1
@@ -540,15 +540,11 @@ static struct device_attribute *mlx4_class_attributes[] = {
 
 static void *mlx4_ib_add(struct mlx4_dev *dev)
 {
-	static int mlx4_ib_version_printed;
 	struct mlx4_ib_dev *ibdev;
 	int num_ports = 0;

drivers/infiniband/hw/mlx4/main.c static struct device_attribute *mlx4_class_attributes[] = { · line 550

Quoted 10 lines
drivers/infiniband/hw/mlx4/main.c +1 -4
 	int i;
 
-	if (!mlx4_ib_version_printed) {
-		printk(KERN_INFO "%s", mlx4_ib_version);
-		++mlx4_ib_version_printed;
-	}
+	printk_once(KERN_INFO "%s", mlx4_ib_version);
 
 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB)
 		num_ports++;

Looks fine but there is near-identical code in drivers/infiniband/hw/mthca/mthca_main.c that you might as well convert too.

Thanks,
Roland

#18 lore raw

Re: [ofa-general] Re: [PATCH 10/14] infiniband: use printk_once

I'm a bit nervous about this one.
printk_once will print once ONLY if CONFIG_PRINTK is set in include/linux/autoconf.h (i.e., when the kernel is configured). Otherwise, it gets defined to printk -- and it will always print in this case.
(see 2.6.30.xx kernel include file "include/linux/kernel.h", lines 235, 249, and 272).

Do you think that distributions will ALWAYS have CONFIG_PRINTK defined?

I would prefer to wait until printk_once printing only once is not config-dependent.

-Jack

Quoted 37 lines · Roland Dreier
Quoted 13 lines
 drivers/infiniband/hw/cxgb3/iwch.c |    4 +---
 drivers/infiniband/hw/mlx4/main.c  |    6 +-----
drivers/infiniband/hw/mlx4/main.c +0 -1
@@ -540,15 +540,11 @@ static struct device_attribute *mlx4_class_attributes[] = {
 
 static void *mlx4_ib_add(struct mlx4_dev *dev)
 {
-	static int mlx4_ib_version_printed;
 	struct mlx4_ib_dev *ibdev;
 	int num_ports = 0;

drivers/infiniband/hw/mlx4/main.c static struct device_attribute *mlx4_class_attributes[] = { · line 550

Quoted 10 lines
drivers/infiniband/hw/mlx4/main.c +1 -4
 	int i;
 
-	if (!mlx4_ib_version_printed) {
-		printk(KERN_INFO "%s", mlx4_ib_version);
-		++mlx4_ib_version_printed;
-	}
+	printk_once(KERN_INFO "%s", mlx4_ib_version);
 
 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB)
 		num_ports++;

Looks fine but there is near-identical code in drivers/infiniband/hw/mthca/mthca_main.c that you might as well convert too.

Thanks,
Roland
_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

#19 lore raw

Re: [ofa-general] Re: [PATCH 10/14] infiniband: use printk_once

Quoted 3 lines · Jack Morgenstein

printk_once will print once ONLY if CONFIG_PRINTK is set in include/linux/autoconf.h (i.e., when the kernel is configured). Otherwise, it gets defined to printk -- and it will always print in this case.

Not true, in that case printk is defined as inlined 'return 0;'

Quoted 1 line

(see 2.6.30.xx kernel include file "include/linux/kernel.h", lines 235, 249, and 272).

See line 265 there.

#20 lore raw

Re: [ofa-general] Re: [PATCH 10/14] infiniband: use printk_once

In reply to Jack Morgenstein
Quoted 6 lines

I'm a bit nervous about this one.
printk_once will print once ONLY if CONFIG_PRINTK is set in include/linux/autoconf.h (i.e., when the kernel is configured). Otherwise, it gets defined to printk -- and it will always print in this case.
(see 2.6.30.xx kernel include file "include/linux/kernel.h", lines 235, 249, and 272).

Umm... if CONFIG_PRINTK is turned off nothing prints, right?

Quoted 1 line

Do you think that distributions will ALWAYS have CONFIG_PRINTK defined?

Yes, I suspect they do want to get kernel messages.

- R.

#21 lore raw

Re: [ofa-general] Re: [PATCH 10/14] infiniband: use printk_once

Quoted 8 lines · Roland Dreier
Quoted 6 lines

I'm a bit nervous about this one.
printk_once will print once ONLY if CONFIG_PRINTK is set in include/linux/autoconf.h (i.e., when the kernel is configured). Otherwise, it gets defined to printk -- and it will always print in this case.
(see 2.6.30.xx kernel include file "include/linux/kernel.h", lines 235, 249, and 272).

Umm... if CONFIG_PRINTK is turned off nothing prints, right?

Jiri Slaby pointed that out to me -- i.e., that printk itself is defined to do nothing but return 0 if CONFIG_PRINTK is not defined. (I missed that when looking at file kernel.h).

I thought no answer was needed (sorry about that) -- Jiri was so obviously correct.

I've got no problem with the patch.

-Jack

#22 lore raw

Re: [PATCH 10/14] infiniband: use printk_once

In reply to Roland Dreier
Quoted 20 lines · Roland Dreier
Quoted 20 lines
 drivers/infiniband/hw/cxgb3/iwch.c |    4 +---
 drivers/infiniband/hw/mlx4/main.c  |    6 +-----
drivers/infiniband/hw/mlx4/main.c +1 -5
@@ -540,15 +540,11 @@ static struct device_attribute *mlx4_class_attributes[] = {
 
 static void *mlx4_ib_add(struct mlx4_dev *dev)
 {
-	static int mlx4_ib_version_printed;
 	struct mlx4_ib_dev *ibdev;
 	int num_ports = 0;
 	int i;
 
-	if (!mlx4_ib_version_printed) {
-		printk(KERN_INFO "%s", mlx4_ib_version);
-		++mlx4_ib_version_printed;
-	}
+	printk_once(KERN_INFO "%s", mlx4_ib_version);
 
Quoted 6 lines

drivers/infiniband/hw/mlx4/main.c static struct device_attribute *mlx4_class_attributes[] = { · line 550

Quoted 2 lines
drivers/infiniband/hw/mlx4/main.c +0 -0
 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB)
 		num_ports++;

Looks fine but there is near-identical code in drivers/infiniband/hw/mthca/mthca_main.c that you might as well convert too.

Thanks for a hint. Updated patch below.

---
From: Marcin Slusarz <[email protected]>
Date: Mon, 10 Aug 2009 18:01:49 +0200
Subject: [PATCH 10/14 v2] infiniband: use printk_once

Cc Roland Dreier <[email protected]>
Cc Sean Hefty <[email protected]>
Cc Hal Rosenstock <[email protected]>
---
 drivers/infiniband/hw/cxgb3/iwch.c       |    4 +---
 drivers/infiniband/hw/mlx4/main.c        |    6 +-----
 drivers/infiniband/hw/mthca/mthca_main.c |    6 +-----
 3 files changed, 3 insertions(+), 13 deletions(-)
drivers/infiniband/hw/cxgb3/iwch.c +1 -3
index 26fc0a4..9cc99df 100644
@@ -105,11 +105,9 @@ static void rnic_init(struct iwch_dev *rnicp)
 static void open_rnic_dev(struct t3cdev *tdev)
 {
 	struct iwch_dev *rnicp;
-	static int vers_printed;
 
 	PDBG("%s t3cdev %p\n", __func__,  tdev);
-	if (!vers_printed++)
-		printk(KERN_INFO MOD "Chelsio T3 RDMA Driver - version %s\n",
+	printk_once(KERN_INFO MOD "Chelsio T3 RDMA Driver - version %s\n",
 		       DRV_VERSION);
 	rnicp = (struct iwch_dev *)ib_alloc_device(sizeof(*rnicp));
 	if (!rnicp) {
drivers/infiniband/hw/mlx4/main.c +1 -5
index ae3d759..0b2f77a 100644
@@ -540,15 +540,11 @@ static struct device_attribute *mlx4_class_attributes[] = {
 
 static void *mlx4_ib_add(struct mlx4_dev *dev)
 {
-	static int mlx4_ib_version_printed;
 	struct mlx4_ib_dev *ibdev;
 	int num_ports = 0;
 	int i;
 
-	if (!mlx4_ib_version_printed) {
-		printk(KERN_INFO "%s", mlx4_ib_version);
-		++mlx4_ib_version_printed;
-	}
+	printk_once(KERN_INFO "%s", mlx4_ib_version);
 
 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB)
 		num_ports++;
drivers/infiniband/hw/mthca/mthca_main.c +1 -5
index 13da9f1..2e4e043 100644
@@ -1215,15 +1215,11 @@ int __mthca_restart_one(struct pci_dev *pdev)
 static int __devinit mthca_init_one(struct pci_dev *pdev,
 				    const struct pci_device_id *id)
 {
-	static int mthca_version_printed = 0;
 	int ret;
 
 	mutex_lock(&mthca_device_mutex);
 
-	if (!mthca_version_printed) {
-		printk(KERN_INFO "%s", mthca_version);
-		++mthca_version_printed;
-	}
+	printk_once(KERN_INFO "%s", mthca_version);
 
 	if (id->driver_data >= ARRAY_SIZE(mthca_hca_table)) {
 		printk(KERN_ERR PFX "%s has invalid driver data %lx\n",
Signature · 1 line
1.6.3.3
#23 lore raw

Re: [PATCH 10/14] infiniband: use printk_once

thanks, applied.

#24 lore raw

PATCH 11/14 drivers/net: use printk_once

In reply to Marcin Slusarz
---
 drivers/net/mlx4/en_main.c |    6 +-----
 drivers/net/mv643xx_eth.c  |    4 +---
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/net/mlx4/en_main.c +1 -5
index 9ed4a15..18e9e4f 100644
@@ -151,15 +151,11 @@ static void mlx4_en_remove(struct mlx4_dev *dev, void *endev_ptr)
 
 static void *mlx4_en_add(struct mlx4_dev *dev)
 {
-	static int mlx4_en_version_printed;
 	struct mlx4_en_dev *mdev;
 	int i;
 	int err;
 
-	if (!mlx4_en_version_printed) {
-		printk(KERN_INFO "%s", mlx4_en_version);
-		mlx4_en_version_printed++;
-	}
+	printk_once(KERN_INFO "%s", mlx4_en_version);
 
 	mdev = kzalloc(sizeof *mdev, GFP_KERNEL);
 	if (!mdev) {
drivers/net/mv643xx_eth.c +1 -3
index 0f32db3..dbb1d9c 100644
@@ -2622,14 +2622,12 @@ static void infer_hw_params(struct mv643xx_eth_shared_private *msp)
 
 static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 {
-	static int mv643xx_eth_version_printed;
 	struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data;
 	struct mv643xx_eth_shared_private *msp;
 	struct resource *res;
 	int ret;
 
-	if (!mv643xx_eth_version_printed++)
-		printk(KERN_NOTICE "MV-643xx 10/100/1000 ethernet "
+	printk_once(KERN_NOTICE "MV-643xx 10/100/1000 ethernet "
 			"driver version %s\n", mv643xx_eth_driver_version);
 
 	ret = -EINVAL;
Signature · 1 line
1.6.3.3
#26 lore raw

PATCH 12/14 scsi: use printk_once

In reply to Marcin Slusarz
---
 drivers/scsi/53c700.c             |    6 +-----
 drivers/scsi/cxgb3i/cxgb3i_init.c |    7 +------
 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/scsi/53c700.c +1 -5
index f5a9add..c5f4fa7 100644
@@ -291,7 +291,6 @@ NCR_700_detect(struct scsi_host_template *tpnt,
 	__u8 *memory;
 	__u32 *script;
 	struct Scsi_Host *host;
-	static int banner = 0;
 	int j;
 
 	if(tpnt->sdev_attrs == NULL)
@@ -385,10 +384,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
 	else
 		hostdata->rev = (NCR_700_readb(host, CTEST7_REG)>>4) & 0x0f;
 	hostdata->fast = (NCR_700_readb(host, CTEST9_REG) == 0);
-	if (banner == 0) {
-		printk(KERN_NOTICE "53c700: Version " NCR_700_VERSION " By [email protected]\n");
-		banner = 1;
-	}
+	printk_once(KERN_NOTICE "53c700: Version " NCR_700_VERSION " By [email protected]\n");
 	printk(KERN_NOTICE "scsi%d: %s rev %d %s\n", host->host_no,
 	       hostdata->chip710 ? "53c710" :
 	       (hostdata->fast ? "53c700-66" : "53c700"),
drivers/scsi/cxgb3i/cxgb3i_init.c +1 -6
index 042d9bc..8c9285f 100644
@@ -43,12 +43,7 @@ static struct cxgb3_client t3c_client = {
  */
 static void open_s3_dev(struct t3cdev *t3dev)
 {
-	static int vers_printed;
-
-	if (!vers_printed) {
-		printk(KERN_INFO "%s", version);
-		vers_printed = 1;
-	}
+	printk_once(KERN_INFO "%s", version);
 
 	cxgb3i_ddp_init(t3dev);
 	cxgb3i_sdev_add(t3dev, &t3c_client);
Signature · 1 line
1.6.3.3
maintainer
#27 lore raw

Re: [PATCH 12/14] scsi: use printk_once

Quoted 37 lines · Marcin Slusarz
---
 drivers/scsi/53c700.c             |    6 +-----
 drivers/scsi/cxgb3i/cxgb3i_init.c |    7 +------
 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/scsi/53c700.c +1 -5
index f5a9add..c5f4fa7 100644
@@ -291,7 +291,6 @@ NCR_700_detect(struct scsi_host_template *tpnt,
 	__u8 *memory;
 	__u32 *script;
 	struct Scsi_Host *host;
-	static int banner = 0;
 	int j;
 
 	if(tpnt->sdev_attrs == NULL)
@@ -385,10 +384,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
 	else
 		hostdata->rev = (NCR_700_readb(host, CTEST7_REG)>>4) & 0x0f;
 	hostdata->fast = (NCR_700_readb(host, CTEST9_REG) == 0);
-	if (banner == 0) {
-		printk(KERN_NOTICE "53c700: Version " NCR_700_VERSION " By [email protected]\n");
-		banner = 1;
-	}
+	printk_once(KERN_NOTICE "53c700: Version " NCR_700_VERSION " By [email protected]\n");
 	printk(KERN_NOTICE "scsi%d: %s rev %d %s\n", host->host_no,
 	       hostdata->chip710 ? "53c710" :
 	       (hostdata->fast ? "53c700-66" : "53c700"),
drivers/scsi/cxgb3i/cxgb3i_init.c +0 -0
index 042d9bc..8c9285f 100644

drivers/scsi/cxgb3i/cxgb3i_init.c static struct cxgb3_client t3c_client = { · line 46

Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c +1 -6
@@ -43,12 +43,7 @@ static struct cxgb3_client t3c_client = {
  */
 static void open_s3_dev(struct t3cdev *t3dev)
 {
-	static int vers_printed;
-
-	if (!vers_printed) {
-		printk(KERN_INFO "%s", version);
-		vers_printed = 1;
-	}
+	printk_once(KERN_INFO "%s", version);

There's really no point to this beyond code churn. Both patterns are correct uses so conversion buys us nothing.

James

#28 lore raw

Re: [PATCH 12/14] scsi: use printk_once

Quoted 11 lines

drivers/scsi/cxgb3i/cxgb3i_init.c static struct cxgb3_client t3c_client = { · line 46

Quoted 8 lines
drivers/scsi/cxgb3i/cxgb3i_init.c +1 -6
-	static int vers_printed;
-
-	if (!vers_printed) {
-		printk(KERN_INFO "%s", version);
-		vers_printed = 1;
-	}
+	printk_once(KERN_INFO "%s", version);

There's really no point to this beyond code churn. Both patterns are correct uses so conversion buys us nothing.

It's a pretty small gain but I do think 6 lines -> 1 line does have value.

- R.

maintainer
#29 lore raw

Re: [PATCH 12/14] scsi: use printk_once

Quoted 11 lines · Roland Dreier
Quoted 10 lines

drivers/scsi/cxgb3i/cxgb3i_init.c static struct cxgb3_client t3c_client = { · line 46

Quoted 7 lines
drivers/scsi/cxgb3i/cxgb3i_init.c +1 -6
-	static int vers_printed;
-
-	if (!vers_printed) {
-		printk(KERN_INFO "%s", version);
-		vers_printed = 1;
-	}
+	printk_once(KERN_INFO "%s", version);

There's really no point to this beyond code churn. Both patterns are correct uses so conversion buys us nothing.

Quoted 1 line

It's a pretty small gain but I do think 6 lines -> 1 line does have value.

Not at the expense of churning the code base of marginal drivers.

I'm not entirely convinced this is a good pattern to begin with. If you add too many patterns you're effectively developing an overly complex development language and rule set. Even if I go with this on the basis of readability (as you say, one line for six), then I still don't think we should churn the code base to convert correct open coding to it; we should just use it ongoing.

James

#30 lore raw

Re: [PATCH 12/14] scsi: use printk_once

In reply to James Bottomley
Quoted 17 lines · James Bottomley

drivers/scsi/cxgb3i/cxgb3i_init.c static struct cxgb3_client t3c_client = { · line 46

Quoted 13 lines · Marcin Slusarz
drivers/scsi/cxgb3i/cxgb3i_init.c +1 -6
@@ -43,12 +43,7 @@ static struct cxgb3_client t3c_client = {
  */
 static void open_s3_dev(struct t3cdev *t3dev)
 {
-	static int vers_printed;
-
-	if (!vers_printed) {
-		printk(KERN_INFO "%s", version);
-		vers_printed = 1;
-	}
+	printk_once(KERN_INFO "%s", version);

There's really no point to this beyond code churn. Both patterns are correct uses so conversion buys us nothing.

Standards are for hacks. Stasis is the best policy. Using patterns isn't worth the electron movement. Code shortening and readability? Humbug.

#31 lore raw

PATCH 13/14 vsprintf: use WARN_ON_ONCE

In reply to Marcin Slusarz
---
 lib/vsprintf.c |   14 ++------------
 1 files changed, 2 insertions(+), 12 deletions(-)
lib/vsprintf.c +2 -12
index 756ccaf..a63bb18 100644
@@ -983,13 +983,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 
 	/* Reject out-of-range values early.  Large positive sizes are
 	   used for unknown buffer sizes. */
-	if (unlikely((int) size < 0)) {
-		/* There can be only one.. */
-		static char warn = 1;
-		WARN_ON(warn);
-		warn = 0;
+	if (WARN_ON_ONCE((int) size < 0))
 		return 0;
-	}
 
 	str = buf;
 	end = buf + size;
@@ -1439,13 +1434,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
 
 	struct printf_spec spec = {0};
 
-	if (unlikely((int) size < 0)) {
-		/* There can be only one.. */
-		static char warn = 1;
-		WARN_ON(warn);
-		warn = 0;
+	if (WARN_ON_ONCE((int) size < 0))
 		return 0;
-	}
 
 	str = buf;
 	end = buf + size;
Signature · 1 line
1.6.3.3
#32 lore raw

PATCH 14/14 net: use printk_once

In reply to Marcin Slusarz
---
 net/ax25/af_ax25.c        |    6 +-----
 net/dsa/dsa.c             |    4 +---
 net/ipv4/raw.c            |    6 ++----
 net/netfilter/xt_recent.c |   10 +++-------
 net/socket.c              |    8 ++------
 5 files changed, 9 insertions(+), 25 deletions(-)
net/ax25/af_ax25.c +1 -5
index da0f64f..39c895b 100644
@@ -1792,12 +1792,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 
 		/* old structure? */
 		if (cmd == SIOCAX25GETINFOOLD) {
-			static int warned = 0;
-			if (!warned) {
-				printk(KERN_INFO "%s uses old SIOCAX25GETINFO\n",
+			printk_once(KERN_INFO "%s uses old SIOCAX25GETINFO\n",
 					current->comm);
-				warned=1;
-			}
 
 			if (copy_to_user(argp, &ax25_info, sizeof(struct ax25_info_struct_deprecated))) {
 				res = -EFAULT;
net/dsa/dsa.c +1 -3
index 71489f6..ecd2dfb 100644
@@ -302,14 +302,12 @@ static struct net_device *dev_to_net_device(struct device *dev)
 
 static int dsa_probe(struct platform_device *pdev)
 {
-	static int dsa_version_printed;
 	struct dsa_platform_data *pd = pdev->dev.platform_data;
 	struct net_device *dev;
 	struct dsa_switch_tree *dst;
 	int i;
 
-	if (!dsa_version_printed++)
-		printk(KERN_NOTICE "Distributed Switch Architecture "
+	printk_once(KERN_NOTICE "Distributed Switch Architecture "
 			"driver version %s\n", dsa_driver_version);
 
 	if (pd == NULL || pd->netdev == NULL)
net/ipv4/raw.c +2 -4
index 2979f14..f919925 100644
@@ -470,10 +470,8 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 		if (msg->msg_namelen < sizeof(*usin))
 			goto out;
 		if (usin->sin_family != AF_INET) {
-			static int complained;
-			if (!complained++)
-				printk(KERN_INFO "%s forgot to set AF_INET in "
-						 "raw sendmsg. Fix it!\n",
+			printk_once(KERN_INFO "%s forgot to set AF_INET in "
+						"raw sendmsg. Fix it!\n",
 						 current->comm);
 			err = -EAFNOSUPPORT;
 			if (usin->sin_family)
net/netfilter/xt_recent.c +3 -7
index eb0ceb8..d60d317 100644
@@ -456,13 +456,9 @@ static int recent_seq_open(struct inode *inode, struct file *file)
 #ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
 static int recent_old_seq_open(struct inode *inode, struct file *filp)
 {
-	static bool warned_of_old;
-
-	if (unlikely(!warned_of_old)) {
-		printk(KERN_INFO KBUILD_MODNAME ": Use of /proc/net/ipt_recent"
-		       " is deprecated; use /proc/net/xt_recent.\n");
-		warned_of_old = true;
-	}
+	printk_once(KERN_INFO KBUILD_MODNAME ": "
+		"Use of /proc/net/ipt_recent is deprecated; "
+		"use /proc/net/xt_recent.\n");
 	return recent_seq_open(inode, filp);
 }
 
net/socket.c +2 -6
index 791d71a..1d07f69 100644
@@ -1161,12 +1161,8 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
 	   deadlock in module load.
 	 */
 	if (family == PF_INET && type == SOCK_PACKET) {
-		static int warned;
-		if (!warned) {
-			warned = 1;
-			printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n",
-			       current->comm);
-		}
+		printk_once(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n",
+			    current->comm);
 		family = PF_PACKET;
 	}
 
Signature · 1 line
1.6.3.3
#34 lore raw
In reply to Marcin Slusarz

Perhaps this could be combined with

pr_<level> once?

Changed printk_once to use bool instead of int, with default set to false not 1. This reduces data and produces slightly smaller object code.

Changed printk_once macro definitions to (fmt, ...) to match other printk/pr_<level> definitions.

---
 include/linux/kernel.h |   57 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 6 deletions(-)
include/linux/kernel.h +51 -6
index 883cd44..343e505 100644
@@ -246,12 +246,12 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
 /*
  * Print a one-time message (analogous to WARN_ONCE() et al):
  */
-#define printk_once(x...) ({			\
-	static int __print_once = 1;		\
+#define printk_once(fmt, ...) ({		\
+	static bool __print_once;		\
 						\
-	if (__print_once) {			\
-		__print_once = 0;		\
-		printk(x);			\
+	if (!__print_once) {			\
+		__print_once = true;		\
+		printk(fmt, ##__VA_ARGS__);	\
 	}					\
 })
 
@@ -269,7 +269,7 @@ static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
 		{ return false; }
 
 /* No effect, but we still get type checking even in the !PRINTK case: */
-#define printk_once(x...) printk(x)
+#define printk_once(fmt, ...) printk(fmt, ##__VA_ARGS__)
 
 static inline void log_buf_kexec_setup(void)
 {
@@ -400,6 +400,51 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
 #endif
 
+/* pr_<level>_once variants */
+
+#define pr_emerg_once(fmt, ...) \
+	printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_alert_once(fmt, ...) \
+	printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_crit_once(fmt, ...) \
+	printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_err_once(fmt, ...) \
+	printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning_once(fmt, ...) \
+	printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_notice_once(fmt, ...) \
+	printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info_once(fmt, ...) \
+	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+/* No pr_cont_once, use a local guard instead */
+
+/* pr_devel_once() should produce zero code unless DEBUG is defined */
+#ifdef DEBUG
+#define pr_devel_once(fmt, ...) \
+	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#else
+#define pr_devel_once(fmt, ...) \
+	({ if (0) printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
+#endif
+
+/* If you are writing a driver, please use dev_dbg instead */
+#if defined(DEBUG)
+#define pr_debug_once(fmt, ...) \
+	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#elif defined(CONFIG_DYNAMIC_DEBUG)
+/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
+#define pr_debug_once(fmt, ...) ({			\
+	static bool __print_once;			\
+	if (!__print_once) {				\
+		__print_once = true;			\
+		dynamic_pr_debug(fmt, ##__VA_ARGS__);	\
+	}						\
+})
+#else
+#define pr_debug_once(fmt, ...) \
+	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
+#endif
+
 /*
  * General tracing related utility functions - trace_printk(),
  * tracing_on/tracing_off and tracing_start()/tracing_stop
Signature · 1 line
1.6.3.1.10.g659a0.dirty