2 * smatch/check_container_of.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
10 * Some macros don't return NULL pointers. Complain if people
11 * check the results for NULL because obviously the programmers
12 * don't know what the pants they're doing.
21 static void is_ok(const char *name
, struct symbol
*sym
, struct expression
*expr
, void *unused
)
23 set_state(my_id
, name
, sym
, &undefined
);
26 static void match_non_null(const char *fn
, struct expression
*expr
, void *unused
)
28 set_state_expr(my_id
, expr
->left
, &non_null
);
31 static void match_condition(struct expression
*expr
)
33 if (__in_pre_condition
)
36 if (get_macro_name(&expr
->pos
))
39 if (get_state_expr(my_id
, expr
) == &non_null
) {
42 name
= get_variable_from_expr(expr
, NULL
);
43 sm_msg("warn: can '%s' even be NULL?", name
);
44 set_state_expr(my_id
, expr
, &undefined
);
49 void check_container_of(int id
)
51 if (option_project
!= PROJ_KERNEL
)
55 add_macro_assign_hook("container_of", &match_non_null
, NULL
);
56 add_macro_assign_hook("list_first_entry", &match_non_null
, NULL
);
57 set_default_modification_hook(my_id
, &is_ok
);
58 add_hook(&match_condition
, CONDITION_HOOK
);