From 17e6ffa6a5d2674cb2ebfd967d28b1048261d977 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 21 Mar 2022 15:30:18 +0100 Subject: hw/i386/amd_iommu: Fix maybe-uninitialized error with GCC 12 Be more explicit that the loop must roll at least once. Avoids the following warning: FAILED: libqemu-x86_64-softmmu.fa.p/hw_i386_amd_iommu.c.o In function 'pte_get_page_mask', inlined from 'amdvi_page_walk' at hw/i386/amd_iommu.c:945:25, inlined from 'amdvi_do_translate' at hw/i386/amd_iommu.c:989:5, inlined from 'amdvi_translate' at hw/i386/amd_iommu.c:1038:5: hw/i386/amd_iommu.c:877:38: error: 'oldlevel' may be used uninitialized [-Werror=maybe-uninitialized] 877 | return ~((1UL << ((oldlevel * 9) + 3)) - 1); | ~~~~~~~~~~~~~~~~^~~~ hw/i386/amd_iommu.c: In function 'amdvi_translate': hw/i386/amd_iommu.c:906:41: note: 'oldlevel' was declared here 906 | unsigned level, present, pte_perms, oldlevel; | ^~~~~~~~ cc1: all warnings being treated as errors Having: $ gcc --version gcc (Debian 12-20220313-1) 12.0.1 20220314 (experimental) Reported-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/i386/amd_iommu.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'hw/i386/amd_iommu.c') diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 4d13d8e697..6986ad3b87 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -913,7 +913,7 @@ static void amdvi_page_walk(AMDVIAddressSpace *as, uint64_t *dte, } /* we are at the leaf page table or page table encodes a huge page */ - while (level > 0) { + do { pte_perms = amdvi_get_perms(pte); present = pte & 1; if (!present || perms != (perms & pte_perms)) { @@ -932,10 +932,7 @@ static void amdvi_page_walk(AMDVIAddressSpace *as, uint64_t *dte, } oldlevel = level; level = get_pte_translation_mode(pte); - if (level == 0x7) { - break; - } - } + } while (level > 0 && level < 7); if (level == 0x7) { page_mask = pte_override_page_mask(pte); -- cgit v1.2.3-55-g7522 /option>
blob: 4e5fca57a801cf62f0df2e9acfd22fa16a54cb8d (plain) (tree)
1
2
3
4
5

                                                           
  
                                         
  


















                                                                                
                       
                        
                    
                  
                       
                              
                       
                     
 
                    

                         

  
                     
                     

  
                                                 
                                       
 
                           
                                          
                                     
                             
         
     


                                                                      


                                      
     


             
 





                                                                            





                                                                     
               
     

                                                

                                       

                                                                        

 

                                                            
                                                                    
 
            
            
                    
                    
                     

            
                                                               
                                 


                                               
                                                                       
                  
     
 
             
                                           
                  
         
                           
                                               
                                 







                                            


                                                                                
                





                                                  
             

                                  
                           
                                                    
                                  
                                                                
                        
                                                         
                                                        
 
                                                
                                                  

                                                
                                                  

                                               
                                                 
                     
 
                                                         
 
                                                   
                                
                                                    

                                                  
                                                            







                                                                    
     


            
              
               

 
 
                                                              
                                                                      
 



                                           
                                                              




                                    

 
 
                                                
                                              
 


                                                        

                                    
                      


                                    
      





                                                                        
     
 



                                        
















                                                                   
 














                                                            

         
                                    
 
 
                                                   
 

                                             
     
                 

 
                                                  
 




                                               
     
                 
 
/*
 * QEMU keysym to keycode conversion using rdesktop keymaps
 *
 * Copyright (c) 2004 Johannes Schindelin
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "keymaps.h"
#include "trace.h"
#include "qemu/ctype.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "ui/input.h"

struct keysym2code {
    uint32_t count;
    uint16_t keycodes[4];
};

struct kbd_layout_t {
    GHashTable *hash;
};

static int get_keysym(const name2keysym_t *table,
                      const char *name)
{
    const name2keysym_t *p;
    for(p = table; p->name != NULL; p++) {
        if (!strcmp(p->name, name)) {
            return p->keysym;
        }
    }
    if (name[0] == 'U' && strlen(name) == 5) { /* try unicode Uxxxx */
        char *end;
        int ret = (int)strtoul(name + 1, &end, 16);
        if (*end == '\0' && ret > 0) {
            return ret;
        }
    }
    return 0;
}


static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k)
{
    struct keysym2code *keysym2code;

    keysym2code = g_hash_table_lookup(k->hash, GINT_TO_POINTER(keysym));
    if (keysym2code) {
        if (keysym2code->count < ARRAY_SIZE(keysym2code->keycodes)) {
            keysym2code->keycodes[keysym2code->count++] = keycode;
        } else {
            warn_report("more than %zd keycodes for keysym %d",
                        ARRAY_SIZE(keysym2code->keycodes), keysym);
        }
        return;
    }

    keysym2code = g_new0(struct keysym2code, 1);
    keysym2code->keycodes[0] = keycode;
    keysym2code->count = 1;
    g_hash_table_replace(k->hash, GINT_TO_POINTER(keysym), keysym2code);
    trace_keymap_add(keysym, keycode, line);
}

static int parse_keyboard_layout(kbd_layout_t *k,
                                 const name2keysym_t *table,
                                 const char *language, Error **errp)
{
    int ret;
    FILE *f;
    char * filename;
    char line[1024];
    char keyname[64];
    int len;

    filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);
    trace_keymap_parse(filename);
    f = filename ? fopen(filename, "r") : NULL;
    g_free(filename);