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,
86 struct probe_desc *pd)
90 list_for_each_entry(ip, &file->ip_list, list) {
91 if ((ip->addr == addr) &&
100 * @brief Add instrumentation pointer
102 * @param file Pointer to the img_file struct
103 * @param addr Function address
104 * @param probe_Pointer to a probe_info structure with an information about
108 int img_file_add_ip(struct img_file *file, unsigned long addr,
109 struct probe_desc *pd)
113 ip = find_img_ip(file, addr, pd);
115 /* ip already exists in img */
119 ip = create_img_ip(addr, pd);
122 img_add_ip_by_list(file, ip);
128 * @brief Delete img_ip struct from img_file struct
130 * @param file Pointer to the img_file struct
131 * @param addr Function address
134 int img_file_del_ip(struct img_file *file, unsigned long addr,
135 struct probe_desc *pd)
139 ip = find_img_ip(file, addr, pd);
141 printk(KERN_INFO "Warning: no ip found in img, addr = %lx\n",
146 img_del_ip_by_list(ip);
153 * @brief Check on absence img_ip structs in img_file struct
155 * @param file Pointer to the img_file struct
160 int img_file_empty(struct img_file *file)
162 return list_empty(&file->ip_list);
168 * @param file Pointer to the img_file struct
173 void img_file_print(struct img_file *file)
177 printk(KERN_INFO "### d_iname=%s\n", file->dentry->d_iname);
179 list_for_each_entry(ip, &file->ip_list, list) {