Skip to contentSkip to conversation

genirq: Consistently use '%u' format specifier for irq

PATCH Applied Andy Shevchenko 2 participants 2 messages May 9, 2025 – May 13, 2025 IRQ

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 genirq: Consistently use '%u' format specifier for irq

There are three cases in the genirq code when the irq, as an unsigned integer variable, is converted to text representation by sprintf(). In two cases it uses '%d' specifier which is for signed values. While it's not a problem right now, potentially it might be in the future in case too big (> INT_MAX) number will appear there.

Consistently use '%u' format specifier for irq which is declared as unsigned int in all these cases.

---
 kernel/irq/debugfs.c | 2 +-
 kernel/irq/proc.c    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/irq/debugfs.c +1 -1
index 9004a17b93a2..3d6a5b3cfaf3 100644
@@ -230,7 +230,7 @@ void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc)
 	if (!irq_dir || !desc || desc->debugfs_file)
 		return;
 
-	sprintf(name, "%d", irq);
+	sprintf(name, "%u", irq);
 	desc->debugfs_file = debugfs_create_file(name, 0644, irq_dir, desc,
 						 &dfs_irq_ops);
 }
kernel/irq/proc.c +2 -2
index 94eba9a425c4..29c2404e743b 100644
@@ -309,7 +309,7 @@ static bool name_unique(unsigned int irq, struct irqaction *new_action)
 
 void register_handler_proc(unsigned int irq, struct irqaction *action)
 {
-	char name [MAX_NAMELEN];
+	char name[MAX_NAMELEN];
 	struct irq_desc *desc = irq_to_desc(irq);
 
 	if (!desc->dir || action->dir || !action->name || !name_unique(irq, action))
@@ -345,7 +345,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
 		return;
 
 	/* create /proc/irq/1234 */
-	sprintf(name, "%d", irq);
+	sprintf(name, "%u", irq);
 	desc->dir = proc_mkdir(name, root_irq_dir);
 	if (!desc->dir)
 		return;
Signature · 1 line
2.47.2
#1 lore raw

[tip: irq/core] genirq: Consistently use '%u' format specifier for unsigned int variables

The following commit has been merged into the irq/core branch of tip:

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     47af06c9d31fe558493de4e04f9a07847dc4992f
Gitweb:        https://git.kernel.org/tip/47af06c9d31fe558493de4e04f9a07847dc4992f
Author:        Andy Shevchenko <[email protected]>
AuthorDate:    Fri, 09 May 2025 18:46:42 +03:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 13 May 2025 09:43:32 +02:00

genirq: Consistently use '%u' format specifier for unsigned int variables

There are three cases in the genirq code when the irq, as an unsigned integer variable, is converted to text representation by sprintf(). In two cases it uses '%d' specifier which is for signed values. While it's not a problem right now, potentially it might be in the future in case too big (> INT_MAX) number will appear there.

Consistently use '%u' format specifier for @irq which is declared as unsigned int in all these cases.

---
 kernel/irq/debugfs.c | 2 +-
 kernel/irq/proc.c    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/irq/debugfs.c +1 -1
index 9004a17..3d6a5b3 100644
@@ -230,7 +230,7 @@ void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc)
 	if (!irq_dir || !desc || desc->debugfs_file)
 		return;
 
-	sprintf(name, "%d", irq);
+	sprintf(name, "%u", irq);
 	desc->debugfs_file = debugfs_create_file(name, 0644, irq_dir, desc,
 						 &dfs_irq_ops);
 }
kernel/irq/proc.c +2 -2
index 94eba9a..29c2404 100644
@@ -309,7 +309,7 @@ static bool name_unique(unsigned int irq, struct irqaction *new_action)
 
 void register_handler_proc(unsigned int irq, struct irqaction *action)
 {
-	char name [MAX_NAMELEN];
+	char name[MAX_NAMELEN];
 	struct irq_desc *desc = irq_to_desc(irq);
 
 	if (!desc->dir || action->dir || !action->name || !name_unique(irq, action))
@@ -345,7 +345,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
 		return;
 
 	/* create /proc/irq/1234 */
-	sprintf(name, "%d", irq);
+	sprintf(name, "%u", irq);
 	desc->dir = proc_mkdir(name, root_irq_dir);
 	if (!desc->dir)
 		return;