2 * sparse/check_struct_type.c
4 * Copyright (C) 2013 Oracle.
6 * Licensed under the Open Software License version 1.1
14 static void match_assign(const char *fn
, struct expression
*expr
, void *_size_arg
)
16 int size_arg
= PTR_INT(_size_arg
);
17 struct expression
*left
;
18 struct expression
*call
;
19 struct expression
*arg
;
20 struct symbol
*left_type
;
21 struct symbol
*size_type
;
23 left
= strip_expr(expr
->left
);
24 left_type
= get_type(left
);
25 if (!left_type
|| left_type
->type
!= SYM_PTR
)
27 left_type
= get_real_base_type(left_type
);
28 if (!left_type
|| left_type
->type
!= SYM_STRUCT
)
31 call
= strip_expr(expr
->right
);
32 arg
= get_argument_from_call_expr(call
->args
, size_arg
);
33 if (!arg
|| arg
->type
!= EXPR_SIZEOF
|| !arg
->cast_type
)
35 size_type
= arg
->cast_type
;
36 if (size_type
->type
!= SYM_NODE
)
38 size_type
= get_real_base_type(size_type
);
39 if (size_type
->type
!= SYM_STRUCT
)
41 if (strcmp(left_type
->ident
->name
, size_type
->ident
->name
) == 0)
43 sm_msg("warn: struct type mismatch '%s vs %s'", left_type
->ident
->name
,
44 size_type
->ident
->name
);
48 void check_struct_type(int id
)
52 if (option_project
== PROJ_KERNEL
) {
53 add_function_assign_hook("kmalloc", &match_assign
, INT_PTR(0));
54 add_function_assign_hook("kzalloc", &match_assign
, INT_PTR(0));