]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
check for errors from pthread_create()
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 13 Jan 2019 20:17:03 +0000 (15:17 -0500)
committerKent Overstreet <kent.overstreet@gmail.com>
Sun, 13 Jan 2019 20:17:03 +0000 (15:17 -0500)
include/linux/printk.h
linux/kthread.c

index 4e29af499df6635f213d97b4cac245502baf58e9..8f8dd6b9352caec26d9b43b7c779272c6599e6c6 100644 (file)
 
 static inline int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
 {
-       int i = vsnprintf(buf, size, fmt, args);
-       ssize_t ssize = size;
+       int i;
 
-       return (i >= ssize) ? (ssize - 1) : i;
+       i = vsnprintf(buf, size, fmt, args);
+
+       if (likely(i < size))
+               return i;
+       if (size != 0)
+               return size - 1;
+       return 0;
 }
 
 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
 {
-       ssize_t ssize = size;
-       va_list args;
-       int i;
+       va_list args;
+       int i;
 
-       va_start(args, fmt);
-       i = vsnprintf(buf, size, fmt, args);
-       va_end(args);
+       va_start(args, fmt);
+       i = vscnprintf(buf, size, fmt, args);
+       va_end(args);
 
-       return (i >= ssize) ? (ssize - 1) : i;
+       return i;
 }
 
 #define printk(...)    printf(__VA_ARGS__)
index eef73fe8632eb7c017d3a9a849bbf2e356838748..eaab31db36ef7aeec98ff9ff3962e5ccbb2acc39 100644 (file)
@@ -57,6 +57,7 @@ struct task_struct *kthread_create(int (*thread_fn)(void *data),
 {
        va_list args;
        struct task_struct *p = malloc(sizeof(*p));
+       int ret;
 
        memset(p, 0, sizeof(*p));
 
@@ -71,7 +72,9 @@ struct task_struct *kthread_create(int (*thread_fn)(void *data),
        atomic_set(&p->usage, 1);
        init_completion(&p->exited);
 
-       pthread_create(&p->thread, NULL, kthread_start_fn, p);
+       ret = pthread_create(&p->thread, NULL, kthread_start_fn, p);
+       if (ret)
+               die("pthread_create error %s", strerror(ret));
        pthread_setname_np(p->thread, p->comm);
        return p;
 }