Skip to contentSkip to conversation

mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

PATCH In review zhong jiang 3 participants 12 messages Oct 30, 2019 – Nov 1, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

WARN_ONCE is more clear and simpler. Just replace it.

---
 arch/x86/mm/ioremap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/mm/ioremap.c +2 -3
index a39dcdb..3b74599 100644
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);
 		return NULL;
 	}
 
Signature · 1 line
1.7.12.4
maintainer
#1 lore raw
Quoted 12 lines · zhong jiang

WARN_ONCE is more clear and simpler. Just replace it.

---
 arch/x86/mm/ioremap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/mm/ioremap.c +0 -0
index a39dcdb..3b74599 100644

arch/x86/mm/ioremap.c static void __ioremap_check_mem(resource_size_t addr, unsigned long size, · line 176

Quoted 8 lines
arch/x86/mm/ioremap.c +2 -3
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);

Does

	WARN_ONCE(!phys_addr_valid(phys_addr),
		  "ioremap: invalid physical address %llx\n",
		  (unsigned long long)phys_addr);

work too?

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#2 lore raw
Quoted 22 lines · Borislav Petkov
Quoted 12 lines · zhong jiang

WARN_ONCE is more clear and simpler. Just replace it.

---
 arch/x86/mm/ioremap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/mm/ioremap.c +0 -0
index a39dcdb..3b74599 100644

arch/x86/mm/ioremap.c static void __ioremap_check_mem(resource_size_t addr, unsigned long size, · line 176

Quoted 8 lines
arch/x86/mm/ioremap.c +2 -3
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);

Does

Quoted 6 lines
	WARN_ONCE(!phys_addr_valid(phys_addr),
		  "ioremap: invalid physical address %llx\n",
		  (unsigned long long)phys_addr);

work too?

Thanks, That is better. Will repost.

#3 lore raw
Quoted 3 lines · zhong jiang
Quoted 2 lines · Borislav Petkov
Quoted 1 line · zhong jiang

WARN_ONCE is more clear and simpler. Just replace it.

[]

Quoted 1 line
Quoted 1 line

arch/x86/mm/ioremap.c

Quoted 1 line
arch/x86/mm/ioremap.c +0 -0

[]

Quoted 14 lines
Quoted 14 lines

arch/x86/mm/ioremap.c static void __ioremap_check_mem(resource_size_t addr, unsigned long size, · line 176

Quoted 9 lines
arch/x86/mm/ioremap.c +2 -3
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);

Does

	WARN_ONCE(!phys_addr_valid(phys_addr),
		  "ioremap: invalid physical address %llx\n",
		  (unsigned long long)phys_addr);
Quoted 3 lines
Quoted 2 lines

work too?

Thanks, That is better. Will repost.

Perhaps this is not good patch concept as now each invalid physical address will not be emitted.

Before:
each invalid physical address printed
one stack dump

After:
one stck dump with first invalid physical address.

#4 lore raw
Quoted 27 lines · Joe Perches
Quoted 3 lines · zhong jiang
Quoted 2 lines · Borislav Petkov
Quoted 1 line · zhong jiang

WARN_ONCE is more clear and simpler. Just replace it.

[]

Quoted 1 line
Quoted 1 line

arch/x86/mm/ioremap.c

Quoted 1 line
arch/x86/mm/ioremap.c +0 -0

[]

Quoted 14 lines
Quoted 14 lines

arch/x86/mm/ioremap.c static void __ioremap_check_mem(resource_size_t addr, unsigned long size, · line 176

Quoted 9 lines
arch/x86/mm/ioremap.c +2 -3
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);

Does

	WARN_ONCE(!phys_addr_valid(phys_addr),
		  "ioremap: invalid physical address %llx\n",
		  (unsigned long long)phys_addr);
Quoted 3 lines
Quoted 2 lines

work too?

Thanks, That is better. Will repost.

Perhaps this is not good patch concept as now each invalid physical address will not be emitted.

Quoted 7 lines

Before:
each invalid physical address printed
one stack dump

After:
one stck dump with first invalid physical address.

Yes, I has told that.

How you think my above patch in the mail. Thanks

Quoted 3 lines

.

#5 lore raw
In reply to Joe Perches
Quoted 27 lines · Joe Perches
Quoted 3 lines · zhong jiang
Quoted 2 lines · Borislav Petkov
Quoted 1 line · zhong jiang

WARN_ONCE is more clear and simpler. Just replace it.

[]

Quoted 1 line
Quoted 1 line

arch/x86/mm/ioremap.c

Quoted 1 line
arch/x86/mm/ioremap.c +0 -0

[]

Quoted 14 lines
Quoted 14 lines

arch/x86/mm/ioremap.c static void __ioremap_check_mem(resource_size_t addr, unsigned long size, · line 176

Quoted 9 lines
arch/x86/mm/ioremap.c +2 -3
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);

Does

	WARN_ONCE(!phys_addr_valid(phys_addr),
		  "ioremap: invalid physical address %llx\n",
		  (unsigned long long)phys_addr);
Quoted 3 lines
Quoted 2 lines

work too?

Thanks, That is better. Will repost.

Perhaps this is not good patch concept as now each invalid physical address will not be emitted.

Quoted 7 lines

Before:
each invalid physical address printed
one stack dump

After:
one stck dump with first invalid physical address.

I misunderstand your meaning. You're right. My patch change its logical. Thanks for your reminder.

Sincerely,
zhong jiang

Quoted 3 lines

.

#6 lore raw
In reply to Borislav Petkov
Quoted 22 lines · Borislav Petkov
Quoted 12 lines · zhong jiang

WARN_ONCE is more clear and simpler. Just replace it.

---
 arch/x86/mm/ioremap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/mm/ioremap.c +0 -0
index a39dcdb..3b74599 100644

arch/x86/mm/ioremap.c static void __ioremap_check_mem(resource_size_t addr, unsigned long size, · line 176

Quoted 8 lines
arch/x86/mm/ioremap.c +2 -3
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);

Does

Quoted 6 lines
	WARN_ONCE(!phys_addr_valid(phys_addr),
		  "ioremap: invalid physical address %llx\n",
		  (unsigned long long)phys_addr);

work too?

Look at this again, It should not works. Because that will change the logical. if phys_addr_valid is false, we should drop out in time.

WARN_ONCE should be just visible for user not should to handle with address.

Thanks,
zhong jiang

maintainer
#7 lore raw
Quoted 2 lines · zhong jiang

Look at this again, It should not works. Because that will change the logical. if phys_addr_valid is false, we should drop out in time.

That you can do too:

arch/x86/mm/ioremap.c +3 -5
index a39dcdb5ae34..13f44cc064af 100644
@@ -171,12 +171,10 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
 	if (!size || last_addr < phys_addr)
 		return NULL;
 
-	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+	if (WARN_ONCE(!phys_addr_valid(phys_addr),
+	    "ioremap: invalid physical address %llx\n",
+	    (unsigned long long)phys_addr))
 		return NULL;
-	}
 
 	__ioremap_check_mem(phys_addr, size, &io_desc);
 

---

I'm not sure whether we care about printing every invalid address, as Joe points out. Maybe we do... *shrug*

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#8 lore raw
Quoted 13 lines · Borislav Petkov
Quoted 2 lines · zhong jiang

Look at this again, It should not works. Because that will change the logical. if phys_addr_valid is false, we should drop out in time.

That you can do too:

arch/x86/mm/ioremap.c +0 -0
index a39dcdb5ae34..13f44cc064af 100644
@@ -171,12 +171,10 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
 	if (!size || last_addr < phys_addr)
 		return NULL;
 

arch/x86/mm/ioremap.c __ioremap_caller(resource_size_t phys_addr, unsigned long size, · line 178

Quoted 10 lines
arch/x86/mm/ioremap.c +3 -5
-	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+	if (WARN_ONCE(!phys_addr_valid(phys_addr),
+	    "ioremap: invalid physical address %llx\n",
+	    (unsigned long long)phys_addr))
 		return NULL;
-	}
 

Yep, WARN_ONCE alway return true in that case.

Thanks,
zhong jiang

Quoted 7 lines
arch/x86/mm/ioremap.c +0 -1
 	__ioremap_check_mem(phys_addr, size, &io_desc);
 
---

I'm not sure whether we care about printing every invalid address, as Joe points out. Maybe we do... *shrug*

maintainer
#9 lore raw
Quoted 1 line · zhong jiang

Yep, WARN_ONCE alway return true in that case.

Are you sure it does that always?

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#10 lore raw
Quoted 4 lines · Borislav Petkov
Quoted 1 line · zhong jiang

Yep, WARN_ONCE alway return true in that case.

Are you sure it does that always?

WARN_ONCE will alway return true if its condition is true.:-)

maintainer
#11 lore raw
Quoted 1 line · zhong jiang

WARN_ONCE will alway return true if its condition is true.:-)

And if its condition is false?

Lemme save you some time: WARN_ONCE() returns the @condition value so constructs like

	if (WARN_ONCE(condition,...))

are possible. Grep the code for examples.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--