Commit 496da0d7 authored by Heiko Carstens's avatar Heiko Carstens Committed by Martin Schwidefsky

s390/debug: adjust coding style

The debug feature code hasn't been touched in ages and the code also
looks like this. Therefore clean up the code so it looks a bit more
like current coding style.

There is no functional change - actually I made also sure that the
generated code with performance_defconfig is identical.
A diff of old vs new with "objdump -d" is empty.

The code is still not checkpatch clean, but that was not the goal.
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 0bb6bba5
...@@ -13,71 +13,71 @@ ...@@ -13,71 +13,71 @@
#include <linux/refcount.h> #include <linux/refcount.h>
#include <uapi/asm/debug.h> #include <uapi/asm/debug.h>
#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */ #define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
#define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */ #define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */
#define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */ #define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */
#define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */ #define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */
#define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */ #define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
#define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */ #define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
#define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */ #define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
#define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */ #define DEBUG_DATA(entry) (char *)(entry + 1) /* data is stored behind */
/* the entry information */ /* the entry information */
typedef struct __debug_entry debug_entry_t; typedef struct __debug_entry debug_entry_t;
struct debug_view; struct debug_view;
typedef struct debug_info { typedef struct debug_info {
struct debug_info* next; struct debug_info *next;
struct debug_info* prev; struct debug_info *prev;
refcount_t ref_count; refcount_t ref_count;
spinlock_t lock; spinlock_t lock;
int level; int level;
int nr_areas; int nr_areas;
int pages_per_area; int pages_per_area;
int buf_size; int buf_size;
int entry_size; int entry_size;
debug_entry_t*** areas; debug_entry_t ***areas;
int active_area; int active_area;
int *active_pages; int *active_pages;
int *active_entries; int *active_entries;
struct dentry* debugfs_root_entry; struct dentry *debugfs_root_entry;
struct dentry* debugfs_entries[DEBUG_MAX_VIEWS]; struct dentry *debugfs_entries[DEBUG_MAX_VIEWS];
struct debug_view* views[DEBUG_MAX_VIEWS]; struct debug_view *views[DEBUG_MAX_VIEWS];
char name[DEBUG_MAX_NAME_LEN]; char name[DEBUG_MAX_NAME_LEN];
umode_t mode; umode_t mode;
} debug_info_t; } debug_info_t;
typedef int (debug_header_proc_t) (debug_info_t* id, typedef int (debug_header_proc_t) (debug_info_t *id,
struct debug_view* view, struct debug_view *view,
int area, int area,
debug_entry_t* entry, debug_entry_t *entry,
char* out_buf); char *out_buf);
typedef int (debug_format_proc_t) (debug_info_t* id, typedef int (debug_format_proc_t) (debug_info_t *id,
struct debug_view* view, char* out_buf, struct debug_view *view, char *out_buf,
const char* in_buf); const char *in_buf);
typedef int (debug_prolog_proc_t) (debug_info_t* id, typedef int (debug_prolog_proc_t) (debug_info_t *id,
struct debug_view* view, struct debug_view *view,
char* out_buf); char *out_buf);
typedef int (debug_input_proc_t) (debug_info_t* id, typedef int (debug_input_proc_t) (debug_info_t *id,
struct debug_view* view, struct debug_view *view,
struct file* file, struct file *file,
const char __user *user_buf, const char __user *user_buf,
size_t in_buf_size, loff_t* offset); size_t in_buf_size, loff_t *offset);
int debug_dflt_header_fn(debug_info_t *id, struct debug_view *view,
int area, debug_entry_t *entry, char *out_buf);
int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
int area, debug_entry_t* entry, char* out_buf);
struct debug_view { struct debug_view {
char name[DEBUG_MAX_NAME_LEN]; char name[DEBUG_MAX_NAME_LEN];
debug_prolog_proc_t* prolog_proc; debug_prolog_proc_t *prolog_proc;
debug_header_proc_t* header_proc; debug_header_proc_t *header_proc;
debug_format_proc_t* format_proc; debug_format_proc_t *format_proc;
debug_input_proc_t* input_proc; debug_input_proc_t *input_proc;
void* private_data; void *private_data;
}; };
extern struct debug_view debug_hex_ascii_view; extern struct debug_view debug_hex_ascii_view;
...@@ -86,65 +86,67 @@ extern struct debug_view debug_sprintf_view; ...@@ -86,65 +86,67 @@ extern struct debug_view debug_sprintf_view;
/* do NOT use the _common functions */ /* do NOT use the _common functions */
debug_entry_t* debug_event_common(debug_info_t* id, int level, debug_entry_t *debug_event_common(debug_info_t *id, int level,
const void* data, int length); const void *data, int length);
debug_entry_t* debug_exception_common(debug_info_t* id, int level, debug_entry_t *debug_exception_common(debug_info_t *id, int level,
const void* data, int length); const void *data, int length);
/* Debug Feature API: */ /* Debug Feature API: */
debug_info_t *debug_register(const char *name, int pages, int nr_areas, debug_info_t *debug_register(const char *name, int pages, int nr_areas,
int buf_size); int buf_size);
debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas, debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
int buf_size, umode_t mode, uid_t uid, int buf_size, umode_t mode, uid_t uid,
gid_t gid); gid_t gid);
void debug_unregister(debug_info_t* id); void debug_unregister(debug_info_t *id);
void debug_set_level(debug_info_t* id, int new_level); void debug_set_level(debug_info_t *id, int new_level);
void debug_set_critical(void); void debug_set_critical(void);
void debug_stop_all(void); void debug_stop_all(void);
static inline bool debug_level_enabled(debug_info_t* id, int level) static inline bool debug_level_enabled(debug_info_t *id, int level)
{ {
return level <= id->level; return level <= id->level;
} }
static inline debug_entry_t* static inline debug_entry_t *debug_event(debug_info_t *id, int level,
debug_event(debug_info_t* id, int level, void* data, int length) void *data, int length)
{ {
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_event_common(id,level,data,length); return debug_event_common(id, level, data, length);
} }
static inline debug_entry_t* static inline debug_entry_t *debug_int_event(debug_info_t *id, int level,
debug_int_event(debug_info_t* id, int level, unsigned int tag) unsigned int tag)
{ {
unsigned int t=tag; unsigned int t = tag;
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_event_common(id,level,&t,sizeof(unsigned int)); return debug_event_common(id, level, &t, sizeof(unsigned int));
} }
static inline debug_entry_t * static inline debug_entry_t *debug_long_event(debug_info_t *id, int level,
debug_long_event (debug_info_t* id, int level, unsigned long tag) unsigned long tag)
{ {
unsigned long t=tag; unsigned long t = tag;
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_event_common(id,level,&t,sizeof(unsigned long)); return debug_event_common(id, level, &t, sizeof(unsigned long));
} }
static inline debug_entry_t* static inline debug_entry_t *debug_text_event(debug_info_t *id, int level,
debug_text_event(debug_info_t* id, int level, const char* txt) const char *txt)
{ {
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_event_common(id,level,txt,strlen(txt)); return debug_event_common(id, level, txt, strlen(txt));
} }
/* /*
...@@ -160,6 +162,7 @@ __debug_sprintf_event(debug_info_t *id, int level, char *string, ...) ...@@ -160,6 +162,7 @@ __debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
debug_entry_t *__ret; \ debug_entry_t *__ret; \
debug_info_t *__id = _id; \ debug_info_t *__id = _id; \
int __level = _level; \ int __level = _level; \
\
if ((!__id) || (__level > __id->level)) \ if ((!__id) || (__level > __id->level)) \
__ret = NULL; \ __ret = NULL; \
else \ else \
...@@ -168,38 +171,40 @@ __debug_sprintf_event(debug_info_t *id, int level, char *string, ...) ...@@ -168,38 +171,40 @@ __debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
__ret; \ __ret; \
}) })
static inline debug_entry_t* static inline debug_entry_t *debug_exception(debug_info_t *id, int level,
debug_exception(debug_info_t* id, int level, void* data, int length) void *data, int length)
{ {
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_exception_common(id,level,data,length); return debug_exception_common(id, level, data, length);
} }
static inline debug_entry_t* static inline debug_entry_t *debug_int_exception(debug_info_t *id, int level,
debug_int_exception(debug_info_t* id, int level, unsigned int tag) unsigned int tag)
{ {
unsigned int t=tag; unsigned int t = tag;
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_exception_common(id,level,&t,sizeof(unsigned int)); return debug_exception_common(id, level, &t, sizeof(unsigned int));
} }
static inline debug_entry_t * static inline debug_entry_t *debug_long_exception (debug_info_t *id, int level,
debug_long_exception (debug_info_t* id, int level, unsigned long tag) unsigned long tag)
{ {
unsigned long t=tag; unsigned long t = tag;
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_exception_common(id,level,&t,sizeof(unsigned long)); return debug_exception_common(id, level, &t, sizeof(unsigned long));
} }
static inline debug_entry_t* static inline debug_entry_t *debug_text_exception(debug_info_t *id, int level,
debug_text_exception(debug_info_t* id, int level, const char* txt) const char *txt)
{ {
if ((!id) || (level > id->level) || (id->pages_per_area == 0)) if ((!id) || (level > id->level) || (id->pages_per_area == 0))
return NULL; return NULL;
return debug_exception_common(id,level,txt,strlen(txt)); return debug_exception_common(id, level, txt, strlen(txt));
} }
/* /*
...@@ -215,6 +220,7 @@ __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...) ...@@ -215,6 +220,7 @@ __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
debug_entry_t *__ret; \ debug_entry_t *__ret; \
debug_info_t *__id = _id; \ debug_info_t *__id = _id; \
int __level = _level; \ int __level = _level; \
\
if ((!__id) || (__level > __id->level)) \ if ((!__id) || (__level > __id->level)) \
__ret = NULL; \ __ret = NULL; \
else \ else \
...@@ -223,13 +229,13 @@ __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...) ...@@ -223,13 +229,13 @@ __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
__ret; \ __ret; \
}) })
int debug_register_view(debug_info_t* id, struct debug_view* view); int debug_register_view(debug_info_t *id, struct debug_view *view);
int debug_unregister_view(debug_info_t* id, struct debug_view* view); int debug_unregister_view(debug_info_t *id, struct debug_view *view);
/* /*
define the debug levels: define the debug levels:
- 0 No debugging output to console or syslog - 0 No debugging output to console or syslog
- 1 Log internal errors to syslog, ignore check conditions - 1 Log internal errors to syslog, ignore check conditions
- 2 Log internal errors and check conditions to syslog - 2 Log internal errors and check conditions to syslog
- 3 Log internal errors to console, log check conditions to syslog - 3 Log internal errors to console, log check conditions to syslog
- 4 Log internal errors and check conditions to console - 4 Log internal errors and check conditions to console
...@@ -247,17 +253,17 @@ int debug_unregister_view(debug_info_t* id, struct debug_view* view); ...@@ -247,17 +253,17 @@ int debug_unregister_view(debug_info_t* id, struct debug_view* view);
#define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
#if DEBUG_LEVEL > 0 #if DEBUG_LEVEL > 0
#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) #define PRINT_DEBUG(x...) printk(KERN_DEBUG PRINTK_HEADER x)
#define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x ) #define PRINT_INFO(x...) printk(KERN_INFO PRINTK_HEADER x)
#define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x ) #define PRINT_WARN(x...) printk(KERN_WARNING PRINTK_HEADER x)
#define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x ) #define PRINT_ERR(x...) printk(KERN_ERR PRINTK_HEADER x)
#define PRINT_FATAL(x...) panic ( PRINTK_HEADER x ) #define PRINT_FATAL(x...) panic(PRINTK_HEADER x)
#else #else
#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) #define PRINT_DEBUG(x...) printk(KERN_DEBUG PRINTK_HEADER x)
#define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) #define PRINT_INFO(x...) printk(KERN_DEBUG PRINTK_HEADER x)
#define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) #define PRINT_WARN(x...) printk(KERN_DEBUG PRINTK_HEADER x)
#define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) #define PRINT_ERR(x...) printk(KERN_DEBUG PRINTK_HEADER x)
#define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) #define PRINT_FATAL(x...) printk(KERN_DEBUG PRINTK_HEADER x)
#endif /* DASD_DEBUG */ #endif /* DASD_DEBUG */
#endif /* DEBUG_H */ #endif /* DEBUG_H */
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Copyright IBM Corp. 1999, 2012 * Copyright IBM Corp. 1999, 2012
* *
* Author(s): Michael Holzheu (holzheu@de.ibm.com), * Author(s): Michael Holzheu (holzheu@de.ibm.com),
* Holger Smolinski (Holger.Smolinski@de.ibm.com) * Holger Smolinski (Holger.Smolinski@de.ibm.com)
* *
* Bugreports to: <Linux390@de.ibm.com> * Bugreports to: <Linux390@de.ibm.com>
*/ */
...@@ -36,69 +36,67 @@ ...@@ -36,69 +36,67 @@
typedef struct file_private_info { typedef struct file_private_info {
loff_t offset; /* offset of last read in file */ loff_t offset; /* offset of last read in file */
int act_area; /* number of last formated area */ int act_area; /* number of last formated area */
int act_page; /* act page in given area */ int act_page; /* act page in given area */
int act_entry; /* last formated entry (offset */ int act_entry; /* last formated entry (offset */
/* relative to beginning of last */ /* relative to beginning of last */
/* formated page) */ /* formated page) */
size_t act_entry_offset; /* up to this offset we copied */ size_t act_entry_offset; /* up to this offset we copied */
/* in last read the last formated */ /* in last read the last formated */
/* entry to userland */ /* entry to userland */
char temp_buf[2048]; /* buffer for output */ char temp_buf[2048]; /* buffer for output */
debug_info_t *debug_info_org; /* original debug information */ debug_info_t *debug_info_org; /* original debug information */
debug_info_t *debug_info_snap; /* snapshot of debug information */ debug_info_t *debug_info_snap; /* snapshot of debug information */
struct debug_view *view; /* used view of debug info */ struct debug_view *view; /* used view of debug info */
} file_private_info_t; } file_private_info_t;
typedef struct typedef struct {
{
char *string; char *string;
/* /*
* This assumes that all args are converted into longs * This assumes that all args are converted into longs
* on L/390 this is the case for all types of parameter * on L/390 this is the case for all types of parameter
* except of floats, and long long (32 bit) * except of floats, and long long (32 bit)
* *
*/ */
long args[0]; long args[0];
} debug_sprintf_entry_t; } debug_sprintf_entry_t;
/* internal function prototyes */ /* internal function prototyes */
static int debug_init(void); static int debug_init(void);
static ssize_t debug_output(struct file *file, char __user *user_buf, static ssize_t debug_output(struct file *file, char __user *user_buf,
size_t user_len, loff_t * offset); size_t user_len, loff_t *offset);
static ssize_t debug_input(struct file *file, const char __user *user_buf, static ssize_t debug_input(struct file *file, const char __user *user_buf,
size_t user_len, loff_t * offset); size_t user_len, loff_t *offset);
static int debug_open(struct inode *inode, struct file *file); static int debug_open(struct inode *inode, struct file *file);
static int debug_close(struct inode *inode, struct file *file); static int debug_close(struct inode *inode, struct file *file);
static debug_info_t *debug_info_create(const char *name, int pages_per_area, static debug_info_t *debug_info_create(const char *name, int pages_per_area,
int nr_areas, int buf_size, umode_t mode); int nr_areas, int buf_size, umode_t mode);
static void debug_info_get(debug_info_t *); static void debug_info_get(debug_info_t *);
static void debug_info_put(debug_info_t *); static void debug_info_put(debug_info_t *);
static int debug_prolog_level_fn(debug_info_t * id, static int debug_prolog_level_fn(debug_info_t *id,
struct debug_view *view, char *out_buf); struct debug_view *view, char *out_buf);
static int debug_input_level_fn(debug_info_t * id, struct debug_view *view, static int debug_input_level_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf, struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t * offset); size_t user_buf_size, loff_t *offset);
static int debug_prolog_pages_fn(debug_info_t * id, static int debug_prolog_pages_fn(debug_info_t *id,
struct debug_view *view, char *out_buf); struct debug_view *view, char *out_buf);
static int debug_input_pages_fn(debug_info_t * id, struct debug_view *view, static int debug_input_pages_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf, struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t * offset); size_t user_buf_size, loff_t *offset);
static int debug_input_flush_fn(debug_info_t * id, struct debug_view *view, static int debug_input_flush_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf, struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t * offset); size_t user_buf_size, loff_t *offset);
static int debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view, static int debug_hex_ascii_format_fn(debug_info_t *id, struct debug_view *view,
char *out_buf, const char *in_buf); char *out_buf, const char *in_buf);
static int debug_raw_format_fn(debug_info_t * id, static int debug_raw_format_fn(debug_info_t *id,
struct debug_view *view, char *out_buf, struct debug_view *view, char *out_buf,
const char *in_buf); const char *in_buf);
static int debug_raw_header_fn(debug_info_t * id, struct debug_view *view, static int debug_raw_header_fn(debug_info_t *id, struct debug_view *view,
int area, debug_entry_t * entry, char *out_buf); int area, debug_entry_t *entry, char *out_buf);
static int debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view, static int debug_sprintf_format_fn(debug_info_t *id, struct debug_view *view,
char *out_buf, debug_sprintf_entry_t *curr_event); char *out_buf, debug_sprintf_entry_t *curr_event);
/* globals */ /* globals */
...@@ -141,19 +139,19 @@ static struct debug_view debug_pages_view = { ...@@ -141,19 +139,19 @@ static struct debug_view debug_pages_view = {
}; };
static struct debug_view debug_flush_view = { static struct debug_view debug_flush_view = {
"flush", "flush",
NULL, NULL,
NULL, NULL,
NULL, NULL,
&debug_input_flush_fn, &debug_input_flush_fn,
NULL NULL
}; };
struct debug_view debug_sprintf_view = { struct debug_view debug_sprintf_view = {
"sprintf", "sprintf",
NULL, NULL,
&debug_dflt_header_fn, &debug_dflt_header_fn,
(debug_format_proc_t*)&debug_sprintf_format_fn, (debug_format_proc_t *)&debug_sprintf_format_fn,
NULL, NULL,
NULL NULL
}; };
...@@ -164,18 +162,18 @@ static unsigned int __used debug_feature_version = __DEBUG_FEATURE_VERSION; ...@@ -164,18 +162,18 @@ static unsigned int __used debug_feature_version = __DEBUG_FEATURE_VERSION;
/* static globals */ /* static globals */
static debug_info_t *debug_area_first = NULL; static debug_info_t *debug_area_first;
static debug_info_t *debug_area_last = NULL; static debug_info_t *debug_area_last;
static DEFINE_MUTEX(debug_mutex); static DEFINE_MUTEX(debug_mutex);
static int initialized; static int initialized;
static int debug_critical; static int debug_critical;
static const struct file_operations debug_file_ops = { static const struct file_operations debug_file_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.read = debug_output, .read = debug_output,
.write = debug_input, .write = debug_input,
.open = debug_open, .open = debug_open,
.release = debug_close, .release = debug_close,
.llseek = no_llseek, .llseek = no_llseek,
}; };
...@@ -190,29 +188,23 @@ static struct dentry *debug_debugfs_root_entry; ...@@ -190,29 +188,23 @@ static struct dentry *debug_debugfs_root_entry;
* areas[areanumber][pagenumber][pageoffset] * areas[areanumber][pagenumber][pageoffset]
*/ */
static debug_entry_t*** static debug_entry_t ***debug_areas_alloc(int pages_per_area, int nr_areas)
debug_areas_alloc(int pages_per_area, int nr_areas)
{ {
debug_entry_t*** areas; debug_entry_t ***areas;
int i,j; int i, j;
areas = kmalloc(nr_areas * areas = kmalloc(nr_areas * sizeof(debug_entry_t **), GFP_KERNEL);
sizeof(debug_entry_t**),
GFP_KERNEL);
if (!areas) if (!areas)
goto fail_malloc_areas; goto fail_malloc_areas;
for (i = 0; i < nr_areas; i++) { for (i = 0; i < nr_areas; i++) {
areas[i] = kmalloc(pages_per_area * areas[i] = kmalloc(pages_per_area * sizeof(debug_entry_t *), GFP_KERNEL);
sizeof(debug_entry_t*),GFP_KERNEL); if (!areas[i])
if (!areas[i]) {
goto fail_malloc_areas2; goto fail_malloc_areas2;
} for (j = 0; j < pages_per_area; j++) {
for(j = 0; j < pages_per_area; j++) {
areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL); areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL);
if(!areas[i][j]) { if (!areas[i][j]) {
for(j--; j >=0 ; j--) { for (j--; j >= 0 ; j--)
kfree(areas[i][j]); kfree(areas[i][j]);
}
kfree(areas[i]); kfree(areas[i]);
goto fail_malloc_areas2; goto fail_malloc_areas2;
} }
...@@ -221,62 +213,55 @@ debug_areas_alloc(int pages_per_area, int nr_areas) ...@@ -221,62 +213,55 @@ debug_areas_alloc(int pages_per_area, int nr_areas)
return areas; return areas;
fail_malloc_areas2: fail_malloc_areas2:
for(i--; i >= 0; i--){ for (i--; i >= 0; i--) {
for(j=0; j < pages_per_area;j++){ for (j = 0; j < pages_per_area; j++)
kfree(areas[i][j]); kfree(areas[i][j]);
}
kfree(areas[i]); kfree(areas[i]);
} }
kfree(areas); kfree(areas);
fail_malloc_areas: fail_malloc_areas:
return NULL; return NULL;
} }
/* /*
* debug_info_alloc * debug_info_alloc
* - alloc new debug-info * - alloc new debug-info
*/ */
static debug_info_t *debug_info_alloc(const char *name, int pages_per_area,
static debug_info_t* int nr_areas, int buf_size, int level,
debug_info_alloc(const char *name, int pages_per_area, int nr_areas, int mode)
int buf_size, int level, int mode)
{ {
debug_info_t* rc; debug_info_t *rc;
/* alloc everything */ /* alloc everything */
rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL); rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL);
if(!rc) if (!rc)
goto fail_malloc_rc; goto fail_malloc_rc;
rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL); rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
if(!rc->active_entries) if (!rc->active_entries)
goto fail_malloc_active_entries; goto fail_malloc_active_entries;
rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL); rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
if(!rc->active_pages) if (!rc->active_pages)
goto fail_malloc_active_pages; goto fail_malloc_active_pages;
if((mode == ALL_AREAS) && (pages_per_area != 0)){ if ((mode == ALL_AREAS) && (pages_per_area != 0)) {
rc->areas = debug_areas_alloc(pages_per_area, nr_areas); rc->areas = debug_areas_alloc(pages_per_area, nr_areas);
if(!rc->areas) if (!rc->areas)
goto fail_malloc_areas; goto fail_malloc_areas;
} else { } else {
rc->areas = NULL; rc->areas = NULL;
} }
/* initialize members */ /* initialize members */
spin_lock_init(&rc->lock); spin_lock_init(&rc->lock);
rc->pages_per_area = pages_per_area; rc->pages_per_area = pages_per_area;
rc->nr_areas = nr_areas; rc->nr_areas = nr_areas;
rc->active_area = 0; rc->active_area = 0;
rc->level = level; rc->level = level;
rc->buf_size = buf_size; rc->buf_size = buf_size;
rc->entry_size = sizeof(debug_entry_t) + buf_size; rc->entry_size = sizeof(debug_entry_t) + buf_size;
strlcpy(rc->name, name, sizeof(rc->name)); strlcpy(rc->name, name, sizeof(rc->name));
memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *)); memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS * memset(rc->debugfs_entries, 0, DEBUG_MAX_VIEWS * sizeof(struct dentry *));
sizeof(struct dentry*));
refcount_set(&(rc->ref_count), 0); refcount_set(&(rc->ref_count), 0);
return rc; return rc;
...@@ -295,18 +280,15 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas, ...@@ -295,18 +280,15 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
* debug_areas_free * debug_areas_free
* - free all debug areas * - free all debug areas
*/ */
static void debug_areas_free(debug_info_t *db_info)
static void
debug_areas_free(debug_info_t* db_info)
{ {
int i,j; int i, j;
if(!db_info->areas) if (!db_info->areas)
return; return;
for (i = 0; i < db_info->nr_areas; i++) { for (i = 0; i < db_info->nr_areas; i++) {
for(j = 0; j < db_info->pages_per_area; j++) { for (j = 0; j < db_info->pages_per_area; j++)
kfree(db_info->areas[i][j]); kfree(db_info->areas[i][j]);
}
kfree(db_info->areas[i]); kfree(db_info->areas[i]);
} }
kfree(db_info->areas); kfree(db_info->areas);
...@@ -317,9 +299,8 @@ debug_areas_free(debug_info_t* db_info) ...@@ -317,9 +299,8 @@ debug_areas_free(debug_info_t* db_info)
* debug_info_free * debug_info_free
* - free memory debug-info * - free memory debug-info
*/ */
static void debug_info_free(debug_info_t *db_info)
static void {
debug_info_free(debug_info_t* db_info){
debug_areas_free(db_info); debug_areas_free(db_info);
kfree(db_info->active_entries); kfree(db_info->active_entries);
kfree(db_info->active_pages); kfree(db_info->active_pages);
...@@ -331,35 +312,34 @@ debug_info_free(debug_info_t* db_info){ ...@@ -331,35 +312,34 @@ debug_info_free(debug_info_t* db_info){
* - create new debug-info * - create new debug-info
*/ */
static debug_info_t* static debug_info_t *debug_info_create(const char *name, int pages_per_area,
debug_info_create(const char *name, int pages_per_area, int nr_areas, int nr_areas, int buf_size, umode_t mode)
int buf_size, umode_t mode)
{ {
debug_info_t* rc; debug_info_t *rc;
rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size, rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
DEBUG_DEFAULT_LEVEL, ALL_AREAS); DEBUG_DEFAULT_LEVEL, ALL_AREAS);
if(!rc) if (!rc)
goto out; goto out;
rc->mode = mode & ~S_IFMT; rc->mode = mode & ~S_IFMT;
/* create root directory */ /* create root directory */
rc->debugfs_root_entry = debugfs_create_dir(rc->name, rc->debugfs_root_entry = debugfs_create_dir(rc->name,
debug_debugfs_root_entry); debug_debugfs_root_entry);
/* append new element to linked list */ /* append new element to linked list */
if (!debug_area_first) { if (!debug_area_first) {
/* first element in list */ /* first element in list */
debug_area_first = rc; debug_area_first = rc;
rc->prev = NULL; rc->prev = NULL;
} else { } else {
/* append element to end of list */ /* append element to end of list */
debug_area_last->next = rc; debug_area_last->next = rc;
rc->prev = debug_area_last; rc->prev = debug_area_last;
} }
debug_area_last = rc; debug_area_last = rc;
rc->next = NULL; rc->next = NULL;
refcount_set(&rc->ref_count, 1); refcount_set(&rc->ref_count, 1);
out: out:
...@@ -370,24 +350,22 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas, ...@@ -370,24 +350,22 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas,
* debug_info_copy * debug_info_copy
* - copy debug-info * - copy debug-info
*/ */
static debug_info_t *debug_info_copy(debug_info_t *in, int mode)
static debug_info_t*
debug_info_copy(debug_info_t* in, int mode)
{ {
int i,j; unsigned long flags;
debug_info_t* rc; debug_info_t *rc;
unsigned long flags; int i, j;
/* get a consistent copy of the debug areas */ /* get a consistent copy of the debug areas */
do { do {
rc = debug_info_alloc(in->name, in->pages_per_area, rc = debug_info_alloc(in->name, in->pages_per_area,
in->nr_areas, in->buf_size, in->level, mode); in->nr_areas, in->buf_size, in->level, mode);
spin_lock_irqsave(&in->lock, flags); spin_lock_irqsave(&in->lock, flags);
if(!rc) if (!rc)
goto out; goto out;
/* has something changed in the meantime ? */ /* has something changed in the meantime ? */
if((rc->pages_per_area == in->pages_per_area) && if ((rc->pages_per_area == in->pages_per_area) &&
(rc->nr_areas == in->nr_areas)) { (rc->nr_areas == in->nr_areas)) {
break; break;
} }
spin_unlock_irqrestore(&in->lock, flags); spin_unlock_irqrestore(&in->lock, flags);
...@@ -395,25 +373,22 @@ debug_info_copy(debug_info_t* in, int mode) ...@@ -395,25 +373,22 @@ debug_info_copy(debug_info_t* in, int mode)
} while (1); } while (1);
if (mode == NO_AREAS) if (mode == NO_AREAS)
goto out; goto out;
for(i = 0; i < in->nr_areas; i++){ for (i = 0; i < in->nr_areas; i++) {
for(j = 0; j < in->pages_per_area; j++) { for (j = 0; j < in->pages_per_area; j++)
memcpy(rc->areas[i][j], in->areas[i][j],PAGE_SIZE); memcpy(rc->areas[i][j], in->areas[i][j], PAGE_SIZE);
} }
}
out: out:
spin_unlock_irqrestore(&in->lock, flags); spin_unlock_irqrestore(&in->lock, flags);
return rc; return rc;
} }
/* /*
* debug_info_get * debug_info_get
* - increments reference count for debug-info * - increments reference count for debug-info
*/ */
static void debug_info_get(debug_info_t *db_info)
static void
debug_info_get(debug_info_t * db_info)
{ {
if (db_info) if (db_info)
refcount_inc(&db_info->ref_count); refcount_inc(&db_info->ref_count);
...@@ -423,9 +398,7 @@ debug_info_get(debug_info_t * db_info) ...@@ -423,9 +398,7 @@ debug_info_get(debug_info_t * db_info)
* debug_info_put: * debug_info_put:
* - decreases reference count for debug-info and frees it if necessary * - decreases reference count for debug-info and frees it if necessary
*/ */
static void debug_info_put(debug_info_t *db_info)
static void
debug_info_put(debug_info_t *db_info)
{ {
int i; int i;
...@@ -438,12 +411,14 @@ debug_info_put(debug_info_t *db_info) ...@@ -438,12 +411,14 @@ debug_info_put(debug_info_t *db_info)
debugfs_remove(db_info->debugfs_entries[i]); debugfs_remove(db_info->debugfs_entries[i]);
} }
debugfs_remove(db_info->debugfs_root_entry); debugfs_remove(db_info->debugfs_root_entry);
if(db_info == debug_area_first) if (db_info == debug_area_first)
debug_area_first = db_info->next; debug_area_first = db_info->next;
if(db_info == debug_area_last) if (db_info == debug_area_last)
debug_area_last = db_info->prev; debug_area_last = db_info->prev;
if(db_info->prev) db_info->prev->next = db_info->next; if (db_info->prev)
if(db_info->next) db_info->next->prev = db_info->prev; db_info->prev->next = db_info->next;
if (db_info->next)
db_info->next->prev = db_info->prev;
debug_info_free(db_info); debug_info_free(db_info);
} }
} }
...@@ -452,71 +427,68 @@ debug_info_put(debug_info_t *db_info) ...@@ -452,71 +427,68 @@ debug_info_put(debug_info_t *db_info)
* debug_format_entry: * debug_format_entry:
* - format one debug entry and return size of formated data * - format one debug entry and return size of formated data
*/ */
static int debug_format_entry(file_private_info_t *p_info)
static int
debug_format_entry(file_private_info_t *p_info)
{ {
debug_info_t *id_snap = p_info->debug_info_snap; debug_info_t *id_snap = p_info->debug_info_snap;
struct debug_view *view = p_info->view; struct debug_view *view = p_info->view;
debug_entry_t *act_entry; debug_entry_t *act_entry;
size_t len = 0; size_t len = 0;
if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
if (p_info->act_entry == DEBUG_PROLOG_ENTRY) {
/* print prolog */ /* print prolog */
if (view->prolog_proc) if (view->prolog_proc)
len += view->prolog_proc(id_snap,view,p_info->temp_buf); len += view->prolog_proc(id_snap, view, p_info->temp_buf);
goto out; goto out;
} }
if (!id_snap->areas) /* this is true, if we have a prolog only view */ if (!id_snap->areas) /* this is true, if we have a prolog only view */
goto out; /* or if 'pages_per_area' is 0 */ goto out; /* or if 'pages_per_area' is 0 */
act_entry = (debug_entry_t *) ((char*)id_snap->areas[p_info->act_area] act_entry = (debug_entry_t *) ((char *)id_snap->areas[p_info->act_area]
[p_info->act_page] + p_info->act_entry); [p_info->act_page] + p_info->act_entry);
if (act_entry->id.stck == 0LL) if (act_entry->id.stck == 0LL)
goto out; /* empty entry */ goto out; /* empty entry */
if (view->header_proc) if (view->header_proc)
len += view->header_proc(id_snap, view, p_info->act_area, len += view->header_proc(id_snap, view, p_info->act_area,
act_entry, p_info->temp_buf + len); act_entry, p_info->temp_buf + len);
if (view->format_proc) if (view->format_proc)
len += view->format_proc(id_snap, view, p_info->temp_buf + len, len += view->format_proc(id_snap, view, p_info->temp_buf + len,
DEBUG_DATA(act_entry)); DEBUG_DATA(act_entry));
out: out:
return len; return len;
} }
/* /*
* debug_next_entry: * debug_next_entry:
* - goto next entry in p_info * - goto next entry in p_info
*/ */
static inline int debug_next_entry(file_private_info_t *p_info)
static inline int
debug_next_entry(file_private_info_t *p_info)
{ {
debug_info_t *id; debug_info_t *id;
id = p_info->debug_info_snap; id = p_info->debug_info_snap;
if(p_info->act_entry == DEBUG_PROLOG_ENTRY){ if (p_info->act_entry == DEBUG_PROLOG_ENTRY) {
p_info->act_entry = 0; p_info->act_entry = 0;
p_info->act_page = 0; p_info->act_page = 0;
goto out; goto out;
} }
if(!id->areas) if (!id->areas)
return 1; return 1;
p_info->act_entry += id->entry_size; p_info->act_entry += id->entry_size;
/* switch to next page, if we reached the end of the page */ /* switch to next page, if we reached the end of the page */
if (p_info->act_entry > (PAGE_SIZE - id->entry_size)){ if (p_info->act_entry > (PAGE_SIZE - id->entry_size)) {
/* next page */ /* next page */
p_info->act_entry = 0; p_info->act_entry = 0;
p_info->act_page += 1; p_info->act_page += 1;
if((p_info->act_page % id->pages_per_area) == 0) { if ((p_info->act_page % id->pages_per_area) == 0) {
/* next area */ /* next area */
p_info->act_area++; p_info->act_area++;
p_info->act_page=0; p_info->act_page = 0;
} }
if(p_info->act_area >= id->nr_areas) if (p_info->act_area >= id->nr_areas)
return 1; return 1;
} }
out: out:
return 0; return 0;
} }
/* /*
...@@ -524,26 +496,24 @@ debug_next_entry(file_private_info_t *p_info) ...@@ -524,26 +496,24 @@ debug_next_entry(file_private_info_t *p_info)
* - called for user read() * - called for user read()
* - copies formated debug entries to the user buffer * - copies formated debug entries to the user buffer
*/ */
static ssize_t debug_output(struct file *file, /* file descriptor */
static ssize_t char __user *user_buf, /* user buffer */
debug_output(struct file *file, /* file descriptor */ size_t len, /* length of buffer */
char __user *user_buf, /* user buffer */ loff_t *offset) /* offset in the file */
size_t len, /* length of buffer */
loff_t *offset) /* offset in the file */
{ {
size_t count = 0; size_t count = 0;
size_t entry_offset; size_t entry_offset;
file_private_info_t *p_info; file_private_info_t *p_info;
p_info = ((file_private_info_t *) file->private_data); p_info = (file_private_info_t *) file->private_data;
if (*offset != p_info->offset) if (*offset != p_info->offset)
return -EPIPE; return -EPIPE;
if(p_info->act_area >= p_info->debug_info_snap->nr_areas) if (p_info->act_area >= p_info->debug_info_snap->nr_areas)
return 0; return 0;
entry_offset = p_info->act_entry_offset; entry_offset = p_info->act_entry_offset;
while(count < len){ while (count < len) {
int formatted_line_size;
int formatted_line_residue; int formatted_line_residue;
int formatted_line_size;
int user_buf_residue; int user_buf_residue;
size_t copy_size; size_t copy_size;
...@@ -551,21 +521,21 @@ debug_output(struct file *file, /* file descriptor */ ...@@ -551,21 +521,21 @@ debug_output(struct file *file, /* file descriptor */
formatted_line_residue = formatted_line_size - entry_offset; formatted_line_residue = formatted_line_size - entry_offset;
user_buf_residue = len-count; user_buf_residue = len-count;
copy_size = min(user_buf_residue, formatted_line_residue); copy_size = min(user_buf_residue, formatted_line_residue);
if(copy_size){ if (copy_size) {
if (copy_to_user(user_buf + count, p_info->temp_buf if (copy_to_user(user_buf + count, p_info->temp_buf
+ entry_offset, copy_size)) + entry_offset, copy_size))
return -EFAULT; return -EFAULT;
count += copy_size; count += copy_size;
entry_offset += copy_size; entry_offset += copy_size;
} }
if(copy_size == formatted_line_residue){ if (copy_size == formatted_line_residue) {
entry_offset = 0; entry_offset = 0;
if(debug_next_entry(p_info)) if (debug_next_entry(p_info))
goto out; goto out;
} }
} }
out: out:
p_info->offset = *offset + count; p_info->offset = *offset + count;
p_info->act_entry_offset = entry_offset; p_info->act_entry_offset = entry_offset;
*offset = p_info->offset; *offset = p_info->offset;
return count; return count;
...@@ -576,24 +546,23 @@ debug_output(struct file *file, /* file descriptor */ ...@@ -576,24 +546,23 @@ debug_output(struct file *file, /* file descriptor */
* - called for user write() * - called for user write()
* - calls input function of view * - calls input function of view
*/ */
static ssize_t debug_input(struct file *file, const char __user *user_buf,
static ssize_t size_t length, loff_t *offset)
debug_input(struct file *file, const char __user *user_buf, size_t length,
loff_t *offset)
{ {
int rc = 0;
file_private_info_t *p_info; file_private_info_t *p_info;
int rc = 0;
mutex_lock(&debug_mutex); mutex_lock(&debug_mutex);
p_info = ((file_private_info_t *) file->private_data); p_info = ((file_private_info_t *) file->private_data);
if (p_info->view->input_proc) if (p_info->view->input_proc) {
rc = p_info->view->input_proc(p_info->debug_info_org, rc = p_info->view->input_proc(p_info->debug_info_org,
p_info->view, file, user_buf, p_info->view, file, user_buf,
length, offset); length, offset);
else } else {
rc = -EPERM; rc = -EPERM;
}
mutex_unlock(&debug_mutex); mutex_unlock(&debug_mutex);
return rc; /* number of input characters */ return rc; /* number of input characters */
} }
/* /*
...@@ -602,13 +571,11 @@ debug_input(struct file *file, const char __user *user_buf, size_t length, ...@@ -602,13 +571,11 @@ debug_input(struct file *file, const char __user *user_buf, size_t length,
* - copies formated output to private_data area of the file * - copies formated output to private_data area of the file
* handle * handle
*/ */
static int debug_open(struct inode *inode, struct file *file)
static int
debug_open(struct inode *inode, struct file *file)
{ {
int i, rc = 0;
file_private_info_t *p_info;
debug_info_t *debug_info, *debug_info_snapshot; debug_info_t *debug_info, *debug_info_snapshot;
file_private_info_t *p_info;
int i, rc = 0;
mutex_lock(&debug_mutex); mutex_lock(&debug_mutex);
debug_info = file_inode(file)->i_private; debug_info = file_inode(file)->i_private;
...@@ -616,10 +583,8 @@ debug_open(struct inode *inode, struct file *file) ...@@ -616,10 +583,8 @@ debug_open(struct inode *inode, struct file *file)
for (i = 0; i < DEBUG_MAX_VIEWS; i++) { for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
if (!debug_info->views[i]) if (!debug_info->views[i])
continue; continue;
else if (debug_info->debugfs_entries[i] == else if (debug_info->debugfs_entries[i] == file->f_path.dentry)
file->f_path.dentry) { goto found; /* found view ! */
goto found; /* found view ! */
}
} }
/* no entry found */ /* no entry found */
rc = -EINVAL; rc = -EINVAL;
...@@ -627,31 +592,28 @@ debug_open(struct inode *inode, struct file *file) ...@@ -627,31 +592,28 @@ debug_open(struct inode *inode, struct file *file)
found: found:
/* Make snapshot of current debug areas to get it consistent. */ /* Make snapshot of current debug areas to get it consistent. */
/* To copy all the areas is only needed, if we have a view which */ /* To copy all the areas is only needed, if we have a view which */
/* formats the debug areas. */ /* formats the debug areas. */
if(!debug_info->views[i]->format_proc && if (!debug_info->views[i]->format_proc && !debug_info->views[i]->header_proc)
!debug_info->views[i]->header_proc){
debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS); debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
} else { else
debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS); debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
}
if(!debug_info_snapshot){ if (!debug_info_snapshot) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
p_info = kmalloc(sizeof(file_private_info_t), p_info = kmalloc(sizeof(file_private_info_t), GFP_KERNEL);
GFP_KERNEL); if (!p_info) {
if(!p_info){
debug_info_free(debug_info_snapshot); debug_info_free(debug_info_snapshot);
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
p_info->offset = 0; p_info->offset = 0;
p_info->debug_info_snap = debug_info_snapshot; p_info->debug_info_snap = debug_info_snapshot;
p_info->debug_info_org = debug_info; p_info->debug_info_org = debug_info;
p_info->view = debug_info->views[i]; p_info->view = debug_info->views[i];
p_info->act_area = 0; p_info->act_area = 0;
p_info->act_page = 0; p_info->act_page = 0;
...@@ -670,17 +632,16 @@ debug_open(struct inode *inode, struct file *file) ...@@ -670,17 +632,16 @@ debug_open(struct inode *inode, struct file *file)
* - called for user close() * - called for user close()
* - deletes private_data area of the file handle * - deletes private_data area of the file handle
*/ */
static int debug_close(struct inode *inode, struct file *file)
static int
debug_close(struct inode *inode, struct file *file)
{ {
file_private_info_t *p_info; file_private_info_t *p_info;
p_info = (file_private_info_t *) file->private_data; p_info = (file_private_info_t *) file->private_data;
if(p_info->debug_info_snap) if (p_info->debug_info_snap)
debug_info_free(p_info->debug_info_snap); debug_info_free(p_info->debug_info_snap);
debug_info_put(p_info->debug_info_org); debug_info_put(p_info->debug_info_org);
kfree(file->private_data); kfree(file->private_data);
return 0; /* success */ return 0; /* success */
} }
/* /*
...@@ -689,7 +650,6 @@ debug_close(struct inode *inode, struct file *file) ...@@ -689,7 +650,6 @@ debug_close(struct inode *inode, struct file *file)
* The mode parameter allows to specify access rights for the s390dbf files * The mode parameter allows to specify access rights for the s390dbf files
* - Returns handle for debug area * - Returns handle for debug area
*/ */
debug_info_t *debug_register_mode(const char *name, int pages_per_area, debug_info_t *debug_register_mode(const char *name, int pages_per_area,
int nr_areas, int buf_size, umode_t mode, int nr_areas, int buf_size, umode_t mode,
uid_t uid, gid_t gid) uid_t uid, gid_t gid)
...@@ -703,18 +663,16 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area, ...@@ -703,18 +663,16 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area,
BUG_ON(!initialized); BUG_ON(!initialized);
mutex_lock(&debug_mutex); mutex_lock(&debug_mutex);
/* create new debug_info */ /* create new debug_info */
rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode); rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
if(!rc) if (!rc)
goto out; goto out;
debug_register_view(rc, &debug_level_view); debug_register_view(rc, &debug_level_view);
debug_register_view(rc, &debug_flush_view); debug_register_view(rc, &debug_flush_view);
debug_register_view(rc, &debug_pages_view); debug_register_view(rc, &debug_pages_view);
out: out:
if (!rc){ if (!rc)
pr_err("Registering debug feature %s failed\n", name); pr_err("Registering debug feature %s failed\n", name);
}
mutex_unlock(&debug_mutex); mutex_unlock(&debug_mutex);
return rc; return rc;
} }
...@@ -725,7 +683,6 @@ EXPORT_SYMBOL(debug_register_mode); ...@@ -725,7 +683,6 @@ EXPORT_SYMBOL(debug_register_mode);
* - creates and initializes debug area for the caller * - creates and initializes debug area for the caller
* - returns handle for debug area * - returns handle for debug area
*/ */
debug_info_t *debug_register(const char *name, int pages_per_area, debug_info_t *debug_register(const char *name, int pages_per_area,
int nr_areas, int buf_size) int nr_areas, int buf_size)
{ {
...@@ -738,18 +695,13 @@ EXPORT_SYMBOL(debug_register); ...@@ -738,18 +695,13 @@ EXPORT_SYMBOL(debug_register);
* debug_unregister: * debug_unregister:
* - give back debug area * - give back debug area
*/ */
void debug_unregister(debug_info_t *id)
void
debug_unregister(debug_info_t * id)
{ {
if (!id) if (!id)
goto out; return;
mutex_lock(&debug_mutex); mutex_lock(&debug_mutex);
debug_info_put(id); debug_info_put(id);
mutex_unlock(&debug_mutex); mutex_unlock(&debug_mutex);
out:
return;
} }
EXPORT_SYMBOL(debug_unregister); EXPORT_SYMBOL(debug_unregister);
...@@ -757,18 +709,17 @@ EXPORT_SYMBOL(debug_unregister); ...@@ -757,18 +709,17 @@ EXPORT_SYMBOL(debug_unregister);
* debug_set_size: * debug_set_size:
* - set area size (number of pages) and number of areas * - set area size (number of pages) and number of areas
*/ */
static int static int debug_set_size(debug_info_t *id, int nr_areas, int pages_per_area)
debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
{ {
debug_entry_t ***new_areas;
unsigned long flags; unsigned long flags;
debug_entry_t *** new_areas; int rc = 0;
int rc=0;
if(!id || (nr_areas <= 0) || (pages_per_area < 0)) if (!id || (nr_areas <= 0) || (pages_per_area < 0))
return -EINVAL; return -EINVAL;
if(pages_per_area > 0){ if (pages_per_area > 0) {
new_areas = debug_areas_alloc(pages_per_area, nr_areas); new_areas = debug_areas_alloc(pages_per_area, nr_areas);
if(!new_areas) { if (!new_areas) {
pr_info("Allocating memory for %i pages failed\n", pr_info("Allocating memory for %i pages failed\n",
pages_per_area); pages_per_area);
rc = -ENOMEM; rc = -ENOMEM;
...@@ -777,16 +728,16 @@ debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area) ...@@ -777,16 +728,16 @@ debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
} else { } else {
new_areas = NULL; new_areas = NULL;
} }
spin_lock_irqsave(&id->lock,flags); spin_lock_irqsave(&id->lock, flags);
debug_areas_free(id); debug_areas_free(id);
id->areas = new_areas; id->areas = new_areas;
id->nr_areas = nr_areas; id->nr_areas = nr_areas;
id->pages_per_area = pages_per_area; id->pages_per_area = pages_per_area;
id->active_area = 0; id->active_area = 0;
memset(id->active_entries,0,sizeof(int)*id->nr_areas); memset(id->active_entries, 0, sizeof(int)*id->nr_areas);
memset(id->active_pages, 0, sizeof(int)*id->nr_areas); memset(id->active_pages, 0, sizeof(int)*id->nr_areas);
spin_unlock_irqrestore(&id->lock,flags); spin_unlock_irqrestore(&id->lock, flags);
pr_info("%s: set new size (%i pages)\n" ,id->name, pages_per_area); pr_info("%s: set new size (%i pages)\n", id->name, pages_per_area);
out: out:
return rc; return rc;
} }
...@@ -795,24 +746,23 @@ debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area) ...@@ -795,24 +746,23 @@ debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
* debug_set_level: * debug_set_level:
* - set actual debug level * - set actual debug level
*/ */
void debug_set_level(debug_info_t *id, int new_level)
void
debug_set_level(debug_info_t* id, int new_level)
{ {
unsigned long flags; unsigned long flags;
if(!id)
return; if (!id)
spin_lock_irqsave(&id->lock,flags); return;
if(new_level == DEBUG_OFF_LEVEL){ spin_lock_irqsave(&id->lock, flags);
id->level = DEBUG_OFF_LEVEL; if (new_level == DEBUG_OFF_LEVEL) {
pr_info("%s: switched off\n",id->name); id->level = DEBUG_OFF_LEVEL;
} else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) { pr_info("%s: switched off\n", id->name);
} else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
pr_info("%s: level %i is out of range (%i - %i)\n", pr_info("%s: level %i is out of range (%i - %i)\n",
id->name, new_level, 0, DEBUG_MAX_LEVEL); id->name, new_level, 0, DEBUG_MAX_LEVEL);
} else { } else {
id->level = new_level; id->level = new_level;
} }
spin_unlock_irqrestore(&id->lock,flags); spin_unlock_irqrestore(&id->lock, flags);
} }
EXPORT_SYMBOL(debug_set_level); EXPORT_SYMBOL(debug_set_level);
...@@ -820,12 +770,10 @@ EXPORT_SYMBOL(debug_set_level); ...@@ -820,12 +770,10 @@ EXPORT_SYMBOL(debug_set_level);
* proceed_active_entry: * proceed_active_entry:
* - set active entry to next in the ring buffer * - set active entry to next in the ring buffer
*/ */
static inline void proceed_active_entry(debug_info_t *id)
static inline void
proceed_active_entry(debug_info_t * id)
{ {
if ((id->active_entries[id->active_area] += id->entry_size) if ((id->active_entries[id->active_area] += id->entry_size)
> (PAGE_SIZE - id->entry_size)){ > (PAGE_SIZE - id->entry_size)) {
id->active_entries[id->active_area] = 0; id->active_entries[id->active_area] = 0;
id->active_pages[id->active_area] = id->active_pages[id->active_area] =
(id->active_pages[id->active_area] + 1) % (id->active_pages[id->active_area] + 1) %
...@@ -837,9 +785,7 @@ proceed_active_entry(debug_info_t * id) ...@@ -837,9 +785,7 @@ proceed_active_entry(debug_info_t * id)
* proceed_active_area: * proceed_active_area:
* - set active area to next in the ring buffer * - set active area to next in the ring buffer
*/ */
static inline void proceed_active_area(debug_info_t *id)
static inline void
proceed_active_area(debug_info_t * id)
{ {
id->active_area++; id->active_area++;
id->active_area = id->active_area % id->nr_areas; id->active_area = id->active_area % id->nr_areas;
...@@ -848,13 +794,11 @@ proceed_active_area(debug_info_t * id) ...@@ -848,13 +794,11 @@ proceed_active_area(debug_info_t * id)
/* /*
* get_active_entry: * get_active_entry:
*/ */
static inline debug_entry_t *get_active_entry(debug_info_t *id)
static inline debug_entry_t*
get_active_entry(debug_info_t * id)
{ {
return (debug_entry_t *) (((char *) id->areas[id->active_area] return (debug_entry_t *) (((char *) id->areas[id->active_area]
[id->active_pages[id->active_area]]) + [id->active_pages[id->active_area]]) +
id->active_entries[id->active_area]); id->active_entries[id->active_area]);
} }
/* /*
...@@ -862,23 +806,22 @@ get_active_entry(debug_info_t * id) ...@@ -862,23 +806,22 @@ get_active_entry(debug_info_t * id)
* - set timestamp, caller address, cpu number etc. * - set timestamp, caller address, cpu number etc.
*/ */
static inline void static inline void debug_finish_entry(debug_info_t *id, debug_entry_t *active,
debug_finish_entry(debug_info_t * id, debug_entry_t* active, int level, int level, int exception)
int exception)
{ {
active->id.stck = get_tod_clock_fast() - active->id.stck = get_tod_clock_fast() -
*(unsigned long long *) &tod_clock_base[1]; *(unsigned long long *) &tod_clock_base[1];
active->id.fields.cpuid = smp_processor_id(); active->id.fields.cpuid = smp_processor_id();
active->caller = __builtin_return_address(0); active->caller = __builtin_return_address(0);
active->id.fields.exception = exception; active->id.fields.exception = exception;
active->id.fields.level = level; active->id.fields.level = level;
proceed_active_entry(id); proceed_active_entry(id);
if(exception) if (exception)
proceed_active_area(id); proceed_active_area(id);
} }
static int debug_stoppable=1; static int debug_stoppable = 1;
static int debug_active=1; static int debug_active = 1;
#define CTL_S390DBF_STOPPABLE 5678 #define CTL_S390DBF_STOPPABLE 5678
#define CTL_S390DBF_ACTIVE 5679 #define CTL_S390DBF_ACTIVE 5679
...@@ -888,9 +831,8 @@ static int debug_active=1; ...@@ -888,9 +831,8 @@ static int debug_active=1;
* always allow read, allow write only if debug_stoppable is set or * always allow read, allow write only if debug_stoppable is set or
* if debug_active is already off * if debug_active is already off
*/ */
static int static int s390dbf_procactive(struct ctl_table *table, int write,
s390dbf_procactive(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
void __user *buffer, size_t *lenp, loff_t *ppos)
{ {
if (!write || debug_stoppable || !debug_active) if (!write || debug_stoppable || !debug_active)
return proc_dointvec(table, write, buffer, lenp, ppos); return proc_dointvec(table, write, buffer, lenp, ppos);
...@@ -898,39 +840,37 @@ s390dbf_procactive(struct ctl_table *table, int write, ...@@ -898,39 +840,37 @@ s390dbf_procactive(struct ctl_table *table, int write,
return 0; return 0;
} }
static struct ctl_table s390dbf_table[] = { static struct ctl_table s390dbf_table[] = {
{ {
.procname = "debug_stoppable", .procname = "debug_stoppable",
.data = &debug_stoppable, .data = &debug_stoppable,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = S_IRUGO | S_IWUSR, .mode = S_IRUGO | S_IWUSR,
.proc_handler = proc_dointvec, .proc_handler = proc_dointvec,
}, },
{ {
.procname = "debug_active", .procname = "debug_active",
.data = &debug_active, .data = &debug_active,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = S_IRUGO | S_IWUSR, .mode = S_IRUGO | S_IWUSR,
.proc_handler = s390dbf_procactive, .proc_handler = s390dbf_procactive,
}, },
{ } { }
}; };
static struct ctl_table s390dbf_dir_table[] = { static struct ctl_table s390dbf_dir_table[] = {
{ {
.procname = "s390dbf", .procname = "s390dbf",
.maxlen = 0, .maxlen = 0,
.mode = S_IRUGO | S_IXUGO, .mode = S_IRUGO | S_IXUGO,
.child = s390dbf_table, .child = s390dbf_table,
}, },
{ } { }
}; };
static struct ctl_table_header *s390dbf_sysctl_header; static struct ctl_table_header *s390dbf_sysctl_header;
void void debug_stop_all(void)
debug_stop_all(void)
{ {
if (debug_stoppable) if (debug_stoppable)
debug_active = 0; debug_active = 0;
...@@ -946,20 +886,20 @@ void debug_set_critical(void) ...@@ -946,20 +886,20 @@ void debug_set_critical(void)
* debug_event_common: * debug_event_common:
* - write debug entry with given size * - write debug entry with given size
*/ */
debug_entry_t *debug_event_common(debug_info_t *id, int level, const void *buf,
debug_entry_t* int len)
debug_event_common(debug_info_t * id, int level, const void *buf, int len)
{ {
unsigned long flags;
debug_entry_t *active; debug_entry_t *active;
unsigned long flags;
if (!debug_active || !id->areas) if (!debug_active || !id->areas)
return NULL; return NULL;
if (debug_critical) { if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags)) if (!spin_trylock_irqsave(&id->lock, flags))
return NULL; return NULL;
} else } else {
spin_lock_irqsave(&id->lock, flags); spin_lock_irqsave(&id->lock, flags);
}
active = get_active_entry(id); active = get_active_entry(id);
memset(DEBUG_DATA(active), 0, id->buf_size); memset(DEBUG_DATA(active), 0, id->buf_size);
memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size)); memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
...@@ -974,20 +914,20 @@ EXPORT_SYMBOL(debug_event_common); ...@@ -974,20 +914,20 @@ EXPORT_SYMBOL(debug_event_common);
* debug_exception_common: * debug_exception_common:
* - write debug entry with given size and switch to next debug area * - write debug entry with given size and switch to next debug area
*/ */
debug_entry_t *debug_exception_common(debug_info_t *id, int level,
debug_entry_t const void *buf, int len)
*debug_exception_common(debug_info_t * id, int level, const void *buf, int len)
{ {
unsigned long flags;
debug_entry_t *active; debug_entry_t *active;
unsigned long flags;
if (!debug_active || !id->areas) if (!debug_active || !id->areas)
return NULL; return NULL;
if (debug_critical) { if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags)) if (!spin_trylock_irqsave(&id->lock, flags))
return NULL; return NULL;
} else } else {
spin_lock_irqsave(&id->lock, flags); spin_lock_irqsave(&id->lock, flags);
}
active = get_active_entry(id); active = get_active_entry(id);
memset(DEBUG_DATA(active), 0, id->buf_size); memset(DEBUG_DATA(active), 0, id->buf_size);
memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size)); memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
...@@ -1001,47 +941,44 @@ EXPORT_SYMBOL(debug_exception_common); ...@@ -1001,47 +941,44 @@ EXPORT_SYMBOL(debug_exception_common);
/* /*
* counts arguments in format string for sprintf view * counts arguments in format string for sprintf view
*/ */
static inline int debug_count_numargs(char *string)
static inline int
debug_count_numargs(char *string)
{ {
int numargs=0; int numargs = 0;
while(*string) { while (*string) {
if(*string++=='%') if (*string++ == '%')
numargs++; numargs++;
} }
return(numargs); return numargs;
} }
/* /*
* debug_sprintf_event: * debug_sprintf_event:
*/ */
debug_entry_t *__debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
debug_entry_t*
__debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
{ {
va_list ap;
int numargs,idx;
unsigned long flags;
debug_sprintf_entry_t *curr_event; debug_sprintf_entry_t *curr_event;
debug_entry_t *active; debug_entry_t *active;
unsigned long flags;
int numargs, idx;
va_list ap;
if (!debug_active || !id->areas) if (!debug_active || !id->areas)
return NULL; return NULL;
numargs=debug_count_numargs(string); numargs = debug_count_numargs(string);
if (debug_critical) { if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags)) if (!spin_trylock_irqsave(&id->lock, flags))
return NULL; return NULL;
} else } else {
spin_lock_irqsave(&id->lock, flags); spin_lock_irqsave(&id->lock, flags);
}
active = get_active_entry(id); active = get_active_entry(id);
curr_event=(debug_sprintf_entry_t *) DEBUG_DATA(active); curr_event = (debug_sprintf_entry_t *) DEBUG_DATA(active);
va_start(ap,string); va_start(ap, string);
curr_event->string=string; curr_event->string = string;
for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++) for (idx = 0; idx < min(numargs, (int)(id->buf_size / sizeof(long)) - 1); idx++)
curr_event->args[idx]=va_arg(ap,long); curr_event->args[idx] = va_arg(ap, long);
va_end(ap); va_end(ap);
debug_finish_entry(id, active, level, 0); debug_finish_entry(id, active, level, 0);
spin_unlock_irqrestore(&id->lock, flags); spin_unlock_irqrestore(&id->lock, flags);
...@@ -1053,32 +990,31 @@ EXPORT_SYMBOL(__debug_sprintf_event); ...@@ -1053,32 +990,31 @@ EXPORT_SYMBOL(__debug_sprintf_event);
/* /*
* debug_sprintf_exception: * debug_sprintf_exception:
*/ */
debug_entry_t *__debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
debug_entry_t*
__debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
{ {
va_list ap;
int numargs,idx;
unsigned long flags;
debug_sprintf_entry_t *curr_event; debug_sprintf_entry_t *curr_event;
debug_entry_t *active; debug_entry_t *active;
unsigned long flags;
int numargs, idx;
va_list ap;
if (!debug_active || !id->areas) if (!debug_active || !id->areas)
return NULL; return NULL;
numargs=debug_count_numargs(string); numargs = debug_count_numargs(string);
if (debug_critical) { if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags)) if (!spin_trylock_irqsave(&id->lock, flags))
return NULL; return NULL;
} else } else {
spin_lock_irqsave(&id->lock, flags); spin_lock_irqsave(&id->lock, flags);
}
active = get_active_entry(id); active = get_active_entry(id);
curr_event=(debug_sprintf_entry_t *)DEBUG_DATA(active); curr_event = (debug_sprintf_entry_t *)DEBUG_DATA(active);
va_start(ap,string); va_start(ap, string);
curr_event->string=string; curr_event->string = string;
for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++) for (idx = 0; idx < min(numargs, (int)(id->buf_size / sizeof(long)) - 1); idx++)
curr_event->args[idx]=va_arg(ap,long); curr_event->args[idx] = va_arg(ap, long);
va_end(ap); va_end(ap);
debug_finish_entry(id, active, level, 1); debug_finish_entry(id, active, level, 1);
spin_unlock_irqrestore(&id->lock, flags); spin_unlock_irqrestore(&id->lock, flags);
...@@ -1090,15 +1026,13 @@ EXPORT_SYMBOL(__debug_sprintf_exception); ...@@ -1090,15 +1026,13 @@ EXPORT_SYMBOL(__debug_sprintf_exception);
/* /*
* debug_register_view: * debug_register_view:
*/ */
int debug_register_view(debug_info_t *id, struct debug_view *view)
int
debug_register_view(debug_info_t * id, struct debug_view *view)
{ {
int rc = 0;
int i;
unsigned long flags; unsigned long flags;
umode_t mode;
struct dentry *pde; struct dentry *pde;
umode_t mode;
int rc = 0;
int i;
if (!id) if (!id)
goto out; goto out;
...@@ -1108,10 +1042,10 @@ debug_register_view(debug_info_t * id, struct debug_view *view) ...@@ -1108,10 +1042,10 @@ debug_register_view(debug_info_t * id, struct debug_view *view)
if (!view->input_proc) if (!view->input_proc)
mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry, pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
id , &debug_file_ops); id, &debug_file_ops);
if (!pde){ if (!pde) {
pr_err("Registering view %s/%s failed due to out of " pr_err("Registering view %s/%s failed due to out of "
"memory\n", id->name,view->name); "memory\n", id->name, view->name);
rc = -1; rc = -1;
goto out; goto out;
} }
...@@ -1139,9 +1073,7 @@ EXPORT_SYMBOL(debug_register_view); ...@@ -1139,9 +1073,7 @@ EXPORT_SYMBOL(debug_register_view);
/* /*
* debug_unregister_view: * debug_unregister_view:
*/ */
int debug_unregister_view(debug_info_t *id, struct debug_view *view)
int
debug_unregister_view(debug_info_t * id, struct debug_view *view)
{ {
struct dentry *dentry = NULL; struct dentry *dentry = NULL;
unsigned long flags; unsigned long flags;
...@@ -1154,9 +1086,9 @@ debug_unregister_view(debug_info_t * id, struct debug_view *view) ...@@ -1154,9 +1086,9 @@ debug_unregister_view(debug_info_t * id, struct debug_view *view)
if (id->views[i] == view) if (id->views[i] == view)
break; break;
} }
if (i == DEBUG_MAX_VIEWS) if (i == DEBUG_MAX_VIEWS) {
rc = -1; rc = -1;
else { } else {
dentry = id->debugfs_entries[i]; dentry = id->debugfs_entries[i];
id->views[i] = NULL; id->views[i] = NULL;
id->debugfs_entries[i] = NULL; id->debugfs_entries[i] = NULL;
...@@ -1168,10 +1100,10 @@ debug_unregister_view(debug_info_t * id, struct debug_view *view) ...@@ -1168,10 +1100,10 @@ debug_unregister_view(debug_info_t * id, struct debug_view *view)
} }
EXPORT_SYMBOL(debug_unregister_view); EXPORT_SYMBOL(debug_unregister_view);
static inline char * static inline char *debug_get_user_string(const char __user *user_buf,
debug_get_user_string(const char __user *user_buf, size_t user_len) size_t user_len)
{ {
char* buffer; char *buffer;
buffer = kmalloc(user_len + 1, GFP_KERNEL); buffer = kmalloc(user_len + 1, GFP_KERNEL);
if (!buffer) if (!buffer)
...@@ -1185,19 +1117,17 @@ debug_get_user_string(const char __user *user_buf, size_t user_len) ...@@ -1185,19 +1117,17 @@ debug_get_user_string(const char __user *user_buf, size_t user_len)
buffer[user_len - 1] = 0; buffer[user_len - 1] = 0;
else else
buffer[user_len] = 0; buffer[user_len] = 0;
return buffer; return buffer;
} }
static inline int static inline int debug_get_uint(char *buf)
debug_get_uint(char *buf)
{ {
int rc; int rc;
buf = skip_spaces(buf); buf = skip_spaces(buf);
rc = simple_strtoul(buf, &buf, 10); rc = simple_strtoul(buf, &buf, 10);
if(*buf){ if (*buf)
rc = -EINVAL; rc = -EINVAL;
}
return rc; return rc;
} }
...@@ -1210,9 +1140,8 @@ debug_get_uint(char *buf) ...@@ -1210,9 +1140,8 @@ debug_get_uint(char *buf)
* prints out actual debug level * prints out actual debug level
*/ */
static int static int debug_prolog_pages_fn(debug_info_t *id, struct debug_view *view,
debug_prolog_pages_fn(debug_info_t * id, char *out_buf)
struct debug_view *view, char *out_buf)
{ {
return sprintf(out_buf, "%i\n", id->pages_per_area); return sprintf(out_buf, "%i\n", id->pages_per_area);
} }
...@@ -1221,32 +1150,31 @@ debug_prolog_pages_fn(debug_info_t * id, ...@@ -1221,32 +1150,31 @@ debug_prolog_pages_fn(debug_info_t * id,
* reads new size (number of pages per debug area) * reads new size (number of pages per debug area)
*/ */
static int static int debug_input_pages_fn(debug_info_t *id, struct debug_view *view,
debug_input_pages_fn(debug_info_t * id, struct debug_view *view, struct file *file, const char __user *user_buf,
struct file *file, const char __user *user_buf, size_t user_len, loff_t *offset)
size_t user_len, loff_t * offset)
{ {
int rc, new_pages;
char *str; char *str;
int rc,new_pages;
if (user_len > 0x10000) if (user_len > 0x10000)
user_len = 0x10000; user_len = 0x10000;
if (*offset != 0){ if (*offset != 0) {
rc = -EPIPE; rc = -EPIPE;
goto out; goto out;
} }
str = debug_get_user_string(user_buf,user_len); str = debug_get_user_string(user_buf, user_len);
if(IS_ERR(str)){ if (IS_ERR(str)) {
rc = PTR_ERR(str); rc = PTR_ERR(str);
goto out; goto out;
} }
new_pages = debug_get_uint(str); new_pages = debug_get_uint(str);
if(new_pages < 0){ if (new_pages < 0) {
rc = -EINVAL; rc = -EINVAL;
goto free_str; goto free_str;
} }
rc = debug_set_size(id,id->nr_areas, new_pages); rc = debug_set_size(id, id->nr_areas, new_pages);
if(rc != 0){ if (rc != 0) {
rc = -EINVAL; rc = -EINVAL;
goto free_str; goto free_str;
} }
...@@ -1261,52 +1189,47 @@ debug_input_pages_fn(debug_info_t * id, struct debug_view *view, ...@@ -1261,52 +1189,47 @@ debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
/* /*
* prints out actual debug level * prints out actual debug level
*/ */
static int debug_prolog_level_fn(debug_info_t *id, struct debug_view *view,
static int char *out_buf)
debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf)
{ {
int rc = 0; int rc = 0;
if(id->level == DEBUG_OFF_LEVEL) { if (id->level == DEBUG_OFF_LEVEL)
rc = sprintf(out_buf,"-\n"); rc = sprintf(out_buf, "-\n");
} else
else {
rc = sprintf(out_buf, "%i\n", id->level); rc = sprintf(out_buf, "%i\n", id->level);
}
return rc; return rc;
} }
/* /*
* reads new debug level * reads new debug level
*/ */
static int debug_input_level_fn(debug_info_t *id, struct debug_view *view,
static int struct file *file, const char __user *user_buf,
debug_input_level_fn(debug_info_t * id, struct debug_view *view, size_t user_len, loff_t *offset)
struct file *file, const char __user *user_buf,
size_t user_len, loff_t * offset)
{ {
int rc, new_level;
char *str; char *str;
int rc,new_level;
if (user_len > 0x10000) if (user_len > 0x10000)
user_len = 0x10000; user_len = 0x10000;
if (*offset != 0){ if (*offset != 0) {
rc = -EPIPE; rc = -EPIPE;
goto out; goto out;
} }
str = debug_get_user_string(user_buf,user_len); str = debug_get_user_string(user_buf, user_len);
if(IS_ERR(str)){ if (IS_ERR(str)) {
rc = PTR_ERR(str); rc = PTR_ERR(str);
goto out; goto out;
} }
if(str[0] == '-'){ if (str[0] == '-') {
debug_set_level(id, DEBUG_OFF_LEVEL); debug_set_level(id, DEBUG_OFF_LEVEL);
rc = user_len; rc = user_len;
goto free_str; goto free_str;
} else { } else {
new_level = debug_get_uint(str); new_level = debug_get_uint(str);
} }
if(new_level < 0) { if (new_level < 0) {
pr_warn("%s is not a valid level for a debug feature\n", str); pr_warn("%s is not a valid level for a debug feature\n", str);
rc = -EINVAL; rc = -EINVAL;
} else { } else {
...@@ -1320,99 +1243,90 @@ debug_input_level_fn(debug_info_t * id, struct debug_view *view, ...@@ -1320,99 +1243,90 @@ debug_input_level_fn(debug_info_t * id, struct debug_view *view,
return rc; /* number of input characters */ return rc; /* number of input characters */
} }
/* /*
* flushes debug areas * flushes debug areas
*/ */
static void debug_flush(debug_info_t *id, int area)
static void debug_flush(debug_info_t* id, int area)
{ {
unsigned long flags; unsigned long flags;
int i,j; int i, j;
if(!id || !id->areas) if (!id || !id->areas)
return; return;
spin_lock_irqsave(&id->lock,flags); spin_lock_irqsave(&id->lock, flags);
if(area == DEBUG_FLUSH_ALL){ if (area == DEBUG_FLUSH_ALL) {
id->active_area = 0; id->active_area = 0;
memset(id->active_entries, 0, id->nr_areas * sizeof(int)); memset(id->active_entries, 0, id->nr_areas * sizeof(int));
for (i = 0; i < id->nr_areas; i++) { for (i = 0; i < id->nr_areas; i++) {
id->active_pages[i] = 0; id->active_pages[i] = 0;
for(j = 0; j < id->pages_per_area; j++) { for (j = 0; j < id->pages_per_area; j++)
memset(id->areas[i][j], 0, PAGE_SIZE); memset(id->areas[i][j], 0, PAGE_SIZE);
}
} }
} else if(area >= 0 && area < id->nr_areas) { } else if (area >= 0 && area < id->nr_areas) {
id->active_entries[area] = 0; id->active_entries[area] = 0;
id->active_pages[area] = 0; id->active_pages[area] = 0;
for(i = 0; i < id->pages_per_area; i++) { for (i = 0; i < id->pages_per_area; i++)
memset(id->areas[area][i],0,PAGE_SIZE); memset(id->areas[area][i], 0, PAGE_SIZE);
} }
} spin_unlock_irqrestore(&id->lock, flags);
spin_unlock_irqrestore(&id->lock,flags);
} }
/* /*
* view function: flushes debug areas * view function: flushes debug areas
*/ */
static int debug_input_flush_fn(debug_info_t *id, struct debug_view *view,
static int struct file *file, const char __user *user_buf,
debug_input_flush_fn(debug_info_t * id, struct debug_view *view, size_t user_len, loff_t *offset)
struct file *file, const char __user *user_buf,
size_t user_len, loff_t * offset)
{ {
char input_buf[1]; char input_buf[1];
int rc = user_len; int rc = user_len;
if (user_len > 0x10000) if (user_len > 0x10000)
user_len = 0x10000; user_len = 0x10000;
if (*offset != 0){ if (*offset != 0) {
rc = -EPIPE; rc = -EPIPE;
goto out; goto out;
}
if (copy_from_user(input_buf, user_buf, 1)) {
rc = -EFAULT;
goto out;
}
if (input_buf[0] == '-') {
debug_flush(id, DEBUG_FLUSH_ALL);
goto out;
}
if (isdigit(input_buf[0])) {
int area = ((int) input_buf[0] - (int) '0');
debug_flush(id, area);
goto out;
} }
if (copy_from_user(input_buf, user_buf, 1)){
rc = -EFAULT;
goto out;
}
if(input_buf[0] == '-') {
debug_flush(id, DEBUG_FLUSH_ALL);
goto out;
}
if (isdigit(input_buf[0])) {
int area = ((int) input_buf[0] - (int) '0');
debug_flush(id, area);
goto out;
}
pr_info("Flushing debug data failed because %c is not a valid " pr_info("Flushing debug data failed because %c is not a valid "
"area\n", input_buf[0]); "area\n", input_buf[0]);
out: out:
*offset += user_len; *offset += user_len;
return rc; /* number of input characters */ return rc; /* number of input characters */
} }
/* /*
* prints debug header in raw format * prints debug header in raw format
*/ */
static int debug_raw_header_fn(debug_info_t *id, struct debug_view *view,
static int int area, debug_entry_t *entry, char *out_buf)
debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
int area, debug_entry_t * entry, char *out_buf)
{ {
int rc; int rc;
rc = sizeof(debug_entry_t); rc = sizeof(debug_entry_t);
memcpy(out_buf,entry,sizeof(debug_entry_t)); memcpy(out_buf, entry, sizeof(debug_entry_t));
return rc; return rc;
} }
/* /*
* prints debug data in raw format * prints debug data in raw format
*/ */
static int debug_raw_format_fn(debug_info_t *id, struct debug_view *view,
static int
debug_raw_format_fn(debug_info_t * id, struct debug_view *view,
char *out_buf, const char *in_buf) char *out_buf, const char *in_buf)
{ {
int rc; int rc;
...@@ -1425,20 +1339,17 @@ debug_raw_format_fn(debug_info_t * id, struct debug_view *view, ...@@ -1425,20 +1339,17 @@ debug_raw_format_fn(debug_info_t * id, struct debug_view *view,
/* /*
* prints debug data in hex/ascii format * prints debug data in hex/ascii format
*/ */
static int debug_hex_ascii_format_fn(debug_info_t *id, struct debug_view *view,
static int char *out_buf, const char *in_buf)
debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
char *out_buf, const char *in_buf)
{ {
int i, rc = 0; int i, rc = 0;
for (i = 0; i < id->buf_size; i++) { for (i = 0; i < id->buf_size; i++)
rc += sprintf(out_buf + rc, "%02x ", rc += sprintf(out_buf + rc, "%02x ", ((unsigned char *) in_buf)[i]);
((unsigned char *) in_buf)[i]);
}
rc += sprintf(out_buf + rc, "| "); rc += sprintf(out_buf + rc, "| ");
for (i = 0; i < id->buf_size; i++) { for (i = 0; i < id->buf_size; i++) {
unsigned char c = in_buf[i]; unsigned char c = in_buf[i];
if (isascii(c) && isprint(c)) if (isascii(c) && isprint(c))
rc += sprintf(out_buf + rc, "%c", c); rc += sprintf(out_buf + rc, "%c", c);
else else
...@@ -1451,16 +1362,14 @@ debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view, ...@@ -1451,16 +1362,14 @@ debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
/* /*
* prints header for debug entry * prints header for debug entry
*/ */
int debug_dflt_header_fn(debug_info_t *id, struct debug_view *view,
int int area, debug_entry_t *entry, char *out_buf)
debug_dflt_header_fn(debug_info_t * id, struct debug_view *view,
int area, debug_entry_t * entry, char *out_buf)
{ {
unsigned long base, sec, usec; unsigned long base, sec, usec;
char *except_str;
unsigned long caller; unsigned long caller;
int rc = 0;
unsigned int level; unsigned int level;
char *except_str;
int rc = 0;
level = entry->id.fields.level; level = entry->id.fields.level;
base = (*(unsigned long *) &tod_clock_base[0]) >> 4; base = (*(unsigned long *) &tod_clock_base[0]) >> 4;
...@@ -1486,19 +1395,18 @@ EXPORT_SYMBOL(debug_dflt_header_fn); ...@@ -1486,19 +1395,18 @@ EXPORT_SYMBOL(debug_dflt_header_fn);
#define DEBUG_SPRINTF_MAX_ARGS 10 #define DEBUG_SPRINTF_MAX_ARGS 10
static int static int debug_sprintf_format_fn(debug_info_t *id, struct debug_view *view,
debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view, char *out_buf, debug_sprintf_entry_t *curr_event)
char *out_buf, debug_sprintf_entry_t *curr_event)
{ {
int num_longs, num_used_args = 0,i, rc = 0; int num_longs, num_used_args = 0, i, rc = 0;
int index[DEBUG_SPRINTF_MAX_ARGS]; int index[DEBUG_SPRINTF_MAX_ARGS];
/* count of longs fit into one entry */ /* count of longs fit into one entry */
num_longs = id->buf_size / sizeof(long); num_longs = id->buf_size / sizeof(long);
if(num_longs < 1) if (num_longs < 1)
goto out; /* bufsize of entry too small */ goto out; /* bufsize of entry too small */
if(num_longs == 1) { if (num_longs == 1) {
/* no args, we use only the string */ /* no args, we use only the string */
strcpy(out_buf, curr_event->string); strcpy(out_buf, curr_event->string);
rc = strlen(curr_event->string); rc = strlen(curr_event->string);
...@@ -1506,22 +1414,20 @@ debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view, ...@@ -1506,22 +1414,20 @@ debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
} }
/* number of arguments used for sprintf (without the format string) */ /* number of arguments used for sprintf (without the format string) */
num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1)); num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int)); memset(index, 0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
for(i = 0; i < num_used_args; i++) for (i = 0; i < num_used_args; i++)
index[i] = i; index[i] = i;
rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]], rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
curr_event->args[index[1]], curr_event->args[index[2]], curr_event->args[index[1]], curr_event->args[index[2]],
curr_event->args[index[3]], curr_event->args[index[4]], curr_event->args[index[3]], curr_event->args[index[4]],
curr_event->args[index[5]], curr_event->args[index[6]], curr_event->args[index[5]], curr_event->args[index[6]],
curr_event->args[index[7]], curr_event->args[index[8]], curr_event->args[index[7]], curr_event->args[index[8]],
curr_event->args[index[9]]); curr_event->args[index[9]]);
out: out:
return rc; return rc;
} }
......
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