Merge tag 'microblaze-3.15-rc1' of git://git.monstr.eu/linux-2.6-microblaze
[cascardo/linux.git] / drivers / staging / unisys / visorutil / visorkmodutils.c
1 /* timskmodutils.c
2  *
3  * Copyright © 2010 - 2013 UNISYS CORPORATION
4  * All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or (at
9  * your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14  * NON INFRINGEMENT.  See the GNU General Public License for more
15  * details.
16  */
17
18 #include "uniklog.h"
19 #include "timskmod.h"
20
21 #define MYDRVNAME "timskmodutils"
22
23 /** Callers to interfaces that set __GFP_NORETRY flag below
24  *  must check for a NULL (error) result as we are telling the
25  *  kernel interface that it is okay to fail.
26  */
27
28 void *kmalloc_kernel(size_t siz)
29 {
30         return kmalloc(siz, GFP_KERNEL | __GFP_NORETRY);
31 }
32
33 /*  Use these handy-dandy seq_file_xxx functions if you want to call some
34  *  functions that write stuff into a seq_file, but you actually just want
35  *  to dump that output into a buffer.  Use them as follows:
36  *  - call visor_seq_file_new_buffer to create the seq_file (you supply the buf)
37  *  - call whatever functions you want that take a seq_file as an argument
38  *    (the buf you supplied will get the output data)
39  *  - call visor_seq_file_done_buffer to dispose of your seq_file
40  */
41 struct seq_file *visor_seq_file_new_buffer(void *buf, size_t buf_size)
42 {
43         struct seq_file *rc = NULL;
44         struct seq_file *m = kmalloc_kernel(sizeof(struct seq_file));
45
46         if (m == NULL) {
47                 rc = NULL;
48                 goto Away;
49         }
50         memset(m, 0, sizeof(struct seq_file));
51         m->buf = buf;
52         m->size = buf_size;
53         rc = m;
54 Away:
55         if (rc == NULL) {
56                 visor_seq_file_done_buffer(m);
57                 m = NULL;
58         }
59         return rc;
60 }
61 EXPORT_SYMBOL_GPL(visor_seq_file_new_buffer);
62
63
64
65 void visor_seq_file_done_buffer(struct seq_file *m)
66 {
67         if (!m)
68                 return;
69         kfree(m);
70 }
71 EXPORT_SYMBOL_GPL(visor_seq_file_done_buffer);