More ppc64 nvram code cleanup
cover More ppc64 nvram code cleanup
This series contains some fixups to Ben Herrenschmidt's Aug. 2 patch set, "[RFC] Clean up ppc64 nvram code" --
http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-August/084601.html
These patches apply atop Ben's 11-patch series.
---
Jim Keniston (4):
Handle partition names >= 12 chars
Fix NVRAM partition list setup
Fix nvram_create_partition() arg order
Fix powerpc nvram init order
arch/powerpc/kernel/nvram_64.c | 31 +++++++++++-------------------- arch/powerpc/platforms/pseries/nvram.c | 8 ++++---- 2 files changed, 15 insertions(+), 24 deletions(-)
--
Jim Keniston
IBM Linux Technology Center
Beaverton, OR
PATCH 1/4 Fix powerpc nvram init order
Don't run pseries_nvram_init_log_partition() until after the partition list has been initialized. Fixes a boot-time crash.
---
arch/powerpc/platforms/pseries/nvram.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/platforms/pseries/nvram.c +1 -1
@@ -318,7 +318,7 @@ static int __init pseries_nvram_init_log_partition(void)return 0 ; } -machine_arch_initcall (pseries, pseries_nvram_init_log_partition); +machine_late_initcall (pseries, pseries_nvram_init_log_partition);int __init pSeries_nvram_init (void ) {
PATCH 2/4 Fix nvram_create_partition() arg order
In reply to Jim KenistonUse the correct arg order when calling nvram_create_partition().
---
arch/powerpc/platforms/pseries/nvram.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pseries/nvram.c +3 -3
@@ -292,7 +292,7 @@ static int __init pseries_nvram_init_log_partition(void)/* Create one if we didn't find */ if (!p) { p =nvram_create_partition (NVRAM_LOG_PART_NAME ,NVRAM_SIG_OS , -NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); +NVRAM_MAX_REQ ,NVRAM_MIN_REQ );/* No room for it, try to get rid of any OS partition * and try again */
@@ -301,8 +301,8 @@ static int __init pseries_nvram_init_log_partition(void) " partition, deleting all OS partitions...");nvram_remove_partition (NULL ,NVRAM_SIG_OS ); p =nvram_create_partition (NVRAM_LOG_PART_NAME , -NVRAM_SIG_OS ,NVRAM_MIN_REQ , -NVRAM_MAX_REQ ); +NVRAM_SIG_OS ,NVRAM_MAX_REQ , +NVRAM_MIN_REQ ); } }
PATCH 3/4 Fix NVRAM partition list setup
In reply to Jim KenistonSimplify creation and use of the NVRAM partition list.
---
arch/powerpc/kernel/nvram_64.c | 26 ++++++++------------------ 1 files changed, 8 insertions(+), 18 deletions(-)
arch/powerpc/kernel/nvram_64.c +8 -18
@@ -51,7 +51,7 @@ struct nvram_partition {unsigned int index; }; -static struct nvram_partition * nvram_part; +static LIST_HEAD (nvram_partitions);static loff_t dev_nvram_llseek (struct file *file,loff_t offset,int origin) {
@@ -196,13 +196,11 @@ static struct miscdevice nvram_dev = {#ifdef DEBUG_NVRAM static void __init nvram_print_partitions (char * label) { -struct list_head * p;struct nvram_partition * tmp_part;printk (KERN_WARNING "--------%s---------\n" , label);printk (KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n" ); -list_for_each (p, &nvram_part->partition) { - tmp_part = list_entry(p, struct nvram_partition, partition); +list_for_each_entry (tmp_part, &nvram_partitions, partition) { printk(KERN_WARNING "%4d \t%02x\t%02x\t%d\t%s\n", tmp_part->index, tmp_part->header.signature, tmp_part->header.checksum, tmp_part->header.length,
@@ -250,7 +248,7 @@ int __init nvram_remove_partition(const char *name, int sig)struct nvram_partition *part, *prev, *tmp;int rc; -list_for_each_entry (part, &nvram_part->partition, partition) { +list_for_each_entry (part, &nvram_partitions, partition) {if (part->header.signature != sig)continue ;if (name &&strncmp (name, part->header.name,12 ))
@@ -269,7 +267,7 @@ int __init nvram_remove_partition(const char *name, int sig)/* Merge contiguous ones */ prev =NULL ; -list_for_each_entry_safe (part, tmp, &nvram_part->partition, partition) { +list_for_each_entry_safe (part, tmp, &nvram_partitions, partition) {if (part->header.signature !=NVRAM_SIG_FREE ) { prev =NULL ;continue ;
@@ -333,7 +331,7 @@ loff_t __init nvram_create_partition(const char *name, int sig,/* Find a free partition that will give us the maximum needed size If can't find one that will give us the minimum size needed */ -list_for_each_entry (part, &nvram_part->partition, partition) { +list_for_each_entry (part, &nvram_partitions, partition) {if (part->header.signature !=NVRAM_SIG_FREE )continue ;
@@ -412,7 +410,7 @@ int nvram_get_partition_size(loff_t data_index) {struct nvram_partition *part; -list_for_each_entry (part, &nvram_part->partition, partition) { +list_for_each_entry (part, &nvram_partitions, partition) {if (part->index +NVRAM_HEADER_LEN == data_index)return (part->header.length -1 ) *NVRAM_BLOCK_LEN ; }
@@ -430,7 +428,7 @@ loff_t nvram_find_partition(const char *name, int sig, int *out_size) {struct nvram_partition *p; -list_for_each_entry (p, &nvram_part->partition, partition) { +list_for_each_entry (p, &nvram_partitions, partition) {if (p->header.signature == sig && (!name || !strncmp (p->header.name, name,12 ))) {if (out_size)
@@ -499,7 +497,7 @@ static int __init nvram_scan_partitions(void)memcpy (&tmp_part->header, &phead,NVRAM_HEADER_LEN ); tmp_part->index = cur_index; -list_add_tail (&tmp_part->partition, &nvram_part->partition); +list_add_tail (&tmp_part->partition, &nvram_partitions); cur_index += phead.length *NVRAM_BLOCK_LEN ; }
@@ -526,14 +524,6 @@ static int __init nvram_init(void)return rc; } -/* initialize our anchor for the nvram partition list */ - nvram_part =kmalloc (sizeof (struct nvram_partition ),GFP_KERNEL ); -if (!nvram_part) { -printk (KERN_ERR "nvram_init: Failed kmalloc\n" ); -return -ENOMEM ; - } -INIT_LIST_HEAD (&nvram_part->partition); -/* Get all the NVRAM partitions */ error =nvram_scan_partitions ();if (error) {
PATCH 4/4 Handle partition names >= 12 chars
In reply to Jim KenistonThe name field in the nvram_header can be < 12 chars, null-terminated, or 12 chars without the null. Handle this safely.
---
arch/powerpc/kernel/nvram_64.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/kernel/nvram_64.c +3 -2
@@ -42,6 +42,7 @@ struct nvram_header {unsigned char signature;unsigned char checksum;unsigned short length; +/* Terminating null required only for names < 12 chars. */ char name[12 ]; };
@@ -201,7 +202,7 @@ static void __init nvram_print_partitions(char * label)printk (KERN_WARNING "--------%s---------\n" , label);printk (KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n" );list_for_each_entry (tmp_part, &nvram_partitions, partition) { -printk (KERN_WARNING "%4d \t%02x\t%02x\t%d\t%s\n" , +printk (KERN_WARNING "%4d \t%02x\t%02x\t%d\t%12s\n" , tmp_part->index, tmp_part->header.signature, tmp_part->header.checksum, tmp_part->header.length, tmp_part->header.name);
@@ -256,7 +257,7 @@ int __init nvram_remove_partition(const char *name, int sig)/* Make partition a free partition */ part->header.signature =NVRAM_SIG_FREE ; -sprintf (part->header.name,"wwwwwwwwwwww" ); +strncpy (part->header.name,"wwwwwwwwwwww" ,12 ); part->header.checksum =nvram_checksum (&part->header); rc =nvram_write_header (part);if (rc <=0 ) {
Quoted 4 lines · Jim Keniston
This series contains some fixups to Ben Herrenschmidt's Aug. 2 patch set, "[RFC] Clean up ppc64 nvram code" --
http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-August/084601.html
Quoted 8 lines
These patches apply atop Ben's 11-patch series.
---Jim Keniston (4):
Handle partition names >= 12 chars
Fix NVRAM partition list setup
Fixnvram_create_partition()arg order
Fix powerpc nvram init order
I've folded the first two (or a slightly different variant) in my series and applied the two next on top. I'll post that new version of the series to the list after a few tests today and will include it in next in a couple of days, possibly along with your other patches provided they survive my review :-)
Cheers,
Ben.