Commit eab73772 authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by Artem Bityutskiy

UBI: embed ubi_debug_info field in ubi_device struct

ubi_debug_info struct was dynamically allocated which
is always suboptimal, for it tends to fragment memory
and make the code error-prone.
Fix this by embedding it in ubi_device struct.
Signed-off-by: default avatarEzequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
parent 64575574
...@@ -985,14 +985,10 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, ...@@ -985,14 +985,10 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
if (!ubi->fm_buf) if (!ubi->fm_buf)
goto out_free; goto out_free;
#endif #endif
err = ubi_debugging_init_dev(ubi);
if (err)
goto out_free;
err = ubi_attach(ubi, 0); err = ubi_attach(ubi, 0);
if (err) { if (err) {
ubi_err("failed to attach mtd%d, error %d", mtd->index, err); ubi_err("failed to attach mtd%d, error %d", mtd->index, err);
goto out_debugging; goto out_free;
} }
if (ubi->autoresize_vol_id != -1) { if (ubi->autoresize_vol_id != -1) {
...@@ -1059,8 +1055,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, ...@@ -1059,8 +1055,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
ubi_wl_close(ubi); ubi_wl_close(ubi);
ubi_free_internal_volumes(ubi); ubi_free_internal_volumes(ubi);
vfree(ubi->vtbl); vfree(ubi->vtbl);
out_debugging:
ubi_debugging_exit_dev(ubi);
out_free: out_free:
vfree(ubi->peb_buf); vfree(ubi->peb_buf);
vfree(ubi->fm_buf); vfree(ubi->fm_buf);
...@@ -1138,7 +1132,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) ...@@ -1138,7 +1132,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
ubi_free_internal_volumes(ubi); ubi_free_internal_volumes(ubi);
vfree(ubi->vtbl); vfree(ubi->vtbl);
put_mtd_device(ubi->mtd); put_mtd_device(ubi->mtd);
ubi_debugging_exit_dev(ubi);
vfree(ubi->peb_buf); vfree(ubi->peb_buf);
vfree(ubi->fm_buf); vfree(ubi->fm_buf);
ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
......
...@@ -217,32 +217,6 @@ void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req) ...@@ -217,32 +217,6 @@ void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req)
pr_err("\t1st 16 characters of name: %s\n", nm); pr_err("\t1st 16 characters of name: %s\n", nm);
} }
/**
* ubi_debugging_init_dev - initialize debugging for an UBI device.
* @ubi: UBI device description object
*
* This function initializes debugging-related data for UBI device @ubi.
* Returns zero in case of success and a negative error code in case of
* failure.
*/
int ubi_debugging_init_dev(struct ubi_device *ubi)
{
ubi->dbg = kzalloc(sizeof(struct ubi_debug_info), GFP_KERNEL);
if (!ubi->dbg)
return -ENOMEM;
return 0;
}
/**
* ubi_debugging_exit_dev - free debugging data for an UBI device.
* @ubi: UBI device description object
*/
void ubi_debugging_exit_dev(struct ubi_device *ubi)
{
kfree(ubi->dbg);
}
/* /*
* Root directory for UBI stuff in debugfs. Contains sub-directories which * Root directory for UBI stuff in debugfs. Contains sub-directories which
* contain the stuff specific to particular UBI devices. * contain the stuff specific to particular UBI devices.
...@@ -295,7 +269,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf, ...@@ -295,7 +269,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
ubi = ubi_get_device(ubi_num); ubi = ubi_get_device(ubi_num);
if (!ubi) if (!ubi)
return -ENODEV; return -ENODEV;
d = ubi->dbg; d = &ubi->dbg;
if (dent == d->dfs_chk_gen) if (dent == d->dfs_chk_gen)
val = d->chk_gen; val = d->chk_gen;
...@@ -341,7 +315,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf, ...@@ -341,7 +315,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
ubi = ubi_get_device(ubi_num); ubi = ubi_get_device(ubi_num);
if (!ubi) if (!ubi)
return -ENODEV; return -ENODEV;
d = ubi->dbg; d = &ubi->dbg;
buf_size = min_t(size_t, count, (sizeof(buf) - 1)); buf_size = min_t(size_t, count, (sizeof(buf) - 1));
if (copy_from_user(buf, user_buf, buf_size)) { if (copy_from_user(buf, user_buf, buf_size)) {
...@@ -398,7 +372,7 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi) ...@@ -398,7 +372,7 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
unsigned long ubi_num = ubi->ubi_num; unsigned long ubi_num = ubi->ubi_num;
const char *fname; const char *fname;
struct dentry *dent; struct dentry *dent;
struct ubi_debug_info *d = ubi->dbg; struct ubi_debug_info *d = &ubi->dbg;
if (!IS_ENABLED(CONFIG_DEBUG_FS)) if (!IS_ENABLED(CONFIG_DEBUG_FS))
return 0; return 0;
...@@ -471,5 +445,5 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi) ...@@ -471,5 +445,5 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
void ubi_debugfs_exit_dev(struct ubi_device *ubi) void ubi_debugfs_exit_dev(struct ubi_device *ubi)
{ {
if (IS_ENABLED(CONFIG_DEBUG_FS)) if (IS_ENABLED(CONFIG_DEBUG_FS))
debugfs_remove_recursive(ubi->dbg->dfs_dir); debugfs_remove_recursive(ubi->dbg.dfs_dir);
} }
...@@ -60,51 +60,11 @@ void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type); ...@@ -60,51 +60,11 @@ void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req); void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
int len); int len);
int ubi_debugging_init_dev(struct ubi_device *ubi);
void ubi_debugging_exit_dev(struct ubi_device *ubi);
int ubi_debugfs_init(void); int ubi_debugfs_init(void);
void ubi_debugfs_exit(void); void ubi_debugfs_exit(void);
int ubi_debugfs_init_dev(struct ubi_device *ubi); int ubi_debugfs_init_dev(struct ubi_device *ubi);
void ubi_debugfs_exit_dev(struct ubi_device *ubi); void ubi_debugfs_exit_dev(struct ubi_device *ubi);
/*
* The UBI debugfs directory name pattern and maximum name length (3 for "ubi"
* + 2 for the number plus 1 for the trailing zero byte.
*/
#define UBI_DFS_DIR_NAME "ubi%d"
#define UBI_DFS_DIR_LEN (3 + 2 + 1)
/**
* struct ubi_debug_info - debugging information for an UBI device.
*
* @chk_gen: if UBI general extra checks are enabled
* @chk_io: if UBI I/O extra checks are enabled
* @disable_bgt: disable the background task for testing purposes
* @emulate_bitflips: emulate bit-flips for testing purposes
* @emulate_io_failures: emulate write/erase failures for testing purposes
* @dfs_dir_name: name of debugfs directory containing files of this UBI device
* @dfs_dir: direntry object of the UBI device debugfs directory
* @dfs_chk_gen: debugfs knob to enable UBI general extra checks
* @dfs_chk_io: debugfs knob to enable UBI I/O extra checks
* @dfs_disable_bgt: debugfs knob to disable the background task
* @dfs_emulate_bitflips: debugfs knob to emulate bit-flips
* @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures
*/
struct ubi_debug_info {
unsigned int chk_gen:1;
unsigned int chk_io:1;
unsigned int disable_bgt:1;
unsigned int emulate_bitflips:1;
unsigned int emulate_io_failures:1;
char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
struct dentry *dfs_dir;
struct dentry *dfs_chk_gen;
struct dentry *dfs_chk_io;
struct dentry *dfs_disable_bgt;
struct dentry *dfs_emulate_bitflips;
struct dentry *dfs_emulate_io_failures;
};
/** /**
* ubi_dbg_is_bgt_disabled - if the background thread is disabled. * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
* @ubi: UBI device description object * @ubi: UBI device description object
...@@ -114,7 +74,7 @@ struct ubi_debug_info { ...@@ -114,7 +74,7 @@ struct ubi_debug_info {
*/ */
static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
{ {
return ubi->dbg->disable_bgt; return ubi->dbg.disable_bgt;
} }
/** /**
...@@ -125,7 +85,7 @@ static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) ...@@ -125,7 +85,7 @@ static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
*/ */
static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
{ {
if (ubi->dbg->emulate_bitflips) if (ubi->dbg.emulate_bitflips)
return !(random32() % 200); return !(random32() % 200);
return 0; return 0;
} }
...@@ -139,7 +99,7 @@ static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) ...@@ -139,7 +99,7 @@ static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
*/ */
static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
{ {
if (ubi->dbg->emulate_io_failures) if (ubi->dbg.emulate_io_failures)
return !(random32() % 500); return !(random32() % 500);
return 0; return 0;
} }
...@@ -153,18 +113,18 @@ static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) ...@@ -153,18 +113,18 @@ static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
*/ */
static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
{ {
if (ubi->dbg->emulate_io_failures) if (ubi->dbg.emulate_io_failures)
return !(random32() % 400); return !(random32() % 400);
return 0; return 0;
} }
static inline int ubi_dbg_chk_io(const struct ubi_device *ubi) static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
{ {
return ubi->dbg->chk_io; return ubi->dbg.chk_io;
} }
static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi) static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
{ {
return ubi->dbg->chk_gen; return ubi->dbg.chk_gen;
} }
#endif /* !__UBI_DEBUG_H__ */ #endif /* !__UBI_DEBUG_H__ */
...@@ -84,6 +84,13 @@ ...@@ -84,6 +84,13 @@
/* The volume ID/LEB number/erase counter is unknown */ /* The volume ID/LEB number/erase counter is unknown */
#define UBI_UNKNOWN -1 #define UBI_UNKNOWN -1
/*
* The UBI debugfs directory name pattern and maximum name length (3 for "ubi"
* + 2 for the number plus 1 for the trailing zero byte.
*/
#define UBI_DFS_DIR_NAME "ubi%d"
#define UBI_DFS_DIR_LEN (3 + 2 + 1)
/* /*
* Error codes returned by the I/O sub-system. * Error codes returned by the I/O sub-system.
* *
...@@ -341,6 +348,37 @@ struct ubi_volume_desc { ...@@ -341,6 +348,37 @@ struct ubi_volume_desc {
struct ubi_wl_entry; struct ubi_wl_entry;
/**
* struct ubi_debug_info - debugging information for an UBI device.
*
* @chk_gen: if UBI general extra checks are enabled
* @chk_io: if UBI I/O extra checks are enabled
* @disable_bgt: disable the background task for testing purposes
* @emulate_bitflips: emulate bit-flips for testing purposes
* @emulate_io_failures: emulate write/erase failures for testing purposes
* @dfs_dir_name: name of debugfs directory containing files of this UBI device
* @dfs_dir: direntry object of the UBI device debugfs directory
* @dfs_chk_gen: debugfs knob to enable UBI general extra checks
* @dfs_chk_io: debugfs knob to enable UBI I/O extra checks
* @dfs_disable_bgt: debugfs knob to disable the background task
* @dfs_emulate_bitflips: debugfs knob to emulate bit-flips
* @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures
*/
struct ubi_debug_info {
unsigned int chk_gen:1;
unsigned int chk_io:1;
unsigned int disable_bgt:1;
unsigned int emulate_bitflips:1;
unsigned int emulate_io_failures:1;
char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
struct dentry *dfs_dir;
struct dentry *dfs_chk_gen;
struct dentry *dfs_chk_io;
struct dentry *dfs_disable_bgt;
struct dentry *dfs_emulate_bitflips;
struct dentry *dfs_emulate_io_failures;
};
/** /**
* struct ubi_device - UBI device description structure * struct ubi_device - UBI device description structure
* @dev: UBI device object to use the the Linux device model * @dev: UBI device object to use the the Linux device model
...@@ -545,7 +583,7 @@ struct ubi_device { ...@@ -545,7 +583,7 @@ struct ubi_device {
struct mutex buf_mutex; struct mutex buf_mutex;
struct mutex ckvol_mutex; struct mutex ckvol_mutex;
struct ubi_debug_info *dbg; struct ubi_debug_info dbg;
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment