-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 215474 b: refs/heads/master c: eecc545 h: refs/heads/master v: v3
- Loading branch information
Patrick McHardy
committed
Oct 4, 2010
1 parent
401210b
commit b62c869
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: f68c53015c5b9aa98ffd87a34009f89bdbbd7160 | ||
refs/heads/master: eecc545856c8a0f27783a440d25f4ceaa1f95ce8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#define S_SIZE (1024 - (sizeof(unsigned int) + 1)) | ||
|
||
struct sbuff { | ||
unsigned int count; | ||
char buf[S_SIZE + 1]; | ||
}; | ||
static struct sbuff emergency, *emergency_ptr = &emergency; | ||
|
||
static int sb_add(struct sbuff *m, const char *f, ...) | ||
{ | ||
va_list args; | ||
int len; | ||
|
||
if (likely(m->count < S_SIZE)) { | ||
va_start(args, f); | ||
len = vsnprintf(m->buf + m->count, S_SIZE - m->count, f, args); | ||
va_end(args); | ||
if (likely(m->count + len < S_SIZE)) { | ||
m->count += len; | ||
return 0; | ||
} | ||
} | ||
m->count = S_SIZE; | ||
printk_once(KERN_ERR KBUILD_MODNAME " please increase S_SIZE\n"); | ||
return -1; | ||
} | ||
|
||
static struct sbuff *sb_open(void) | ||
{ | ||
struct sbuff *m = kmalloc(sizeof(*m), GFP_ATOMIC); | ||
|
||
if (unlikely(!m)) { | ||
local_bh_disable(); | ||
do { | ||
m = xchg(&emergency_ptr, NULL); | ||
} while (!m); | ||
} | ||
m->count = 0; | ||
return m; | ||
} | ||
|
||
static void sb_close(struct sbuff *m) | ||
{ | ||
m->buf[m->count] = 0; | ||
printk("%s\n", m->buf); | ||
|
||
if (likely(m != &emergency)) | ||
kfree(m); | ||
else { | ||
xchg(&emergency_ptr, m); | ||
local_bh_enable(); | ||
} | ||
} | ||
|