Skip to contentSkip to conversation

firmware/dmi_scan: Cleanups

PATCH Applied Jean Delvare 3 participants 11 messages Jul 9, 2013 – Jul 10, 2013 Dmi/smbios support

lore
Share & tools
lore
#0 lore raw

cover firmware/dmi_scan: Cleanups

[PATCH 1/3] firmware/dmi_scan: Drop obsolete comment
[PATCH 2/3] firmware/dmi_scan: Fix most checkpatch errors and warnings [PATCH 3/3] firmware/dmi_scan: Constify strings

Signature · 2 lines
Jean Delvare
Suse L3
#1 lore raw

PATCH 1/3 firmware/dmi_scan: Drop obsolete comment

This comment predates the introduction of early_ioremap. Since then the missing calls to dmi_iounmap have been added by Ingo and Yinghai in commits 0d64484f7ea12ca04211b497e94634c3d27cf3fb and 3212bff370c2f22e4987c6679ba485654cefb178. That was over 5 years ago so it is about time to drop this now misleading comment.

Cc Ingo Molnar <[email protected]>
Cc Yinghai Lu <[email protected]>
---
 drivers/firmware/dmi_scan.c |    5 -----
 1 file changed, 5 deletions(-)
drivers/firmware/dmi_scan.c +0 -5
@@ -497,11 +497,6 @@ void __init dmi_scan_machine(void)
 		}
 	}
 	else {
-		/*
-		 * no iounmap() for that ioremap(); it would be a no-op, but
-		 * it's so early in setup that sucker gets confused into doing
-		 * what it shouldn't if we actually call it.
-		 */
 		p = dmi_ioremap(0xF0000, 0x10000);
 		if (p == NULL)
 			goto error;
Signature · 2 lines
Jean Delvare
Suse L3
#2 lore raw

PATCH 2/3 firmware/dmi_scan: Fix most checkpatch errors and warnings

In reply to Jean Delvare

Fix all errors and trivial warnings reported by checkpatch for file drivers/firmware/dmi_scan.c.

---
 drivers/firmware/dmi_scan.c |   47 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)
drivers/firmware/dmi_scan.c +24 -23
@@ -63,7 +63,7 @@ static char * __init dmi_string(const st
 	if (str != NULL)
 		strcpy(str, bp);
 	else
-		printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
+		pr_err("dmi_string: cannot allocate %Zu bytes.\n", len);
 
 	return str;
 }
@@ -140,9 +140,10 @@ int dmi_available;
 /*
  *	Save a DMI string
  */
-static void __init dmi_save_ident(const struct dmi_header *dm, int slot, int string)
+static void __init dmi_save_ident(const struct dmi_header *dm, int slot,
+		int string)
 {
-	const char *d = (const char*) dm;
+	const char *d = (const char *) dm;
 	char *p;
 
 	if (dmi_ident[slot])
@@ -155,9 +156,10 @@ static void __init dmi_save_ident(const
 	dmi_ident[slot] = p;
 }
 
-static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int index)
+static void __init dmi_save_uuid(const struct dmi_header *dm, int slot,
+		int index)
 {
-	const u8 *d = (u8*) dm + index;
+	const u8 *d = (u8 *) dm + index;
 	char *s;
 	int is_ff = 1, is_00 = 1, i;
 
@@ -188,12 +190,13 @@ static void __init dmi_save_uuid(const s
 	else
 		sprintf(s, "%pUB", d);
 
-        dmi_ident[slot] = s;
+	dmi_ident[slot] = s;
 }
 
-static void __init dmi_save_type(const struct dmi_header *dm, int slot, int index)
+static void __init dmi_save_type(const struct dmi_header *dm, int slot,
+		int index)
 {
-	const u8 *d = (u8*) dm + index;
+	const u8 *d = (u8 *) dm + index;
 	char *s;
 
 	if (dmi_ident[slot])
@@ -217,7 +220,7 @@ static void __init dmi_save_one_device(i
 
 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
 	if (!dev) {
-		printk(KERN_ERR "dmi_save_one_device: out of memory.\n");
+		pr_err("dmi_save_one_device: out of memory.\n");
 		return;
 	}
 
@@ -256,8 +259,7 @@ static void __init dmi_save_oem_strings_
 
 		dev = dmi_alloc(sizeof(*dev));
 		if (!dev) {
-			printk(KERN_ERR
-			   "dmi_save_oem_strings_devices: out of memory.\n");
+			pr_err("dmi_save_oem_strings_devices: out of memory.\n");
 			break;
 		}
 
@@ -272,11 +274,11 @@ static void __init dmi_save_oem_strings_
 static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
 {
 	struct dmi_device *dev;
-	void * data;
+	void *data;
 
 	data = dmi_alloc(dm->length);
 	if (data == NULL) {
-		printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
+		pr_err("dmi_save_ipmi_device: out of memory.\n");
 		return;
 	}
 
@@ -284,7 +286,7 @@ static void __init dmi_save_ipmi_device(
 
 	dev = dmi_alloc(sizeof(*dev));
 	if (!dev) {
-		printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
+		pr_err("dmi_save_ipmi_device: out of memory.\n");
 		return;
 	}
 
@@ -302,7 +304,7 @@ static void __init dmi_save_dev_onboard(
 
 	onboard_dev = dmi_alloc(sizeof(*onboard_dev) + strlen(name) + 1);
 	if (!onboard_dev) {
-		printk(KERN_ERR "dmi_save_dev_onboard: out of memory.\n");
+		pr_err("dmi_save_dev_onboard: out of memory.\n");
 		return;
 	}
 	onboard_dev->instance = instance;
@@ -320,7 +322,7 @@ static void __init dmi_save_dev_onboard(
 
 static void __init dmi_save_extended_devices(const struct dmi_header *dm)
 {
-	const u8 *d = (u8*) dm + 5;
+	const u8 *d = (u8 *) dm + 5;
 
 	/* Skip disabled device */
 	if ((*d & 0x80) == 0)
@@ -338,7 +340,7 @@ static void __init dmi_save_extended_dev
  */
 static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
 {
-	switch(dm->type) {
+	switch (dm->type) {
 	case 0:		/* BIOS Information */
 		dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
 		dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
@@ -495,8 +497,7 @@ void __init dmi_scan_machine(void)
 			dmi_available = 1;
 			goto out;
 		}
-	}
-	else {
+	} else {
 		p = dmi_ioremap(0xF0000, 0x10000);
 		if (p == NULL)
 			goto error;
@@ -514,7 +515,7 @@ void __init dmi_scan_machine(void)
 		dmi_iounmap(p, 0x10000);
 	}
  error:
-	printk(KERN_INFO "DMI not present or invalid.\n");
+	pr_info("DMI not present or invalid.\n");
  out:
 	dmi_initialized = 1;
 }
@@ -650,7 +651,7 @@ int dmi_name_in_serial(const char *str)
 
 /**
  *	dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
- *	@str: 	Case sensitive Name
+ *	@str: Case sensitive Name
  */
 int dmi_name_in_vendors(const char *str)
 {
@@ -677,13 +678,13 @@ EXPORT_SYMBOL(dmi_name_in_vendors);
  *	A new search is initiated by passing %NULL as the @from argument.
  *	If @from is not %NULL, searches continue from next device.
  */
-const struct dmi_device * dmi_find_device(int type, const char *name,
+const struct dmi_device *dmi_find_device(int type, const char *name,
 				    const struct dmi_device *from)
 {
 	const struct list_head *head = from ? &from->list : &dmi_devices;
 	struct list_head *d;
 
-	for(d = head->next; d != &dmi_devices; d = d->next) {
+	for (d = head->next; d != &dmi_devices; d = d->next) {
 		const struct dmi_device *dev =
 			list_entry(d, struct dmi_device, list);
 
Signature · 2 lines
Jean Delvare
Suse L3
#3 lore raw

Re: [PATCH 2/3] firmware/dmi_scan: Fix most checkpatch errors and warnings

Quoted 2 lines · Jean Delvare

Fix all errors and trivial warnings reported by checkpatch for file drivers/firmware/dmi_scan.c.

trivia:

drivers/firmware/dmi_scan.c static char * __init dmi_string(const st · line 66

Quoted 7 lines

+++ linux-3.11-rc0/drivers/firmware/dmi_scan.c 2013-07-09 16:08:13.979592957 +0200

drivers/firmware/dmi_scan.c +1 -1
@@ -63,7 +63,7 @@ static char * __init dmi_string(const st
 	if (str != NULL)
 		strcpy(str, bp);
 	else
-		printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
+		pr_err("dmi_string: cannot allocate %Zu bytes.\n", len);

If the function name is used in every printk, it might be better to add

#define pr_fmt(fmt) "%s: " fmt, __func__

before any #include

If not, then I suggest removing the embedded function names and writing these as

		pr_err("%s: etc...", __func__, etc...);

This eliminates any possible function name mismatch.

drivers/firmware/dmi_scan.c static void __init dmi_save_one_device(i · line 223

Quoted 6 lines
drivers/firmware/dmi_scan.c +1 -1
@@ -217,7 +220,7 @@ static void __init dmi_save_one_device(i
 
 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
 	if (!dev) {
-		printk(KERN_ERR "dmi_save_one_device: out of memory.\n");
+		pr_err("dmi_save_one_device: out of memory.\n");

OOM messages generally aren't useful.

dmi_alloc is either a trivial front-end to kmalloc, and kmalloc already does a dump_stack() when OOM, or for x86, dmi_alloc uses extend_brk which BUGs when unsuccessful.

x86/ia64 do have a slight mismatch in dmi_alloc as x86 does a memset(0), and ia64 just does kmalloc.

#4 lore raw

ia64: dmi.h: Make dmi_alloc use kzalloc

x86/ia64 have a slight mismatch in dmi_alloc as
x86 does a memset(0), and ia64 just does kmalloc.

Make the ia64 dmi_alloc match the x86 style.

---
 arch/ia64/include/asm/dmi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/include/asm/dmi.h +1 -1
index 1ed4c8f..185d3d1 100644
@@ -7,6 +7,6 @@
 /* Use normal IO mappings for DMI */
 #define dmi_ioremap ioremap
 #define dmi_iounmap(x,l) iounmap(x)
-#define dmi_alloc(l) kmalloc(l, GFP_ATOMIC)
+#define dmi_alloc(l) kzalloc(l, GFP_ATOMIC)
 
 #endif
Applied
#5 lore raw

Re: ia64: dmi.h: Make dmi_alloc use kzalloc

Quoted 6 lines · Joe Perches

x86/ia64 have a slight mismatch in dmi_alloc as
x86 does a memset(0), and ia64 just does kmalloc.

Make the ia64 dmi_alloc match the x86 style.

Applied. Thanks Joe.

-Tony

#6 lore raw

Re: [PATCH 2/3] firmware/dmi_scan: Fix most checkpatch errors and warnings

In reply to Joe Perches

Hi Joe,

Quoted 17 lines · Joe Perches
Quoted 2 lines · Jean Delvare

Fix all errors and trivial warnings reported by checkpatch for file drivers/firmware/dmi_scan.c.

trivia:

drivers/firmware/dmi_scan.c static char * __init dmi_string(const st · line 66

Quoted 7 lines

+++ linux-3.11-rc0/drivers/firmware/dmi_scan.c 2013-07-09 16:08:13.979592957 +0200

drivers/firmware/dmi_scan.c +1 -1
@@ -63,7 +63,7 @@ static char * __init dmi_string(const st
 	if (str != NULL)
 		strcpy(str, bp);
 	else
-		printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
+		pr_err("dmi_string: cannot allocate %Zu bytes.\n", len);

If the function name is used in every printk, it might be better to add

Quoted 3 lines

#define pr_fmt(fmt) "%s: " fmt, __func__

before any #include

No, only error messages include the function name, debug and info messages do not.

Quoted 5 lines

If not, then I suggest removing the embedded function names and writing these as

		pr_err("%s: etc...", __func__, etc...);

This eliminates any possible function name mismatch.

I had considered this too, but stepped back after finding out that this change would increase the binary size. It's hard to sell such a change then when it's only fixing a theoretical problem.

Quoted 9 lines

drivers/firmware/dmi_scan.c static void __init dmi_save_one_device(i · line 223

Quoted 6 lines
drivers/firmware/dmi_scan.c +1 -1
@@ -217,7 +220,7 @@ static void __init dmi_save_one_device(i
 
 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
 	if (!dev) {
-		printk(KERN_ERR "dmi_save_one_device: out of memory.\n");
+		pr_err("dmi_save_one_device: out of memory.\n");

OOM messages generally aren't useful.

Quoted 4 lines

dmi_alloc is either a trivial front-end to kmalloc, and kmalloc already does a dump_stack() when OOM, or for x86, dmi_alloc uses extend_brk which BUGs when unsuccessful.

Fair enough, I'll send a separate patch for this in a minute.

Signature · 2 lines
Jean Delvare
Suse L3
#7 lore raw

Re: [PATCH 2/3] firmware/dmi_scan: Fix most checkpatch errors and warnings

Quoted 1 line · Jean Delvare

Hi Joe,

hi Jean.

Quoted 2 lines · Joe Perches
Quoted 1 line · Jean Delvare

[]

Quoted 3 lines
Quoted 3 lines

If the function name is used in every printk, it might be better to add
#define pr_fmt(fmt) "%s: " fmt, __func__

[]

Quoted 7 lines
Quoted 4 lines

If not, then I suggest removing the embedded function names and writing these as

		pr_err("%s: etc...", __func__, etc...);

This eliminates any possible function name mismatch.

I had considered this too, but stepped back after finding out that this change would increase the binary size. It's hard to sell such a change then when it's only fixing a theoretical problem.

No worries.

Another tiny consideration is that __func__ is both generally not particularly useful and could in the future be consolidated via vsprintf/printk having some extension that uses __builtin_return_address and sprint_symbol_no_offset.

cheers, Joe

#8 lore raw

PATCH 3/3 firmware/dmi_scan: Constify strings

In reply to Jean Delvare

Add const to all DMI string pointers where this is possible. This fixes a checkpatch warning.

---
 drivers/firmware/dmi_scan.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/firmware/dmi_scan.c +5 -5
@@ -14,7 +14,7 @@
  * of and an antecedent to, SMBIOS, which stands for System
  * Management BIOS.  See further: http://www.dmtf.org/standards
  */
-static char dmi_empty_string[] = "        ";
+static const char dmi_empty_string[] = "        ";
 
 static u16 __initdata dmi_ver;
 /*
@@ -49,7 +49,7 @@ static const char * __init dmi_string_no
 	return "";
 }
 
-static char * __init dmi_string(const struct dmi_header *dm, u8 s)
+static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
 {
 	const char *bp = dmi_string_nosave(dm, s);
 	char *str;
@@ -133,7 +133,7 @@ static int __init dmi_checksum(const u8
 	return sum == 0;
 }
 
-static char *dmi_ident[DMI_STRING_MAX];
+static const char *dmi_ident[DMI_STRING_MAX];
 static LIST_HEAD(dmi_devices);
 int dmi_available;
 
@@ -144,7 +144,7 @@ static void __init dmi_save_ident(const
 		int string)
 {
 	const char *d = (const char *) dm;
-	char *p;
+	const char *p;
 
 	if (dmi_ident[slot])
 		return;
@@ -252,7 +252,7 @@ static void __init dmi_save_oem_strings_
 	struct dmi_device *dev;
 
 	for (i = 1; i <= count; i++) {
-		char *devname = dmi_string(dm, i);
+		const char *devname = dmi_string(dm, i);
 
 		if (devname == dmi_empty_string)
 			continue;
Signature · 2 lines
Jean Delvare
Suse L3
#9 lore raw

Re: [PATCH 3/3] firmware/dmi_scan: Constify strings

Quoted 2 lines · Jean Delvare

Add const to all DMI string pointers where this is possible. This fixes a checkpatch warning.

That's a nice little improvement.

Quoted 1 line

+++ linux-3.10-rc0/drivers/firmware/dmi_scan.c 2013-05-04 11:20:52.808187924 +0200

[]

drivers/firmware/dmi_scan.c static void __init dmi_save_oem_strings_ · line 257

Quoted 8 lines
drivers/firmware/dmi_scan.c +1 -1
@@ -252,7 +252,7 @@ static void __init dmi_save_oem_strings_
 	struct dmi_device *dev;
 
 	for (i = 1; i <= count; i++) {
-		char *devname = dmi_string(dm, i);
+		const char *devname = dmi_string(dm, i);
 
 		if (devname == dmi_empty_string)

btw: that last test sure looks like it would be
better written as
if (strcmp(devname, dmi_empty_string) == 0)

#10 lore raw

Re: [PATCH 3/3] firmware/dmi_scan: Constify strings

Hi Joe,

Quoted 5 lines · Joe Perches
Quoted 2 lines · Jean Delvare

Add const to all DMI string pointers where this is possible. This fixes a checkpatch warning.

That's a nice little improvement.

Thanks.

Quoted 9 lines
Quoted 1 line

+++ linux-3.10-rc0/drivers/firmware/dmi_scan.c 2013-05-04 11:20:52.808187924 +0200

[]

Quoted 7 lines
drivers/firmware/dmi_scan.c +1 -1
@@ -252,7 +252,7 @@ static void __init dmi_save_oem_strings_
 	struct dmi_device *dev;
 
 	for (i = 1; i <= count; i++) {
-		char *devname = dmi_string(dm, i);
+		const char *devname = dmi_string(dm, i);
 
Quoted 6 lines

drivers/firmware/dmi_scan.c static void __init dmi_save_oem_strings_ · line 257

Quoted 1 line
drivers/firmware/dmi_scan.c +0 -0
 		if (devname == dmi_empty_string)

btw: that last test sure looks like it would be
better written as
if (strcmp(devname, dmi_empty_string) == 0)

No, it does not. If you look at the rest of the code, the comparison makes sense as is.

Signature · 2 lines
Jean Delvare
Suse L3