Print this page
12724 update smatch to 0.6.1-rc1-il-5

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_mtag_data.c
          +++ new/usr/src/tools/smatch/src/smatch_mtag_data.c
↓ open down ↓ 73 lines elided ↑ open up ↑
  74   74          char *macro;
  75   75  
  76   76          macro = get_macro_name(expr->pos);
  77   77          if (!macro)
  78   78                  return false;
  79   79          if (strcmp(macro, "EXPORT_SYMBOL") == 0)
  80   80                  return true;
  81   81          return false;
  82   82  }
  83   83  
       84 +static bool is_head_next(struct expression *expr)
       85 +{
       86 +        struct symbol *type;
       87 +
       88 +        /* Smatch thinks head->next == head is always true.  *sad face* */
       89 +
       90 +        if (option_project != PROJ_KERNEL)
       91 +                return false;
       92 +
       93 +        if (expr->type != EXPR_DEREF)
       94 +                return false;
       95 +        if (!expr->member || !expr->member->name ||
       96 +            strcmp(expr->member->name, "next") != 0)
       97 +                return false;
       98 +
       99 +        type = get_type(expr->deref);
      100 +        if (!type)
      101 +                return false;
      102 +        if (type->type == SYM_PTR)
      103 +                type = get_real_base_type(type);
      104 +        if (type->type != SYM_STRUCT)
      105 +                return false;
      106 +        if (!type->ident || !type->ident->name ||
      107 +            strcmp(type->ident->name, "list_head") != 0)
      108 +                return false;
      109 +        return true;
      110 +}
      111 +
      112 +mtag_t ignored_mtag;
      113 +static bool is_ignored_tag(mtag_t tag)
      114 +{
      115 +        if (tag == ignored_mtag)
      116 +                return true;
      117 +        return false;
      118 +}
      119 +
  84  120  static void insert_mtag_data(mtag_t tag, int offset, struct range_list *rl)
  85  121  {
      122 +        if (is_ignored_tag(tag))
      123 +                return;
      124 +
  86  125          rl = clone_rl_permanent(rl);
  87  126  
  88  127          mem_sql(NULL, NULL, "delete from mtag_data where tag = %lld and offset = %d and type = %d",
  89  128                  tag, offset, DATA_VALUE);
  90  129          mem_sql(NULL, NULL, "insert into mtag_data values (%lld, %d, %d, '%lu');",
  91  130                  tag, offset, DATA_VALUE, (unsigned long)rl);
  92  131  }
  93  132  
  94  133  static bool invalid_type(struct symbol *type)
  95  134  {
↓ open down ↓ 1 lines elided ↑ open up ↑
  97  136                  return true;
  98  137          if (type == &void_ctype)
  99  138                  return true;
 100  139          if (type->type == SYM_STRUCT ||
 101  140              type->type == SYM_ARRAY ||
 102  141              type->type == SYM_UNION)
 103  142                  return true;
 104  143          return false;
 105  144  }
 106  145  
      146 +static bool parent_is_fresh_alloc(struct expression *expr)
      147 +{
      148 +        struct symbol *sym;
      149 +
      150 +        sym = expr_to_sym(expr);
      151 +        if (!sym || !sym->ident)
      152 +                return false;
      153 +        return is_fresh_alloc_var_sym(sym->ident->name, sym);
      154 +}
      155 +
 107  156  void update_mtag_data(struct expression *expr, struct smatch_state *state)
 108  157  {
 109  158          struct range_list *orig, *new;
 110  159          struct symbol *type;
 111  160          char *name;
 112  161          mtag_t tag;
 113  162          int offset;
 114  163  
 115  164          if (!expr)
 116  165                  return;
 117  166          if (is_local_variable(expr))
 118  167                  return;
 119  168          if (is_ignored_macro(expr))
 120  169                  return;
      170 +        if (is_head_next(expr))
      171 +                return;
 121  172          name = expr_to_var(expr);
 122  173          if (is_kernel_param(name)) {
 123  174                  free_string(name);
 124  175                  return;
 125  176          }
 126  177          free_string(name);
 127  178  
 128  179          if (!expr_to_mtag_offset(expr, &tag, &offset))
 129  180                  return;
 130  181  
 131  182          type = get_type(expr);
 132  183          if (offset == 0 && invalid_type(type))
 133  184                  return;
 134  185  
 135      -        orig = select_orig(tag, offset);
      186 +        if (parent_is_fresh_alloc(expr))
      187 +                orig = NULL;
      188 +        else
      189 +                orig = select_orig(tag, offset);
 136  190          new = rl_union(orig, estate_rl(state));
 137  191          insert_mtag_data(tag, offset, new);
 138  192  }
 139  193  
 140  194  static void match_global_assign(struct expression *expr)
 141  195  {
 142  196          struct range_list *rl;
 143  197          mtag_t tag;
 144  198          int offset;
 145  199          char *name;
 146  200  
 147  201          if (is_ignored_macro(expr))
 148  202                  return;
      203 +        if (is_head_next(expr->left))
      204 +                return;
 149  205          name = expr_to_var(expr->left);
 150  206          if (is_kernel_param(name)) {
 151  207                  free_string(name);
 152  208                  return;
 153  209          }
 154  210          free_string(name);
 155  211  
 156  212          if (!expr_to_mtag_offset(expr->left, &tag, &offset))
 157  213                  return;
 158  214  
↓ open down ↓ 112 lines elided ↑ open up ↑
 271  327          if (invalid_type(type))
 272  328                  return 0;
 273  329  
 274  330          return get_rl_from_mtag_offset(tag, offset, type, rl);
 275  331  }
 276  332  
 277  333  void register_mtag_data(int id)
 278  334  {
 279  335          my_id = id;
 280  336  
      337 +        ignored_mtag = str_to_mtag("extern boot_params");
 281  338          add_hook(&clear_cache, FUNC_DEF_HOOK);
 282  339  
 283  340  //      if (!option_info)
 284  341  //              return;
 285  342          add_hook(&match_global_assign, GLOBAL_ASSIGNMENT_HOOK);
 286  343          add_hook(&match_end_file, END_FILE_HOOK);
 287  344  }
 288  345  
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX