Make it obvious that pci_nic_init() can't fail
Before this patch, pci_nic_init() returns NULL when it can't find the model in pci_nic_models[]. Except this can't happen, because qemu_check_nic_model_list() just searched for model in pci_nic_models[], and terminated the program on failure. Repeating the search here is pointless. Instead, change qemu_check_nic_model_list() to return the model's array index. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									49bd1458da
								
							
						
					
					
						commit
						9ee05825d9
					
				
							
								
								
									
										9
									
								
								hw/pci.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								hw/pci.c
									
									
									
									
									
								
							@ -871,10 +871,7 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
 | 
				
			|||||||
    DeviceState *dev;
 | 
					    DeviceState *dev;
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qemu_check_nic_model_list(nd, pci_nic_models, default_model);
 | 
					    i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (i = 0; pci_nic_models[i]; i++) {
 | 
					 | 
				
			||||||
        if (strcmp(nd->model, pci_nic_models[i]) == 0) {
 | 
					 | 
				
			||||||
    pci_dev = pci_create(pci_nic_names[i], devaddr);
 | 
					    pci_dev = pci_create(pci_nic_names[i], devaddr);
 | 
				
			||||||
    dev = &pci_dev->qdev;
 | 
					    dev = &pci_dev->qdev;
 | 
				
			||||||
    if (nd->id)
 | 
					    if (nd->id)
 | 
				
			||||||
@ -883,10 +880,6 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
 | 
				
			|||||||
    qdev_init(dev);
 | 
					    qdev_init(dev);
 | 
				
			||||||
    nd->private = dev;
 | 
					    nd->private = dev;
 | 
				
			||||||
    return pci_dev;
 | 
					    return pci_dev;
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return NULL;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								net.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								net.c
									
									
									
									
									
								
							@ -2358,7 +2358,7 @@ void qemu_check_nic_model(NICInfo *nd, const char *model)
 | 
				
			|||||||
    qemu_check_nic_model_list(nd, models, model);
 | 
					    qemu_check_nic_model_list(nd, models, model);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
 | 
					int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
 | 
				
			||||||
                              const char *default_model)
 | 
					                              const char *default_model)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i, exit_status = 0;
 | 
					    int i, exit_status = 0;
 | 
				
			||||||
@ -2369,7 +2369,7 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
 | 
				
			|||||||
    if (strcmp(nd->model, "?") != 0) {
 | 
					    if (strcmp(nd->model, "?") != 0) {
 | 
				
			||||||
        for (i = 0 ; models[i]; i++)
 | 
					        for (i = 0 ; models[i]; i++)
 | 
				
			||||||
            if (strcmp(nd->model, models[i]) == 0)
 | 
					            if (strcmp(nd->model, models[i]) == 0)
 | 
				
			||||||
                return;
 | 
					                return i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
 | 
					        fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
 | 
				
			||||||
        exit_status = 1;
 | 
					        exit_status = 1;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								net.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								net.h
									
									
									
									
									
								
							@ -76,7 +76,7 @@ void qemu_purge_queued_packets(VLANClientState *vc);
 | 
				
			|||||||
void qemu_flush_queued_packets(VLANClientState *vc);
 | 
					void qemu_flush_queued_packets(VLANClientState *vc);
 | 
				
			||||||
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
 | 
					void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
 | 
				
			||||||
void qemu_check_nic_model(NICInfo *nd, const char *model);
 | 
					void qemu_check_nic_model(NICInfo *nd, const char *model);
 | 
				
			||||||
void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
 | 
					int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
 | 
				
			||||||
                              const char *default_model);
 | 
					                              const char *default_model);
 | 
				
			||||||
void qemu_handler_true(void *opaque);
 | 
					void qemu_handler_true(void *opaque);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user