sval: cast bitwise negates
[smatch.git] / check_gfp_dma.c
blobf6df3e129c2f279fa53268a08958b83c8e639c55
1 /*
2 * sparse/check_gfp_dma.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 /* this is stolen from the kernel but it's totally fair use dude... */
15 #define __GFP_DMA (0x01u)
16 #define __GFP_HIGHMEM (0x02u)
17 #define __GFP_DMA32 (0x04u)
18 #define __GFP_MOVABLE (0x08u)
19 #define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE)
21 static void match_alloc(const char *fn, struct expression *expr, void *_arg)
23 int arg_nr = PTR_INT(_arg);
24 struct expression *arg_expr;
25 sval_t sval;
27 arg_expr = get_argument_from_call_expr(expr->args, arg_nr);
28 if (!get_value(arg_expr, &sval))
29 return;
30 if (sval.uvalue == 0) /* GFP_NOWAIT */
31 return;
32 if (!(sval.uvalue & ~GFP_ZONEMASK))
33 sm_msg("error: no modifiers for allocation.");
36 void check_gfp_dma(int id)
38 my_id = id;
39 if (option_project != PROJ_KERNEL)
40 return;
41 add_function_hook("kmalloc", &match_alloc, INT_PTR(1));
42 add_function_hook("kzalloc", &match_alloc, INT_PTR(1));