205 if (!sval_is_a_max(tmp_max) && sval_cmp(tmp_max, max) > 0)
206 max = tmp_max;
207 } END_FOR_EACH_PTR(tmp);
208 if (sval_is_negative(min) && sval_cmp_val(min, -4095) < 0)
209 sm_error("%s too low for ERR_PTR", sval_to_str(min));
210 if (sval_is_positive(max) && sval_cmp_val(max, 0) != 0)
211 sm_error("passing non negative %s to ERR_PTR", sval_to_str(max));
212 }
213
214 void check_err_ptr_deref(int id)
215 {
216 if (option_project != PROJ_KERNEL)
217 return;
218
219 my_id = id;
220 return_implies_state("IS_ERR", 0, 0, &match_checked, NULL);
221 return_implies_state("IS_ERR", 1, 1, &match_err, NULL);
222 return_implies_state("IS_ERR_OR_NULL", 0, 0, &match_checked, NULL);
223 return_implies_state("IS_ERR_OR_NULL", 1, 1, &match_err, NULL);
224 return_implies_state("PTR_RET", 0, 0, &match_checked, NULL);
225 return_implies_state("PTR_RET", -4096, -1, &match_err, NULL);
226 register_err_ptr_funcs();
227 add_hook(&match_dereferences, DEREF_HOOK);
228 add_function_hook("ERR_PTR", &match_err_ptr_positive_const, NULL);
229 add_function_hook("ERR_PTR", &match_err_ptr, NULL);
230 add_hook(&match_condition, CONDITION_HOOK);
231 add_modification_hook(my_id, &ok_to_use);
232 add_function_hook("kfree", &match_kfree, INT_PTR(0));
233 add_function_hook("brelse", &match_kfree, INT_PTR(0));
234 add_function_hook("kmem_cache_free", &match_kfree, INT_PTR(1));
235 add_function_hook("vfree", &match_kfree, INT_PTR(0));
236
237 err_ptr_rl = clone_rl_permanent(alloc_rl(err_ptr_min, err_ptr_max));
238
239 select_return_implies_hook(DEREFERENCE, &set_param_dereferenced);
240 }
241
|
205 if (!sval_is_a_max(tmp_max) && sval_cmp(tmp_max, max) > 0)
206 max = tmp_max;
207 } END_FOR_EACH_PTR(tmp);
208 if (sval_is_negative(min) && sval_cmp_val(min, -4095) < 0)
209 sm_error("%s too low for ERR_PTR", sval_to_str(min));
210 if (sval_is_positive(max) && sval_cmp_val(max, 0) != 0)
211 sm_error("passing non negative %s to ERR_PTR", sval_to_str(max));
212 }
213
214 void check_err_ptr_deref(int id)
215 {
216 if (option_project != PROJ_KERNEL)
217 return;
218
219 my_id = id;
220 return_implies_state("IS_ERR", 0, 0, &match_checked, NULL);
221 return_implies_state("IS_ERR", 1, 1, &match_err, NULL);
222 return_implies_state("IS_ERR_OR_NULL", 0, 0, &match_checked, NULL);
223 return_implies_state("IS_ERR_OR_NULL", 1, 1, &match_err, NULL);
224 return_implies_state("PTR_RET", 0, 0, &match_checked, NULL);
225 return_implies_state("PTR_RET", -4095, -1, &match_err, NULL);
226 register_err_ptr_funcs();
227 add_hook(&match_dereferences, DEREF_HOOK);
228 add_function_hook("ERR_PTR", &match_err_ptr_positive_const, NULL);
229 add_function_hook("ERR_PTR", &match_err_ptr, NULL);
230 add_hook(&match_condition, CONDITION_HOOK);
231 add_modification_hook(my_id, &ok_to_use);
232 add_function_hook("kfree", &match_kfree, INT_PTR(0));
233 add_function_hook("brelse", &match_kfree, INT_PTR(0));
234 add_function_hook("kmem_cache_free", &match_kfree, INT_PTR(1));
235 add_function_hook("vfree", &match_kfree, INT_PTR(0));
236
237 err_ptr_rl = clone_rl_permanent(alloc_rl(err_ptr_min, err_ptr_max));
238
239 select_return_implies_hook(DEREFERENCE, &set_param_dereferenced);
240 }
241
|