3 * modules/us_manager/img/img_file.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin: SWAP us_manager implement
28 #include <linux/slab.h>
29 #include <linux/dcache.h>
32 static void img_del_ip_by_list(struct img_ip *ip);
35 * @brief Create img_file struct
37 * @param dentry Dentry of file
38 * @return Pointer to the created img_file struct
40 struct img_file *create_img_file(struct dentry *dentry)
42 struct img_file *file;
44 file = kmalloc(sizeof(*file), GFP_ATOMIC);
46 pr_err("%s: failed to allocate memory\n", __func__);
50 file->dentry = dentry;
51 INIT_LIST_HEAD(&file->ip_list);
52 INIT_LIST_HEAD(&file->list);
58 * @brief Remove img_file struct
60 * @param file remove object
63 void free_img_file(struct img_file *file)
65 struct img_ip *ip, *tmp;
67 list_for_each_entry_safe(ip, tmp, &file->ip_list, list) {
68 img_del_ip_by_list(ip);
75 static void img_add_ip_by_list(struct img_file *file, struct img_ip *ip)
77 list_add(&ip->list, &file->ip_list);
80 static void img_del_ip_by_list(struct img_ip *ip)
85 static struct img_ip *find_img_ip(struct img_file *file, unsigned long addr)
89 list_for_each_entry(ip, &file->ip_list, list) {
98 * @brief Add instrumentation pointer
100 * @param file Pointer to the img_file struct
101 * @param addr Function address
102 * @param probe_Pointer to a probe_info structure with an information about
106 int img_file_add_ip(struct img_file *file, unsigned long addr,
107 struct probe_info *probe_i)
111 ip = find_img_ip(file, addr);
113 /* ip already exists in img */
117 ip = create_img_ip(addr, probe_i);
121 img_add_ip_by_list(file, ip);
127 * @brief Delete img_ip struct from img_file struct
129 * @param file Pointer to the img_file struct
130 * @param addr Function address
133 int img_file_del_ip(struct img_file *file, unsigned long addr)
137 ip = find_img_ip(file, addr);
139 printk(KERN_INFO "Warning: no ip found in img, addr = %lx\n",
144 img_del_ip_by_list(ip);
150 * @brief Check on absence img_ip structs in img_file struct
152 * @param file Pointer to the img_file struct
157 int img_file_empty(struct img_file *file)
159 return list_empty(&file->ip_list);
165 * @param file Pointer to the img_file struct
170 void img_file_print(struct img_file *file)
174 printk(KERN_INFO "### d_iname=%s\n", file->dentry->d_iname);
176 list_for_each_entry(ip, &file->ip_list, list) {