xen/arm: setup: nr_banks should be unsigned int
PATCH 1/1 xen/arm: setup: nr_banks should be unsigned int
From: Julien Grall <[email protected]>
It is not possible to have a negative number of banks. So switch to unsigned int.
The type change is also propagated to any users of nr_banks that were using "int" (there are not that many).
Note that fdt_num_mem_rsv() can actually returns a negative value in case of an error. So the return should be checked before assigning the result to an unsigned variable.
--- xen/arch/arm/domain_build.c | 9 +++++---- xen/arch/arm/efi/efi-dom0.c | 4 ++-- xen/arch/arm/include/asm/setup.h | 6 +++--- xen/arch/arm/setup.c | 17 +++++++++++++---- 4 files changed, 23 insertions(+), 13 deletions(-)
xen/arch/arm/domain_build.c +5 -4
@@ -111,7 +111,8 @@ static bool __init insert_11_bank(struct domain *d, struct page_info *pg, unsigned int order) { - int res, i; +unsigned int i; +int res;mfn_t smfn;paddr_t start, size;
@@ -264,7 +265,7 @@ static void __init allocate_memory_11(struct domain *d,const unsigned int min_order =get_order_from_bytes (MB (4 ));struct page_info *pg;unsigned int order =get_allocation_size (kinfo->unassigned_mem); -int i; +unsigned int i;bool lowmem = true;unsigned int lowmem_bitsize =min (32U ,arch_get_dma_bitsize ());
@@ -1022,8 +1023,8 @@ static int __init make_memory_node(const struct domain *d, int addrcells, int sizecells, struct meminfo *mem) { - int res, i; -int reg_size = addrcells + sizecells; + unsigned int i; +int res, reg_size = addrcells + sizecells;int nr_cells =0 ;/* Placeholder for memory@ + a 64-bit number + \0 */ char buf[24 ];
xen/arch/arm/efi/efi-dom0.c +2 -2
@@ -34,14 +34,14 @@/* Constant to indicate "Xen" in unicode u16 format */ static const CHAR16 xen_efi_fw_vendor[] = {0x0058 ,0x0065 ,0x006E ,0x0000 }; -size_t __init estimate_efi_size (int mem_nr_banks) +size_t __init estimate_efi_size (unsigned int mem_nr_banks) {size_t size;size_t est_size =sizeof (EFI_SYSTEM_TABLE );size_t ect_size =sizeof (EFI_CONFIGURATION_TABLE );size_t emd_size =sizeof (EFI_MEMORY_DESCRIPTOR );size_t fw_vendor_size =sizeof (xen_efi_fw_vendor); -int acpi_mem_nr_banks =0 ; +unsigned int acpi_mem_nr_banks =0 ;if ( !acpi_disabled ) acpi_mem_nr_banks = bootinfo.acpi.nr_banks;
xen/arch/arm/include/asm/setup.h +3 -3
@@ -30,7 +30,7 @@ struct membank { };struct meminfo { -int nr_banks; +unsigned int nr_banks;struct membank bank[NR_MEM_BANKS ]; };
@@ -93,7 +93,7 @@ extern domid_t max_init_domid;void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len); -size_t estimate_efi_size (int mem_nr_banks); +size_t estimate_efi_size (unsigned int mem_nr_banks);void acpi_create_efi_system_table (struct domain *d,struct membank tbl_add[]);
@@ -109,7 +109,7 @@ void create_dom0(void);void discard_initial_modules (void );void fw_unreserved_regions (paddr_t s,paddr_t e, -void (*cb)(paddr_t ,paddr_t ),int first); +void (*cb)(paddr_t ,paddr_t ),unsigned int first);size_t boot_fdt_info (const void *fdt,paddr_t paddr);const char *boot_fdt_cmdline (const void *fdt);
xen/arch/arm/setup.c +13 -4
@@ -201,9 +201,17 @@ static void __init processor_id(void)static void __init dt_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ), -int first) +unsigned int first) { -int i, nr =fdt_num_mem_rsv (device_tree_flattened); +unsigned int i, nr; +int rc; + + rc =fdt_num_mem_rsv (device_tree_flattened); +if ( rc <0 ) +panic ("Unable to retrieve the number of reserved regions (rc=%d)\n" , + rc); + + nr = rc;for ( i = first; i < nr ; i++ ) {
@@ -249,7 +257,8 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, }void __init fw_unreserved_regions (paddr_t s,paddr_t e, -void (*cb)(paddr_t ,paddr_t ),int first) +void (*cb)(paddr_t ,paddr_t ), +unsigned int first) {if ( acpi_disabled )dt_unreserved_regions (s, e, cb, first);
@@ -693,7 +702,7 @@ static void __init setup_mm(void)paddr_t ram_start, ram_end, ram_size, e;unsigned long ram_pages;unsigned long heap_pages, xenheap_pages, domheap_pages; -int i; +unsigned int i;const uint32_t ctr =READ_CP32 (CTR );if ( !bootinfo.mem.nr_banks )
Signature · 1 line
2.32.0
Hi Julien,
Quoted 158 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Julien Grall
Sent: 2022年5月24日 3:47
To: [email protected]
Cc: Michal Orzel <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>
Subject: [PATCH] xen/arm: setup:nr_banksshould be unsigned intFrom: Julien Grall <[email protected]>
It is not possible to have a negative number of banks. So switch to unsigned int.
The type change is also propagated to any users of
nr_banksthat were using "int" (there are not that many).Note that
fdt_num_mem_rsv()can actually returns a negative value in case of an error. So the return should be checked before assigning the result to an unsigned variable.Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain_build.c | 9 +++++---- xen/arch/arm/efi/efi-dom0.c | 4 ++-- xen/arch/arm/include/asm/setup.h | 6 +++--- xen/arch/arm/setup.c | 17 +++++++++++++---- 4 files changed, 23 insertions(+), 13 deletions(-)xen/arch/arm/domain_build.c +5
-4@@ -111,7 +111,8 @@ static bool __init insert_11_bank(struct domain *d, struct page_info *pg, unsigned int order) { - int res, i; +unsigned int i; +int res;mfn_t smfn;paddr_t start, size;@@ -264,7 +265,7 @@ static void __init allocate_memory_11(struct domain *d,const unsigned int min_order =get_order_from_bytes (MB (4 ));struct page_info *pg;unsigned int order =get_allocation_size (kinfo->unassigned_mem); -int i; +unsigned int i;bool lowmem = true;unsigned int lowmem_bitsize =min (32U ,arch_get_dma_bitsize ());@@ -1022,8 +1023,8 @@ static int __init make_memory_node(const structdomain *d, int addrcells, int sizecells, struct meminfo *mem) { - int res, i; -int reg_size = addrcells + sizecells; + unsigned int i; +int res, reg_size = addrcells + sizecells;int nr_cells =0 ;/* Placeholder for memory@ + a 64-bit number + \0 */ char buf[24];xen/arch/arm/efi/efi-dom0.c +2
-2@@ -34,14 +34,14 @@/* Constant to indicate "Xen" in unicode u16 format */ static const CHAR16 xen_efi_fw_vendor[] = {0x0058 ,0x0065 ,0x006E ,0x0000 }; -size_t __init estimate_efi_size (int mem_nr_banks) +size_t __init estimate_efi_size (unsigned int mem_nr_banks) {size_t size;size_t est_size =sizeof (EFI_SYSTEM_TABLE );size_t ect_size =sizeof (EFI_CONFIGURATION_TABLE );size_t emd_size =sizeof (EFI_MEMORY_DESCRIPTOR );size_t fw_vendor_size =sizeof (xen_efi_fw_vendor); -int acpi_mem_nr_banks =0 ; +unsigned int acpi_mem_nr_banks =0 ;if ( !acpi_disabled )acpi_mem_nr_banks = bootinfo.acpi.nr_banks;xen/arch/arm/include/asm/setup.h +3
-3@@ -30,7 +30,7 @@ struct membank { };struct meminfo { -int nr_banks; +unsigned int nr_banks;struct membank bank[NR_MEM_BANKS ]; };@@ -93,7 +93,7 @@ extern domid_t max_init_domid;void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len); -size_t estimate_efi_size (int mem_nr_banks); +size_t estimate_efi_size (unsigned int mem_nr_banks);void acpi_create_efi_system_table (struct domain *d,struct membank tbl_add[]);@@ -109,7 +109,7 @@ void create_dom0(void);void discard_initial_modules (void );void fw_unreserved_regions (paddr_t s,paddr_t e, -void (*cb)(paddr_t ,paddr_t ),int first); +void (*cb)(paddr_t ,paddr_t ),unsigned int first);size_t boot_fdt_info (const void *fdt,paddr_t paddr);const char *boot_fdt_cmdline(const void *fdt);
xen/arch/arm/setup.c +10
-2@@ -201,9 +201,17 @@ static void __init processor_id(void)static void __init dt_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ), -int first) +unsigned int first) { -int i, nr =fdt_num_mem_rsv (device_tree_flattened); +unsigned int i, nr; +int rc; + + rc =fdt_num_mem_rsv (device_tree_flattened); +if ( rc <0 ) + panic("Unable to retrieve the number of reserved regions (rc=%d)\n", + rc); + + nr = rc;for ( i = first; i < nr ; i++ ){xen/arch/arm/setup.c +2
-1@@ -249,7 +257,8 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, }void __init fw_unreserved_regions (paddr_t s,paddr_t e, -void (*cb)(paddr_t ,paddr_t ),int first) +void (*cb)(paddr_t ,paddr_t ), +unsigned int first) {if ( acpi_disabled )dt_unreserved_regions(s, e, cb, first);
xen/arch/arm/setup.c static void __init setup_mm(void) · line 708
Quoted 8 lines
xen/arch/arm/setup.c +1
-1@@ -693,7 +702,7 @@ static void __init setup_mm(void)paddr_t ram_start, ram_end, ram_size, e;unsigned long ram_pages;unsigned long heap_pages, xenheap_pages, domheap_pages; -int i; +unsigned int i;const uint32_t ctr =READ_CP32 (CTR );if ( !bootinfo.mem.nr_banks )
Quoted 3 lines
--
2.32.0
Stefano Stabellini
Acked-byQuoted 167 lines · Wei Chen
Hi Julien,
Quoted 165 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Julien Grall
Sent: 2022年5月24日 3:47
To: [email protected]
Cc: Michal Orzel <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>
Subject: [PATCH] xen/arm: setup:nr_banksshould be unsigned intFrom: Julien Grall <[email protected]>
It is not possible to have a negative number of banks. So switch to unsigned int.
The type change is also propagated to any users of
nr_banksthat were using "int" (there are not that many).Note that
fdt_num_mem_rsv()can actually returns a negative value in case of an error. So the return should be checked before assigning the result to an unsigned variable.Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain_build.c | 9 +++++---- xen/arch/arm/efi/efi-dom0.c | 4 ++-- xen/arch/arm/include/asm/setup.h | 6 +++--- xen/arch/arm/setup.c | 17 +++++++++++++---- 4 files changed, 23 insertions(+), 13 deletions(-)xen/arch/arm/domain_build.c +5
-4@@ -111,7 +111,8 @@ static bool __init insert_11_bank(struct domain *d, struct page_info *pg, unsigned int order) { - int res, i; +unsigned int i; +int res;mfn_t smfn;paddr_t start, size;@@ -264,7 +265,7 @@ static void __init allocate_memory_11(struct domain *d,const unsigned int min_order =get_order_from_bytes (MB (4 ));struct page_info *pg;unsigned int order =get_allocation_size (kinfo->unassigned_mem); -int i; +unsigned int i;bool lowmem = true;unsigned int lowmem_bitsize =min (32U ,arch_get_dma_bitsize ());@@ -1022,8 +1023,8 @@ static int __init make_memory_node(const structdomain *d, int addrcells, int sizecells, struct meminfo *mem) { - int res, i; -int reg_size = addrcells + sizecells; + unsigned int i; +int res, reg_size = addrcells + sizecells;int nr_cells =0 ;/* Placeholder for memory@ + a 64-bit number + \0 */ char buf[24];xen/arch/arm/efi/efi-dom0.c +2
-2@@ -34,14 +34,14 @@/* Constant to indicate "Xen" in unicode u16 format */ static const CHAR16 xen_efi_fw_vendor[] = {0x0058 ,0x0065 ,0x006E ,0x0000 }; -size_t __init estimate_efi_size (int mem_nr_banks) +size_t __init estimate_efi_size (unsigned int mem_nr_banks) {size_t size;size_t est_size =sizeof (EFI_SYSTEM_TABLE );size_t ect_size =sizeof (EFI_CONFIGURATION_TABLE );size_t emd_size =sizeof (EFI_MEMORY_DESCRIPTOR );size_t fw_vendor_size =sizeof (xen_efi_fw_vendor); -int acpi_mem_nr_banks =0 ; +unsigned int acpi_mem_nr_banks =0 ;if ( !acpi_disabled )acpi_mem_nr_banks = bootinfo.acpi.nr_banks;xen/arch/arm/include/asm/setup.h +3
-3@@ -30,7 +30,7 @@ struct membank { };struct meminfo { -int nr_banks; +unsigned int nr_banks;struct membank bank[NR_MEM_BANKS ]; };@@ -93,7 +93,7 @@ extern domid_t max_init_domid;void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len); -size_t estimate_efi_size (int mem_nr_banks); +size_t estimate_efi_size (unsigned int mem_nr_banks);void acpi_create_efi_system_table (struct domain *d,struct membank tbl_add[]);@@ -109,7 +109,7 @@ void create_dom0(void);void discard_initial_modules (void );void fw_unreserved_regions (paddr_t s,paddr_t e, -void (*cb)(paddr_t ,paddr_t ),int first); +void (*cb)(paddr_t ,paddr_t ),unsigned int first);size_t boot_fdt_info (const void *fdt,paddr_t paddr);const char *boot_fdt_cmdline(const void *fdt);
xen/arch/arm/setup.c +10
-2@@ -201,9 +201,17 @@ static void __init processor_id(void)static void __init dt_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ), -int first) +unsigned int first) { -int i, nr =fdt_num_mem_rsv (device_tree_flattened); +unsigned int i, nr; +int rc; + + rc =fdt_num_mem_rsv (device_tree_flattened); +if ( rc <0 ) + panic("Unable to retrieve the number of reserved regions (rc=%d)\n", + rc); + + nr = rc;for ( i = first; i < nr ; i++ ){xen/arch/arm/setup.c +2
-1@@ -249,7 +257,8 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, }void __init fw_unreserved_regions (paddr_t s,paddr_t e, -void (*cb)(paddr_t ,paddr_t ),int first) +void (*cb)(paddr_t ,paddr_t ), +unsigned int first) {if ( acpi_disabled )dt_unreserved_regions(s, e, cb, first);xen/arch/arm/setup.c +1
-1@@ -693,7 +702,7 @@ static void __init setup_mm(void)paddr_t ram_start, ram_end, ram_size, e;unsigned long ram_pages;unsigned long heap_pages, xenheap_pages, domheap_pages; -int i; +unsigned int i;const uint32_t ctr =READ_CP32 (CTR );
Quoted 3 lines
xen/arch/arm/setup.c static void __init setup_mm(void) · line 708
Quoted 1 line
xen/arch/arm/setup.c +0
-0if ( !bootinfo.mem.nr_banks )Reviewed-by Wei Chen <[email protected]>
and committed