blob: e73b1fef897dc84eefd0e2cfb8cd512948ebcddf [file] [log] [blame]
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +04001/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Artem Bityutskiy (Битюцкий Артём)
19 */
20
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040021#include "ubi.h"
Artem Bityutskiy2a734bb2011-05-18 14:53:05 +030022#include <linux/debugfs.h>
23#include <linux/uaccess.h>
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020024#include <linux/module.h>
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040025
Artem Bityutskiyef7088e2012-04-24 07:10:33 +030026
27/**
28 * ubi_dump_flash - dump a region of flash.
29 * @ubi: UBI device description object
30 * @pnum: the physical eraseblock number to dump
31 * @offset: the starting offset within the physical eraseblock to dump
32 * @len: the length of the region to dump
33 */
34void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
35{
36 int err;
37 size_t read;
38 void *buf;
39 loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
40
41 buf = vmalloc(len);
42 if (!buf)
43 return;
44 err = mtd_read(ubi->mtd, addr, len, &read, buf);
45 if (err && err != -EUCLEAN) {
46 ubi_err("error %d while reading %d bytes from PEB %d:%d, "
47 "read %zd bytes", err, len, pnum, offset, read);
48 goto out;
49 }
50
51 ubi_msg("dumping %d bytes of data from PEB %d, offset %d",
52 len, pnum, offset);
53 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
54out:
55 vfree(buf);
56 return;
57}
58
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040059/**
Artem Bityutskiya904e3f2012-04-25 09:02:44 +030060 * ubi_dump_ec_hdr - dump an erase counter header.
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040061 * @ec_hdr: the erase counter header to dump
62 */
Artem Bityutskiya904e3f2012-04-25 09:02:44 +030063void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040064{
Artem Bityutskiyc8566352008-07-16 17:40:22 +030065 printk(KERN_DEBUG "Erase counter header dump:\n");
66 printk(KERN_DEBUG "\tmagic %#08x\n",
67 be32_to_cpu(ec_hdr->magic));
68 printk(KERN_DEBUG "\tversion %d\n", (int)ec_hdr->version);
69 printk(KERN_DEBUG "\tec %llu\n",
70 (long long)be64_to_cpu(ec_hdr->ec));
71 printk(KERN_DEBUG "\tvid_hdr_offset %d\n",
72 be32_to_cpu(ec_hdr->vid_hdr_offset));
73 printk(KERN_DEBUG "\tdata_offset %d\n",
74 be32_to_cpu(ec_hdr->data_offset));
Adrian Hunter0c6c7fa2009-06-26 14:58:01 +030075 printk(KERN_DEBUG "\timage_seq %d\n",
76 be32_to_cpu(ec_hdr->image_seq));
Artem Bityutskiyc8566352008-07-16 17:40:22 +030077 printk(KERN_DEBUG "\thdr_crc %#08x\n",
78 be32_to_cpu(ec_hdr->hdr_crc));
79 printk(KERN_DEBUG "erase counter header hexdump:\n");
Artem Bityutskiy69866462007-08-29 14:56:20 +030080 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
81 ec_hdr, UBI_EC_HDR_SIZE, 1);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040082}
83
84/**
Artem Bityutskiya904e3f2012-04-25 09:02:44 +030085 * ubi_dump_vid_hdr - dump a volume identifier header.
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040086 * @vid_hdr: the volume identifier header to dump
87 */
Artem Bityutskiya904e3f2012-04-25 09:02:44 +030088void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040089{
Artem Bityutskiyc8566352008-07-16 17:40:22 +030090 printk(KERN_DEBUG "Volume identifier header dump:\n");
91 printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic));
Artem Bityutskiyfeddbb32011-03-28 10:12:25 +030092 printk(KERN_DEBUG "\tversion %d\n", (int)vid_hdr->version);
93 printk(KERN_DEBUG "\tvol_type %d\n", (int)vid_hdr->vol_type);
94 printk(KERN_DEBUG "\tcopy_flag %d\n", (int)vid_hdr->copy_flag);
95 printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat);
96 printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id));
97 printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum));
98 printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size));
99 printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs));
100 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad));
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300101 printk(KERN_DEBUG "\tsqnum %llu\n",
Christoph Hellwig3261ebd2007-05-21 17:41:46 +0300102 (unsigned long long)be64_to_cpu(vid_hdr->sqnum));
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300103 printk(KERN_DEBUG "\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc));
104 printk(KERN_DEBUG "Volume identifier header hexdump:\n");
105 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
106 vid_hdr, UBI_VID_HDR_SIZE, 1);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400107}
108
109/**
Artem Bityutskiy766381f2012-05-16 17:53:17 +0300110 * ubi_dump_vol_info - dump volume information.
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400111 * @vol: UBI volume description object
112 */
Artem Bityutskiy766381f2012-05-16 17:53:17 +0300113void ubi_dump_vol_info(const struct ubi_volume *vol)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400114{
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300115 printk(KERN_DEBUG "Volume information dump:\n");
116 printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id);
117 printk(KERN_DEBUG "\treserved_pebs %d\n", vol->reserved_pebs);
118 printk(KERN_DEBUG "\talignment %d\n", vol->alignment);
119 printk(KERN_DEBUG "\tdata_pad %d\n", vol->data_pad);
120 printk(KERN_DEBUG "\tvol_type %d\n", vol->vol_type);
121 printk(KERN_DEBUG "\tname_len %d\n", vol->name_len);
122 printk(KERN_DEBUG "\tusable_leb_size %d\n", vol->usable_leb_size);
123 printk(KERN_DEBUG "\tused_ebs %d\n", vol->used_ebs);
124 printk(KERN_DEBUG "\tused_bytes %lld\n", vol->used_bytes);
125 printk(KERN_DEBUG "\tlast_eb_bytes %d\n", vol->last_eb_bytes);
126 printk(KERN_DEBUG "\tcorrupted %d\n", vol->corrupted);
127 printk(KERN_DEBUG "\tupd_marker %d\n", vol->upd_marker);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400128
129 if (vol->name_len <= UBI_VOL_NAME_MAX &&
130 strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300131 printk(KERN_DEBUG "\tname %s\n", vol->name);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400132 } else {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300133 printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
134 vol->name[0], vol->name[1], vol->name[2],
135 vol->name[3], vol->name[4]);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400136 }
137}
138
139/**
Artem Bityutskiy1f021e1d2012-05-16 17:56:50 +0300140 * ubi_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400141 * @r: the object to dump
142 * @idx: volume table index
143 */
Artem Bityutskiy1f021e1d2012-05-16 17:56:50 +0300144void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400145{
Christoph Hellwig3261ebd2007-05-21 17:41:46 +0300146 int name_len = be16_to_cpu(r->name_len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400147
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300148 printk(KERN_DEBUG "Volume table record %d dump:\n", idx);
149 printk(KERN_DEBUG "\treserved_pebs %d\n",
150 be32_to_cpu(r->reserved_pebs));
151 printk(KERN_DEBUG "\talignment %d\n", be32_to_cpu(r->alignment));
152 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(r->data_pad));
153 printk(KERN_DEBUG "\tvol_type %d\n", (int)r->vol_type);
154 printk(KERN_DEBUG "\tupd_marker %d\n", (int)r->upd_marker);
155 printk(KERN_DEBUG "\tname_len %d\n", name_len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400156
157 if (r->name[0] == '\0') {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300158 printk(KERN_DEBUG "\tname NULL\n");
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400159 return;
160 }
161
162 if (name_len <= UBI_VOL_NAME_MAX &&
163 strnlen(&r->name[0], name_len + 1) == name_len) {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300164 printk(KERN_DEBUG "\tname %s\n", &r->name[0]);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400165 } else {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300166 printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400167 r->name[0], r->name[1], r->name[2], r->name[3],
168 r->name[4]);
169 }
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300170 printk(KERN_DEBUG "\tcrc %#08x\n", be32_to_cpu(r->crc));
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400171}
172
173/**
Artem Bityutskiycb28a932012-05-17 06:59:30 +0300174 * ubi_dump_sv - dump a &struct ubi_ainf_volume object.
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400175 * @sv: the object to dump
176 */
Artem Bityutskiycb28a932012-05-17 06:59:30 +0300177void ubi_dump_sv(const struct ubi_ainf_volume *sv)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400178{
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300179 printk(KERN_DEBUG "Volume scanning information dump:\n");
180 printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id);
181 printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum);
182 printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count);
183 printk(KERN_DEBUG "\tcompat %d\n", sv->compat);
184 printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type);
185 printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs);
186 printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size);
187 printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400188}
189
190/**
Artem Bityutskiy2c5ec5c2012-05-17 08:26:24 +0300191 * ubi_dump_aeb - dump a &struct ubi_ainf_peb object.
192 * @aeb: the object to dump
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400193 * @type: object type: 0 - not corrupted, 1 - corrupted
194 */
Artem Bityutskiy2c5ec5c2012-05-17 08:26:24 +0300195void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400196{
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300197 printk(KERN_DEBUG "eraseblock scanning information dump:\n");
Artem Bityutskiy2c5ec5c2012-05-17 08:26:24 +0300198 printk(KERN_DEBUG "\tec %d\n", aeb->ec);
199 printk(KERN_DEBUG "\tpnum %d\n", aeb->pnum);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400200 if (type == 0) {
Artem Bityutskiy2c5ec5c2012-05-17 08:26:24 +0300201 printk(KERN_DEBUG "\tlnum %d\n", aeb->lnum);
202 printk(KERN_DEBUG "\tscrub %d\n", aeb->scrub);
203 printk(KERN_DEBUG "\tsqnum %llu\n", aeb->sqnum);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400204 }
205}
206
207/**
Artem Bityutskiy718c00b2012-05-16 18:03:32 +0300208 * ubi_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400209 * @req: the object to dump
210 */
Artem Bityutskiy718c00b2012-05-16 18:03:32 +0300211void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400212{
213 char nm[17];
214
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300215 printk(KERN_DEBUG "Volume creation request dump:\n");
216 printk(KERN_DEBUG "\tvol_id %d\n", req->vol_id);
217 printk(KERN_DEBUG "\talignment %d\n", req->alignment);
218 printk(KERN_DEBUG "\tbytes %lld\n", (long long)req->bytes);
219 printk(KERN_DEBUG "\tvol_type %d\n", req->vol_type);
220 printk(KERN_DEBUG "\tname_len %d\n", req->name_len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400221
222 memcpy(nm, req->name, 16);
223 nm[16] = 0;
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300224 printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400225}
226
Artem Bityutskiy867996b2009-07-24 15:31:33 +0300227/**
Artem Bityutskiy2a734bb2011-05-18 14:53:05 +0300228 * ubi_debugging_init_dev - initialize debugging for an UBI device.
229 * @ubi: UBI device description object
230 *
231 * This function initializes debugging-related data for UBI device @ubi.
232 * Returns zero in case of success and a negative error code in case of
233 * failure.
234 */
235int ubi_debugging_init_dev(struct ubi_device *ubi)
236{
237 ubi->dbg = kzalloc(sizeof(struct ubi_debug_info), GFP_KERNEL);
238 if (!ubi->dbg)
239 return -ENOMEM;
240
241 return 0;
242}
243
244/**
245 * ubi_debugging_exit_dev - free debugging data for an UBI device.
246 * @ubi: UBI device description object
247 */
248void ubi_debugging_exit_dev(struct ubi_device *ubi)
249{
250 kfree(ubi->dbg);
251}
252
253/*
254 * Root directory for UBI stuff in debugfs. Contains sub-directories which
255 * contain the stuff specific to particular UBI devices.
256 */
257static struct dentry *dfs_rootdir;
258
259/**
260 * ubi_debugfs_init - create UBI debugfs directory.
261 *
262 * Create UBI debugfs directory. Returns zero in case of success and a negative
263 * error code in case of failure.
264 */
265int ubi_debugfs_init(void)
266{
267 dfs_rootdir = debugfs_create_dir("ubi", NULL);
268 if (IS_ERR_OR_NULL(dfs_rootdir)) {
269 int err = dfs_rootdir ? -ENODEV : PTR_ERR(dfs_rootdir);
270
271 ubi_err("cannot create \"ubi\" debugfs directory, error %d\n",
272 err);
273 return err;
274 }
275
276 return 0;
277}
278
279/**
280 * ubi_debugfs_exit - remove UBI debugfs directory.
281 */
282void ubi_debugfs_exit(void)
283{
284 debugfs_remove(dfs_rootdir);
285}
286
287/* Read an UBI debugfs file */
288static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
289 size_t count, loff_t *ppos)
290{
291 unsigned long ubi_num = (unsigned long)file->private_data;
292 struct dentry *dent = file->f_path.dentry;
293 struct ubi_device *ubi;
294 struct ubi_debug_info *d;
295 char buf[3];
296 int val;
297
298 ubi = ubi_get_device(ubi_num);
299 if (!ubi)
300 return -ENODEV;
301 d = ubi->dbg;
302
303 if (dent == d->dfs_chk_gen)
304 val = d->chk_gen;
305 else if (dent == d->dfs_chk_io)
306 val = d->chk_io;
Artem Bityutskiycd6d8562011-05-18 16:21:43 +0300307 else if (dent == d->dfs_disable_bgt)
308 val = d->disable_bgt;
309 else if (dent == d->dfs_emulate_bitflips)
310 val = d->emulate_bitflips;
311 else if (dent == d->dfs_emulate_io_failures)
312 val = d->emulate_io_failures;
Artem Bityutskiy2a734bb2011-05-18 14:53:05 +0300313 else {
314 count = -EINVAL;
315 goto out;
316 }
317
318 if (val)
319 buf[0] = '1';
320 else
321 buf[0] = '0';
322 buf[1] = '\n';
323 buf[2] = 0x00;
324
325 count = simple_read_from_buffer(user_buf, count, ppos, buf, 2);
326
327out:
328 ubi_put_device(ubi);
329 return count;
330}
331
332/* Write an UBI debugfs file */
333static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
334 size_t count, loff_t *ppos)
335{
336 unsigned long ubi_num = (unsigned long)file->private_data;
337 struct dentry *dent = file->f_path.dentry;
338 struct ubi_device *ubi;
339 struct ubi_debug_info *d;
340 size_t buf_size;
341 char buf[8];
342 int val;
343
344 ubi = ubi_get_device(ubi_num);
345 if (!ubi)
346 return -ENODEV;
347 d = ubi->dbg;
348
349 buf_size = min_t(size_t, count, (sizeof(buf) - 1));
350 if (copy_from_user(buf, user_buf, buf_size)) {
351 count = -EFAULT;
352 goto out;
353 }
354
355 if (buf[0] == '1')
356 val = 1;
357 else if (buf[0] == '0')
358 val = 0;
359 else {
360 count = -EINVAL;
361 goto out;
362 }
363
364 if (dent == d->dfs_chk_gen)
365 d->chk_gen = val;
366 else if (dent == d->dfs_chk_io)
367 d->chk_io = val;
Artem Bityutskiycd6d8562011-05-18 16:21:43 +0300368 else if (dent == d->dfs_disable_bgt)
369 d->disable_bgt = val;
370 else if (dent == d->dfs_emulate_bitflips)
371 d->emulate_bitflips = val;
372 else if (dent == d->dfs_emulate_io_failures)
373 d->emulate_io_failures = val;
Artem Bityutskiy2a734bb2011-05-18 14:53:05 +0300374 else
375 count = -EINVAL;
376
377out:
378 ubi_put_device(ubi);
379 return count;
380}
381
Artem Bityutskiy2a734bb2011-05-18 14:53:05 +0300382/* File operations for all UBI debugfs files */
383static const struct file_operations dfs_fops = {
384 .read = dfs_file_read,
385 .write = dfs_file_write,
Stephen Boyd234e3402012-04-05 14:25:11 -0700386 .open = simple_open,
Artem Bityutskiy2a734bb2011-05-18 14:53:05 +0300387 .llseek = no_llseek,
388 .owner = THIS_MODULE,
389};
390
391/**
392 * ubi_debugfs_init_dev - initialize debugfs for an UBI device.
393 * @ubi: UBI device description object
394 *
395 * This function creates all debugfs files for UBI device @ubi. Returns zero in
396 * case of success and a negative error code in case of failure.
397 */
398int ubi_debugfs_init_dev(struct ubi_device *ubi)
399{
400 int err, n;
401 unsigned long ubi_num = ubi->ubi_num;
402 const char *fname;
403 struct dentry *dent;
404 struct ubi_debug_info *d = ubi->dbg;
405
406 n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN + 1, UBI_DFS_DIR_NAME,
407 ubi->ubi_num);
408 if (n == UBI_DFS_DIR_LEN) {
409 /* The array size is too small */
410 fname = UBI_DFS_DIR_NAME;
411 dent = ERR_PTR(-EINVAL);
412 goto out;
413 }
414
415 fname = d->dfs_dir_name;
416 dent = debugfs_create_dir(fname, dfs_rootdir);
417 if (IS_ERR_OR_NULL(dent))
418 goto out;
419 d->dfs_dir = dent;
420
421 fname = "chk_gen";
422 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
423 &dfs_fops);
424 if (IS_ERR_OR_NULL(dent))
425 goto out_remove;
426 d->dfs_chk_gen = dent;
427
428 fname = "chk_io";
429 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
430 &dfs_fops);
431 if (IS_ERR_OR_NULL(dent))
432 goto out_remove;
433 d->dfs_chk_io = dent;
434
Artem Bityutskiycd6d8562011-05-18 16:21:43 +0300435 fname = "tst_disable_bgt";
436 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
437 &dfs_fops);
438 if (IS_ERR_OR_NULL(dent))
439 goto out_remove;
440 d->dfs_disable_bgt = dent;
441
442 fname = "tst_emulate_bitflips";
443 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
444 &dfs_fops);
445 if (IS_ERR_OR_NULL(dent))
446 goto out_remove;
447 d->dfs_emulate_bitflips = dent;
448
449 fname = "tst_emulate_io_failures";
450 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
451 &dfs_fops);
452 if (IS_ERR_OR_NULL(dent))
453 goto out_remove;
454 d->dfs_emulate_io_failures = dent;
455
Artem Bityutskiy2a734bb2011-05-18 14:53:05 +0300456 return 0;
457
458out_remove:
459 debugfs_remove_recursive(d->dfs_dir);
460out:
461 err = dent ? PTR_ERR(dent) : -ENODEV;
462 ubi_err("cannot create \"%s\" debugfs file or directory, error %d\n",
463 fname, err);
464 return err;
465}
466
467/**
468 * dbg_debug_exit_dev - free all debugfs files corresponding to device @ubi
469 * @ubi: UBI device description object
470 */
471void ubi_debugfs_exit_dev(struct ubi_device *ubi)
472{
473 debugfs_remove_recursive(ubi->dbg->dfs_dir);
474}