Patchwork bios: pciirq: fix printf format and tidy some variable scopes

login
register
mail settings
Submitter Colin King
Date Jan. 9, 2014, 3:22 p.m.
Message ID <1389280922-24235-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/308857/
State Accepted
Headers show

Comments

Colin King - Jan. 9, 2014, 3:22 p.m.
From: Colin Ian King <colin.king@canonical.com>

fix %u format specifier on an int.  While were at it, reduce
the scope of a few variables (stops cppcheck complaining)

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/bios/pciirq/pciirq.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Ivan Hu - Jan. 13, 2014, 3:21 a.m.
On 01/09/2014 11:22 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> fix %u format specifier on an int.  While were at it, reduce
> the scope of a few variables (stops cppcheck complaining)
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/bios/pciirq/pciirq.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/src/bios/pciirq/pciirq.c b/src/bios/pciirq/pciirq.c
> index 11789ad..a2a3b51 100644
> --- a/src/bios/pciirq/pciirq.c
> +++ b/src/bios/pciirq/pciirq.c
> @@ -77,14 +77,15 @@ static const char *pciirq_reserved(uint8_t *data)
>   static const char *pciirq_irq_bitmap(uint16_t val)
>   {
>   	static char buf[40];
> -	char tmp[5];
> -	int i;
>
>   	*buf = '\0';
>   	if (val) {
> -		for (i=0; i < 16; val >>= 1, i++) {
> +		int i;
> +
> +		for (i = 0; i < 16; val >>= 1, i++) {
>   			if (val & 1) {
> -				snprintf(tmp, sizeof(tmp), "%s%u", *buf ? " ": "", i);
> +				char tmp[5];
> +				snprintf(tmp, sizeof(tmp), "%s%d", *buf ? " ": "", i);
>   				strcat(buf, tmp);
>   			}
>   		}
> @@ -117,7 +118,6 @@ static int pciirq_test1(fwts_framework *fw)
>   	}
>
>   	for (i=0; i < PCIIRQ_REGION_SIZE; i+= 16) {
> -		bool slot_ok;
>   		pci_irq_routing_table *pciirq = (pci_irq_routing_table*)(mem+i);
>   		if ((memcmp(pciirq->signature, "$PIR", 4) == 0) &&
>   		    (fwts_checksum(mem+i, pciirq->table_size) == 0)) {
> @@ -125,6 +125,7 @@ static int pciirq_test1(fwts_framework *fw)
>   			slot_entry *slot;
>   			int slot_count = (pciirq->table_size - 32) / sizeof(slot_entry);
>   			int expected_size = (32 + (slot_count * sizeof(slot_entry)));
> +			bool slot_ok = true;
>
>   			fwts_log_nl(fw);
>   			fwts_log_info(fw, "Found PCI IRQ Routing Table at 0x%8.8x", PCIIRQ_REGION_START+i);
> @@ -208,7 +209,6 @@ static int pciirq_test1(fwts_framework *fw)
>   			/*
>   			 *  This is a fairly shallow test
>   			 */
> -			slot_ok = true;
>   			for (slot = pciirq->slots, j = 0; j < slot_count; j++, slot++) {
>   				for (k = 0; k < 4; k++) {
>   					if ((slot->INT[k].link != 0) && (slot->INT[k].bitmap == 0)) {
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Alex Hung - Jan. 14, 2014, 2:10 a.m.
On 01/09/2014 11:22 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> fix %u format specifier on an int.  While were at it, reduce
> the scope of a few variables (stops cppcheck complaining)
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/bios/pciirq/pciirq.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/bios/pciirq/pciirq.c b/src/bios/pciirq/pciirq.c
> index 11789ad..a2a3b51 100644
> --- a/src/bios/pciirq/pciirq.c
> +++ b/src/bios/pciirq/pciirq.c
> @@ -77,14 +77,15 @@ static const char *pciirq_reserved(uint8_t *data)
>  static const char *pciirq_irq_bitmap(uint16_t val)
>  {
>  	static char buf[40];
> -	char tmp[5];
> -	int i;
>  
>  	*buf = '\0';
>  	if (val) {
> -		for (i=0; i < 16; val >>= 1, i++) {
> +		int i;
> +
> +		for (i = 0; i < 16; val >>= 1, i++) {
>  			if (val & 1) {
> -				snprintf(tmp, sizeof(tmp), "%s%u", *buf ? " ": "", i);
> +				char tmp[5];
> +				snprintf(tmp, sizeof(tmp), "%s%d", *buf ? " ": "", i);
>  				strcat(buf, tmp);
>  			}
>  		}
> @@ -117,7 +118,6 @@ static int pciirq_test1(fwts_framework *fw)
>  	}
>  
>  	for (i=0; i < PCIIRQ_REGION_SIZE; i+= 16) {
> -		bool slot_ok;
>  		pci_irq_routing_table *pciirq = (pci_irq_routing_table*)(mem+i);
>  		if ((memcmp(pciirq->signature, "$PIR", 4) == 0) &&
>  		    (fwts_checksum(mem+i, pciirq->table_size) == 0)) {
> @@ -125,6 +125,7 @@ static int pciirq_test1(fwts_framework *fw)
>  			slot_entry *slot;
>  			int slot_count = (pciirq->table_size - 32) / sizeof(slot_entry);
>  			int expected_size = (32 + (slot_count * sizeof(slot_entry)));
> +			bool slot_ok = true;
>  
>  			fwts_log_nl(fw);
>  			fwts_log_info(fw, "Found PCI IRQ Routing Table at 0x%8.8x", PCIIRQ_REGION_START+i);
> @@ -208,7 +209,6 @@ static int pciirq_test1(fwts_framework *fw)
>  			/*
>  			 *  This is a fairly shallow test
>  			 */
> -			slot_ok = true;
>  			for (slot = pciirq->slots, j = 0; j < slot_count; j++, slot++) {
>  				for (k = 0; k < 4; k++) {
>  					if ((slot->INT[k].link != 0) && (slot->INT[k].bitmap == 0)) {
> 


Acked-by: Alex Hung <alex.hung@canonical.com>

Patch

diff --git a/src/bios/pciirq/pciirq.c b/src/bios/pciirq/pciirq.c
index 11789ad..a2a3b51 100644
--- a/src/bios/pciirq/pciirq.c
+++ b/src/bios/pciirq/pciirq.c
@@ -77,14 +77,15 @@  static const char *pciirq_reserved(uint8_t *data)
 static const char *pciirq_irq_bitmap(uint16_t val)
 {
 	static char buf[40];
-	char tmp[5];
-	int i;
 
 	*buf = '\0';
 	if (val) {
-		for (i=0; i < 16; val >>= 1, i++) {
+		int i;
+
+		for (i = 0; i < 16; val >>= 1, i++) {
 			if (val & 1) {
-				snprintf(tmp, sizeof(tmp), "%s%u", *buf ? " ": "", i);
+				char tmp[5];
+				snprintf(tmp, sizeof(tmp), "%s%d", *buf ? " ": "", i);
 				strcat(buf, tmp);
 			}
 		}
@@ -117,7 +118,6 @@  static int pciirq_test1(fwts_framework *fw)
 	}
 
 	for (i=0; i < PCIIRQ_REGION_SIZE; i+= 16) {
-		bool slot_ok;
 		pci_irq_routing_table *pciirq = (pci_irq_routing_table*)(mem+i);
 		if ((memcmp(pciirq->signature, "$PIR", 4) == 0) &&
 		    (fwts_checksum(mem+i, pciirq->table_size) == 0)) {
@@ -125,6 +125,7 @@  static int pciirq_test1(fwts_framework *fw)
 			slot_entry *slot;
 			int slot_count = (pciirq->table_size - 32) / sizeof(slot_entry);
 			int expected_size = (32 + (slot_count * sizeof(slot_entry)));
+			bool slot_ok = true;
 
 			fwts_log_nl(fw);
 			fwts_log_info(fw, "Found PCI IRQ Routing Table at 0x%8.8x", PCIIRQ_REGION_START+i);
@@ -208,7 +209,6 @@  static int pciirq_test1(fwts_framework *fw)
 			/*
 			 *  This is a fairly shallow test
 			 */
-			slot_ok = true;
 			for (slot = pciirq->slots, j = 0; j < slot_count; j++, slot++) {
 				for (k = 0; k < 4; k++) {
 					if ((slot->INT[k].link != 0) && (slot->INT[k].bitmap == 0)) {