brick_say: ensure that OOM cannot disturb

This commit is contained in:
Thomas Schoebel-Theuer 2012-12-04 18:01:17 +01:00 committed by Thomas Schoebel-Theuer
parent 79b76d41c7
commit ee15a118e0
2 changed files with 20 additions and 12 deletions

View File

@ -216,7 +216,7 @@ char *_brick_string_alloc(int len, int line)
#ifdef CONFIG_MARS_DEBUG #ifdef CONFIG_MARS_DEBUG
res = kzalloc(len + 1024, GFP_BRICK); res = kzalloc(len + 1024, GFP_BRICK);
#else #else
res = kzalloc(len, GFP_BRICK); res = kzalloc(len + 1, GFP_BRICK);
#endif #endif
#ifdef CONFIG_MARS_MEM_RETRY #ifdef CONFIG_MARS_MEM_RETRY
if (likely(res)) if (likely(res))

View File

@ -282,25 +282,28 @@ struct say_channel *_make_channel(const char *name)
say(SAY_ERROR, "cannot create channel '%s'\n", name); say(SAY_ERROR, "cannot create channel '%s'\n", name);
goto done; goto done;
} }
restart:
res = kzalloc(sizeof(struct say_channel), mode); res = kzalloc(sizeof(struct say_channel), mode);
if (unlikely(!res)) { if (unlikely(!res)) {
goto done; schedule();
goto restart;
} }
init_waitqueue_head(&res->ch_progress); init_waitqueue_head(&res->ch_progress);
restart2:
res->ch_name = kstrdup(name, mode); res->ch_name = kstrdup(name, mode);
if (unlikely(!res->ch_name)) { if (unlikely(!res->ch_name)) {
kfree(res); schedule();
goto done; goto restart2;
} }
for (i = 0; i < MAX_SAY_CLASS; i++) { for (i = 0; i < MAX_SAY_CLASS; i++) {
spin_lock_init(&res->ch_lock[i]); spin_lock_init(&res->ch_lock[i]);
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
char *buf = (void*)__get_free_pages(mode, SAY_ORDER); char *buf;
restart3:
buf = (void*)__get_free_pages(mode, SAY_ORDER);
if (unlikely(!buf)) { if (unlikely(!buf)) {
del_channel(res); schedule();
res = NULL; goto restart3;
goto done;
} }
res->ch_buf[i][j] = buf; res->ch_buf[i][j] = buf;
} }
@ -540,10 +543,15 @@ void out_to_syslog(int class, char *buf, int len)
static inline static inline
char *_make_filename(struct say_channel *ch, int class, int transact, int add_tmp) char *_make_filename(struct say_channel *ch, int class, int transact, int add_tmp)
{ {
char *filename = kmalloc(1024, GFP_KERNEL); char *filename;
if (likely(filename)) {
snprintf(filename, 1023, "%s/%d.%s.%s%s", ch->ch_name, class, say_class[class], transact ? "status" : "log", add_tmp ? ".tmp" : ""); restart:
filename = kmalloc(1024, GFP_KERNEL);
if (unlikely(!filename)) {
schedule();
goto restart;
} }
snprintf(filename, 1023, "%s/%d.%s.%s%s", ch->ch_name, class, say_class[class], transact ? "status" : "log", add_tmp ? ".tmp" : "");
return filename; return filename;
} }