MIPS: BCM47XX: Fix coding style to match kernel standards
Subsystems (2)
Rafał Miłecki
maintainerPATCH 1/3 MIPS: BCM47XX: Fix coding style to match kernel standards
Signed-off-by Rafał Miłecki <[email protected]>
--- arch/mips/bcm47xx/bcm47xx_private.h | 4 ++++ arch/mips/bcm47xx/board.c | 3 +-- arch/mips/bcm47xx/nvram.c | 25 ++++++++++++++----------- arch/mips/bcm47xx/prom.c | 3 +-- arch/mips/bcm47xx/serial.c | 8 ++++---- arch/mips/bcm47xx/setup.c | 12 ++++++------ arch/mips/bcm47xx/sprom.c | 8 ++++---- arch/mips/bcm47xx/time.c | 1 - 8 files changed, 34 insertions(+), 30 deletions(-)
arch/mips/bcm47xx/bcm47xx_private.h +4 -0
@@ -1,6 +1,10 @@#ifndef LINUX_BCM47XX_PRIVATE_H_ #define LINUX_BCM47XX_PRIVATE_H_ +#ifndef pr_fmt +#define pr_fmt (fmt) "bcm47xx: " fmt +#endif +#include <linux/kernel.h> /* prom.c */
arch/mips/bcm47xx/board.c +1 -2
@@ -330,9 +330,8 @@ void __init bcm47xx_board_detect(void) err =bcm47xx_nvram_getenv ("boardtype" , buf,sizeof (buf));/* init of nvram failed, probably too early now */ -if (err == -ENXIO ) { +if (err == -ENXIO )return ; - } board_detected =bcm47xx_board_get_nvram (); bcm47xx_board.board = board_detected->board;
arch/mips/bcm47xx/nvram.c +14 -11
@@ -18,8 +18,10 @@#include <linux/mtd/mtd.h> #include <linux/bcm47xx_nvram.h> -#define NVRAM_MAGIC 0x48534C46/* 'FLSH' */ -#define NVRAM_SPACE 0x8000 +#define NVRAM_MAGIC 0x48534C46/* 'FLSH' */ +#define NVRAM_SPACE 0x8000 +#define NVRAM_MAX_GPIO_ENTRIES 32 +#define NVRAM_MAX_GPIO_VALUE_LEN 30#define FLASH_MIN 0x00020000/* Minimum flash size */
@@ -98,8 +100,8 @@ found:pr_err ("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n" , header->len,NVRAM_SPACE ); - src = (u32 *) header; - dst = (u32 *) nvram_buf; + src = (u32 *)header; + dst = (u32 *)nvram_buf;for (i =0 ; i <sizeof (struct nvram_header ); i +=4 ) *dst++ = *src++;for (; i < header->len && i <NVRAM_SPACE && i < size; i +=4 )
@@ -192,16 +194,16 @@ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)/* Look for name=value and return value */ var = &nvram_buf[sizeof (struct nvram_header )]; end = nvram_buf +sizeof (nvram_buf) -2 ; - end[0 ] = end[1 ] ='\0' ; + end[0 ] ='\0' ; + end[1 ] ='\0' ;for (; *var; var = value +strlen (value) +1 ) { eq =strchr (var,'=' );if (!eq)break ; value = eq +1 ; -if ((eq - var) ==strlen (name) && -strncmp (var, name, (eq - var)) ==0 ) { +if (eq - var ==strlen (name) && +strncmp (var, name, eq - var) ==0 )return snprintf (val, val_len,"%s" , value); - } }return -ENOENT ; }
@@ -210,10 +212,11 @@ EXPORT_SYMBOL(bcm47xx_nvram_getenv);int bcm47xx_nvram_gpio_pin (const char *name) {int i, err; -char nvram_var[10 ]; -char buf[30 ]; +char *nvram_var ="gpioXX" ; +char buf[NVRAM_MAX_GPIO_VALUE_LEN ]; -for (i =0 ; i <32 ; i++) { +/* TODO: Optimize it to don't call getenv so many times */ +for (i =0 ; i <NVRAM_MAX_GPIO_ENTRIES ; i++) { err =snprintf (nvram_var,sizeof (nvram_var),"gpio%i" , i);if (err <=0 )continue ;
arch/mips/bcm47xx/prom.c +1 -2
@@ -35,7 +35,6 @@#include <bcm47xx.h> #include <bcm47xx_board.h> -static char bcm47xx_system_type[20 ] ="Broadcom BCM47XX" ;const char *get_system_type (void )
@@ -83,7 +82,7 @@ static __init void prom_init_mem(void)/* Loop condition may be not enough, off may be over 1 MiB */ if (off + mem >= max) { mem = max; -printk (KERN_DEBUG "assume 128MB RAM\n" ); +pr_debug ("Assume 128MB RAM\n" );break ; }if (!memcmp (prom_init, prom_init + mem,32 ))
arch/mips/bcm47xx/serial.c +4 -4
@@ -36,8 +36,8 @@ static int __init uart8250_init_ssb(void)struct plat_serial8250_port *p = &(uart8250_data[i]);struct ssb_serial_port *ssb_port = &(mcore->serial_ports[i]); - p->mapbase = (unsigned int ) ssb_port->regs; - p->membase = (void *) ssb_port->regs; + p->mapbase = (unsigned int )ssb_port->regs; + p->membase = (void *)ssb_port->regs; p->irq = ssb_port->irq +2 ; p->uartclk = ssb_port->baud_base; p->regshift = ssb_port->reg_shift;
@@ -62,8 +62,8 @@ static int __init uart8250_init_bcma(void)struct bcma_serial_port *bcma_port; bcma_port = &(cc->serial_ports[i]); - p->mapbase = (unsigned int ) bcma_port->regs; - p->membase = (void *) bcma_port->regs; + p->mapbase = (unsigned int )bcma_port->regs; + p->membase = (void *)bcma_port->regs; p->irq = bcma_port->irq; p->uartclk = bcma_port->baud_base; p->regshift = bcma_port->reg_shift;
arch/mips/bcm47xx/setup.c +6 -6
@@ -52,7 +52,7 @@ EXPORT_SYMBOL(bcm47xx_bus_type);static void bcm47xx_machine_restart (char *command) { -printk (KERN_ALERT "Please stand by while rebooting the system...\n" ); +pr_alert ("Please stand by while rebooting the system...\n" );local_irq_disable ();/* Set the watchdog timer to reset immediately */ switch (bcm47xx_bus_type) {
@@ -107,7 +107,7 @@ static int bcm47xx_get_invariants(struct ssb_bus *bus,char buf[20 ];/* Fill boardinfo structure */ -memset (&(iv->boardinfo),0 ,sizeof (struct ssb_boardinfo )); +memset (&iv->boardinfo,0 ,sizeof (struct ssb_boardinfo ));bcm47xx_fill_ssb_boardinfo (&iv->boardinfo,NULL );
@@ -126,7 +126,7 @@ static void __init bcm47xx_register_ssb(void)char buf[100 ];struct ssb_mipscore *mcore; - err =ssb_bus_ssbbus_register (&(bcm47xx_bus.ssb),SSB_ENUM_BASE , + err =ssb_bus_ssbbus_register (&bcm47xx_bus.ssb,SSB_ENUM_BASE , bcm47xx_get_invariants);if (err)panic ("Failed to initialize SSB bus (err %d)" , err);
@@ -136,7 +136,7 @@ static void __init bcm47xx_register_ssb(void)if (strstr (buf,"console=ttyS1" )) {struct ssb_serial_port port; -printk (KERN_DEBUG "Swapping serial ports!\n" ); +pr_debug ("Swapping serial ports!\n" );/* swap serial ports */ memcpy (&port, &mcore->serial_ports[0 ],sizeof (port)); memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
@@ -168,7 +168,7 @@ void __init plat_mem_setup(void)struct cpuinfo_mips *c = ¤t_cpu_data;if ((c->cputype ==CPU_74K ) || (c->cputype ==CPU_1074K )) { -printk (KERN_INFO "bcm47xx: using bcma bus\n" ); +pr_info ("Using bcma bus\n" );#ifdef CONFIG_BCM47XX_BCMA bcm47xx_bus_type =BCM47XX_BUS_TYPE_BCMA ;bcm47xx_sprom_register_fallbacks ();
@@ -179,7 +179,7 @@ void __init plat_mem_setup(void)#endif #endif }else { -printk (KERN_INFO "bcm47xx: using ssb bus\n" ); +pr_info ("Using ssb bus\n" );#ifdef CONFIG_BCM47XX_SSB bcm47xx_bus_type =BCM47XX_BUS_TYPE_SSB ;bcm47xx_sprom_register_fallbacks ();
arch/mips/bcm47xx/sprom.c +4 -4
@@ -780,8 +780,8 @@ void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix,bcm47xx_fill_sprom_path_r4589 (sprom, prefix, fallback);break ;default : -pr_warn ("Unsupported SPROM revision %d detected. Will extract" -" v1\n" , sprom->revision); +pr_warn ("Unsupported SPROM revision %d detected. Will extract v1\n" , + sprom->revision); sprom->revision =1 ;bcm47xx_fill_sprom_r1234589 (sprom, prefix, fallback);bcm47xx_fill_sprom_r12389 (sprom, prefix, fallback);
@@ -828,7 +828,7 @@ static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)bcm47xx_fill_sprom (out, prefix, false);return 0 ; }else { -pr_warn ("bcm47xx: unable to fill SPROM for given bustype.\n" ); +pr_warn ("Unable to fill SPROM for given bustype.\n" );return -EINVAL ; } }
@@ -860,7 +860,7 @@ static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) }return 0 ;default : -pr_warn ("bcm47xx: unable to fill SPROM for given bustype.\n" ); +pr_warn ("Unable to fill SPROM for given bustype.\n" );return -EINVAL ; } }
arch/mips/bcm47xx/time.c +0 -1
@@ -22,7 +22,6 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/init.h> #include <linux/ssb/ssb.h> #include <asm/time.h>
Signature · 1 line
1.8.4.5
Rafał Miłecki
maintainerPATCH 2/3 MIPS: BCM47XX: Use helpers for reading NVRAM content
Also drop some unneeded memset-s.
Signed-off-by Rafał Miłecki <[email protected]>
--- arch/mips/bcm47xx/nvram.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/mips/bcm47xx/nvram.c +2 -5
@@ -93,7 +93,6 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim)return -ENXIO ; found: -if (header->len > size)pr_err ("The nvram size accoridng to the header seems to be bigger than the partition on flash\n" );if (header->len >NVRAM_SPACE )
@@ -103,10 +102,9 @@ found: src = (u32 *)header; dst = (u32 *)nvram_buf;for (i =0 ; i <sizeof (struct nvram_header ); i +=4 ) - *dst++ = *src++; + *dst++ =__raw_readl (src++);for (; i < header->len && i <NVRAM_SPACE && i < size; i +=4 ) - *dst++ =le32_to_cpu (*src++); -memset (dst,0x0 ,NVRAM_SPACE - i); + *dst++ =readl (src++);return 0 ; }
@@ -167,7 +165,6 @@ static int nvram_init(void) err =mtd_read (mtd, from, len, &bytes_read, dst);if (err)return err; -memset (dst + bytes_read,0x0 ,NVRAM_SPACE - bytes_read);return 0 ; }
Signature · 1 line
1.8.4.5
Rafał Miłecki
maintainerPATCH 3/3 MIPS: BCM47XX: Use strnchr to avoid reading out of the buffer
In reply to Rafał MiłeckiSigned-off-by Rafał Miłecki <[email protected]>
---
This code is there for YEARS, so I think it can wait for 3.20.
--- arch/mips/bcm47xx/nvram.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/mips/bcm47xx/nvram.c +4 -2
@@ -177,7 +177,7 @@ static int nvram_init(void)int bcm47xx_nvram_getenv (const char *name,char *val,size_t val_len) {char *var, *value, *end, *eq; -int err; +int data_left, err;if (!name)return -EINVAL ;
@@ -194,7 +194,9 @@ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) end[0 ] ='\0' ; end[1 ] ='\0' ;for (; *var; var = value +strlen (value) +1 ) { - eq =strchr (var,'=' ); + data_left = end - var; + + eq =strnchr (var, data_left,'=' );if (!eq)break ; value = eq +1 ;
Signature · 1 line
1.8.4.5
Rafał Miłecki
maintainerPATCH v2 1/3 MIPS: BCM47XX: Fix coding style to match kernel standards
In reply to Rafał MiłeckiSigned-off-by Rafał Miłecki <[email protected]>
---
V2: Replace
char *nvram_var = "gpioXX";
with
char nvram_var[] = "gpioXX";
to fix sizeof().
--- arch/mips/bcm47xx/bcm47xx_private.h | 4 ++++ arch/mips/bcm47xx/board.c | 3 +-- arch/mips/bcm47xx/nvram.c | 25 ++++++++++++++----------- arch/mips/bcm47xx/prom.c | 3 +-- arch/mips/bcm47xx/serial.c | 8 ++++---- arch/mips/bcm47xx/setup.c | 12 ++++++------ arch/mips/bcm47xx/sprom.c | 8 ++++---- arch/mips/bcm47xx/time.c | 1 - 8 files changed, 34 insertions(+), 30 deletions(-)
arch/mips/bcm47xx/bcm47xx_private.h +4 -0
@@ -1,6 +1,10 @@#ifndef LINUX_BCM47XX_PRIVATE_H_ #define LINUX_BCM47XX_PRIVATE_H_ +#ifndef pr_fmt +#define pr_fmt (fmt) "bcm47xx: " fmt +#endif +#include <linux/kernel.h> /* prom.c */
arch/mips/bcm47xx/board.c +1 -2
@@ -330,9 +330,8 @@ void __init bcm47xx_board_detect(void) err =bcm47xx_nvram_getenv ("boardtype" , buf,sizeof (buf));/* init of nvram failed, probably too early now */ -if (err == -ENXIO ) { +if (err == -ENXIO )return ; - } board_detected =bcm47xx_board_get_nvram (); bcm47xx_board.board = board_detected->board;
arch/mips/bcm47xx/nvram.c +14 -11
@@ -18,8 +18,10 @@#include <linux/mtd/mtd.h> #include <linux/bcm47xx_nvram.h> -#define NVRAM_MAGIC 0x48534C46/* 'FLSH' */ -#define NVRAM_SPACE 0x8000 +#define NVRAM_MAGIC 0x48534C46/* 'FLSH' */ +#define NVRAM_SPACE 0x8000 +#define NVRAM_MAX_GPIO_ENTRIES 32 +#define NVRAM_MAX_GPIO_VALUE_LEN 30#define FLASH_MIN 0x00020000/* Minimum flash size */
@@ -98,8 +100,8 @@ found:pr_err ("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n" , header->len,NVRAM_SPACE ); - src = (u32 *) header; - dst = (u32 *) nvram_buf; + src = (u32 *)header; + dst = (u32 *)nvram_buf;for (i =0 ; i <sizeof (struct nvram_header ); i +=4 ) *dst++ = *src++;for (; i < header->len && i <NVRAM_SPACE && i < size; i +=4 )
@@ -192,16 +194,16 @@ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)/* Look for name=value and return value */ var = &nvram_buf[sizeof (struct nvram_header )]; end = nvram_buf +sizeof (nvram_buf) -2 ; - end[0 ] = end[1 ] ='\0' ; + end[0 ] ='\0' ; + end[1 ] ='\0' ;for (; *var; var = value +strlen (value) +1 ) { eq =strchr (var,'=' );if (!eq)break ; value = eq +1 ; -if ((eq - var) ==strlen (name) && -strncmp (var, name, (eq - var)) ==0 ) { +if (eq - var ==strlen (name) && +strncmp (var, name, eq - var) ==0 )return snprintf (val, val_len,"%s" , value); - } }return -ENOENT ; }
@@ -210,10 +212,11 @@ EXPORT_SYMBOL(bcm47xx_nvram_getenv);int bcm47xx_nvram_gpio_pin (const char *name) {int i, err; -char nvram_var[10 ]; -char buf[30 ]; +char nvram_var[] ="gpioXX" ; +char buf[NVRAM_MAX_GPIO_VALUE_LEN ]; -for (i =0 ; i <32 ; i++) { +/* TODO: Optimize it to don't call getenv so many times */ +for (i =0 ; i <NVRAM_MAX_GPIO_ENTRIES ; i++) { err =snprintf (nvram_var,sizeof (nvram_var),"gpio%i" , i);if (err <=0 )continue ;
arch/mips/bcm47xx/prom.c +1 -2
@@ -35,7 +35,6 @@#include <bcm47xx.h> #include <bcm47xx_board.h> -static char bcm47xx_system_type[20 ] ="Broadcom BCM47XX" ;const char *get_system_type (void )
@@ -83,7 +82,7 @@ static __init void prom_init_mem(void)/* Loop condition may be not enough, off may be over 1 MiB */ if (off + mem >= max) { mem = max; -printk (KERN_DEBUG "assume 128MB RAM\n" ); +pr_debug ("Assume 128MB RAM\n" );break ; }if (!memcmp (prom_init, prom_init + mem,32 ))
arch/mips/bcm47xx/serial.c +4 -4
@@ -36,8 +36,8 @@ static int __init uart8250_init_ssb(void)struct plat_serial8250_port *p = &(uart8250_data[i]);struct ssb_serial_port *ssb_port = &(mcore->serial_ports[i]); - p->mapbase = (unsigned int ) ssb_port->regs; - p->membase = (void *) ssb_port->regs; + p->mapbase = (unsigned int )ssb_port->regs; + p->membase = (void *)ssb_port->regs; p->irq = ssb_port->irq +2 ; p->uartclk = ssb_port->baud_base; p->regshift = ssb_port->reg_shift;
@@ -62,8 +62,8 @@ static int __init uart8250_init_bcma(void)struct bcma_serial_port *bcma_port; bcma_port = &(cc->serial_ports[i]); - p->mapbase = (unsigned int ) bcma_port->regs; - p->membase = (void *) bcma_port->regs; + p->mapbase = (unsigned int )bcma_port->regs; + p->membase = (void *)bcma_port->regs; p->irq = bcma_port->irq; p->uartclk = bcma_port->baud_base; p->regshift = bcma_port->reg_shift;
arch/mips/bcm47xx/setup.c +6 -6
@@ -52,7 +52,7 @@ EXPORT_SYMBOL(bcm47xx_bus_type);static void bcm47xx_machine_restart (char *command) { -printk (KERN_ALERT "Please stand by while rebooting the system...\n" ); +pr_alert ("Please stand by while rebooting the system...\n" );local_irq_disable ();/* Set the watchdog timer to reset immediately */ switch (bcm47xx_bus_type) {
@@ -107,7 +107,7 @@ static int bcm47xx_get_invariants(struct ssb_bus *bus,char buf[20 ];/* Fill boardinfo structure */ -memset (&(iv->boardinfo),0 ,sizeof (struct ssb_boardinfo )); +memset (&iv->boardinfo,0 ,sizeof (struct ssb_boardinfo ));bcm47xx_fill_ssb_boardinfo (&iv->boardinfo,NULL );
@@ -126,7 +126,7 @@ static void __init bcm47xx_register_ssb(void)char buf[100 ];struct ssb_mipscore *mcore; - err =ssb_bus_ssbbus_register (&(bcm47xx_bus.ssb),SSB_ENUM_BASE , + err =ssb_bus_ssbbus_register (&bcm47xx_bus.ssb,SSB_ENUM_BASE , bcm47xx_get_invariants);if (err)panic ("Failed to initialize SSB bus (err %d)" , err);
@@ -136,7 +136,7 @@ static void __init bcm47xx_register_ssb(void)if (strstr (buf,"console=ttyS1" )) {struct ssb_serial_port port; -printk (KERN_DEBUG "Swapping serial ports!\n" ); +pr_debug ("Swapping serial ports!\n" );/* swap serial ports */ memcpy (&port, &mcore->serial_ports[0 ],sizeof (port)); memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
@@ -168,7 +168,7 @@ void __init plat_mem_setup(void)struct cpuinfo_mips *c = ¤t_cpu_data;if ((c->cputype ==CPU_74K ) || (c->cputype ==CPU_1074K )) { -printk (KERN_INFO "bcm47xx: using bcma bus\n" ); +pr_info ("Using bcma bus\n" );#ifdef CONFIG_BCM47XX_BCMA bcm47xx_bus_type =BCM47XX_BUS_TYPE_BCMA ;bcm47xx_sprom_register_fallbacks ();
@@ -179,7 +179,7 @@ void __init plat_mem_setup(void)#endif #endif }else { -printk (KERN_INFO "bcm47xx: using ssb bus\n" ); +pr_info ("Using ssb bus\n" );#ifdef CONFIG_BCM47XX_SSB bcm47xx_bus_type =BCM47XX_BUS_TYPE_SSB ;bcm47xx_sprom_register_fallbacks ();
arch/mips/bcm47xx/sprom.c +4 -4
@@ -780,8 +780,8 @@ void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix,bcm47xx_fill_sprom_path_r4589 (sprom, prefix, fallback);break ;default : -pr_warn ("Unsupported SPROM revision %d detected. Will extract" -" v1\n" , sprom->revision); +pr_warn ("Unsupported SPROM revision %d detected. Will extract v1\n" , + sprom->revision); sprom->revision =1 ;bcm47xx_fill_sprom_r1234589 (sprom, prefix, fallback);bcm47xx_fill_sprom_r12389 (sprom, prefix, fallback);
@@ -828,7 +828,7 @@ static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)bcm47xx_fill_sprom (out, prefix, false);return 0 ; }else { -pr_warn ("bcm47xx: unable to fill SPROM for given bustype.\n" ); +pr_warn ("Unable to fill SPROM for given bustype.\n" );return -EINVAL ; } }
@@ -860,7 +860,7 @@ static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) }return 0 ;default : -pr_warn ("bcm47xx: unable to fill SPROM for given bustype.\n" ); +pr_warn ("Unable to fill SPROM for given bustype.\n" );return -EINVAL ; } }
arch/mips/bcm47xx/time.c +0 -1
@@ -22,7 +22,6 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/init.h> #include <linux/ssb/ssb.h> #include <asm/time.h>
Signature · 1 line
1.8.4.5
Quoted 7 lines · Rafał Miłecki
Signed-off-by Rafał Miłecki <[email protected]>---
V2: Replace
char*nvram_var= "gpioXX";
with
char nvram_var[] = "gpioXX";
to fixsizeof().
Quoted 11 lines
--- arch/mips/bcm47xx/bcm47xx_private.h | 4 ++++ arch/mips/bcm47xx/board.c | 3 +-- arch/mips/bcm47xx/nvram.c | 25 ++++++++++++++----------- arch/mips/bcm47xx/prom.c | 3 +-- arch/mips/bcm47xx/serial.c | 8 ++++---- arch/mips/bcm47xx/setup.c | 12 ++++++------ arch/mips/bcm47xx/sprom.c | 8 ++++---- arch/mips/bcm47xx/time.c | 1 - 8 files changed, 34 insertions(+), 30 deletions(-)
Acked-by Hauke Mehrtens <[email protected]>
For all 3 patches.