pci-assign: avoid pointless stat
Just check the errno value after fopen and follow it with fstat. This shuts up Coverity's complaint about TOC/TOU violation. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
		
							parent
							
								
									ece9086eb5
								
							
						
					
					
						commit
						9ed2690354
					
				@ -39,19 +39,19 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, struct Object *owner,
 | 
				
			|||||||
             "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/rom",
 | 
					             "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/rom",
 | 
				
			||||||
             domain, bus, slot, function);
 | 
					             domain, bus, slot, function);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (stat(rom_file, &st)) {
 | 
					 | 
				
			||||||
        if (errno != ENOENT) {
 | 
					 | 
				
			||||||
            error_report("pci-assign: Invalid ROM.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Write "1" to the ROM file to enable it */
 | 
					    /* Write "1" to the ROM file to enable it */
 | 
				
			||||||
    fp = fopen(rom_file, "r+");
 | 
					    fp = fopen(rom_file, "r+");
 | 
				
			||||||
    if (fp == NULL) {
 | 
					    if (fp == NULL) {
 | 
				
			||||||
 | 
					        if (errno != ENOENT) {
 | 
				
			||||||
            error_report("pci-assign: Cannot open %s: %s", rom_file, strerror(errno));
 | 
					            error_report("pci-assign: Cannot open %s: %s", rom_file, strerror(errno));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (fstat(fileno(fp), &st) == -1) {
 | 
				
			||||||
 | 
					        error_report("pci-assign: Cannot stat %s: %s", rom_file, strerror(errno));
 | 
				
			||||||
 | 
					        goto close_rom;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    val = 1;
 | 
					    val = 1;
 | 
				
			||||||
    if (fwrite(&val, 1, 1, fp) != 1) {
 | 
					    if (fwrite(&val, 1, 1, fp) != 1) {
 | 
				
			||||||
        goto close_rom;
 | 
					        goto close_rom;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user