Merge linux-3.10.67 into dev-kernel-3.10
[linux-3.10.git] / fs / pstore / ram.c
1 /*
2  * RAM Oops/Panic logger
3  *
4  * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
5  * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
6  * Copyright (C) 2014 NVIDIA Corporation. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
26 #include <linux/kernel.h>
27 #include <linux/err.h>
28 #include <linux/module.h>
29 #include <linux/version.h>
30 #include <linux/pstore.h>
31 #include <linux/time.h>
32 #include <linux/io.h>
33 #include <linux/ioport.h>
34 #include <linux/platform_device.h>
35 #include <linux/slab.h>
36 #include <linux/compiler.h>
37 #include <linux/pstore_ram.h>
38
39 #define RAMOOPS_KERNMSG_HDR "===="
40 #define MIN_MEM_SIZE 4096UL
41
42 static ulong record_size = MIN_MEM_SIZE;
43 module_param(record_size, ulong, 0400);
44 MODULE_PARM_DESC(record_size,
45                 "size of each dump done on oops/panic");
46
47 static ulong ramoops_console_size = MIN_MEM_SIZE;
48 module_param_named(console_size, ramoops_console_size, ulong, 0400);
49 MODULE_PARM_DESC(console_size, "size of kernel console log");
50
51 static ulong ramoops_ftrace_size = MIN_MEM_SIZE;
52 module_param_named(ftrace_size, ramoops_ftrace_size, ulong, 0400);
53 MODULE_PARM_DESC(ftrace_size, "size of ftrace log");
54
55 static ulong ramoops_rtrace_size = MIN_MEM_SIZE;
56 module_param_named(rtrace_size, ramoops_rtrace_size, ulong, 0400);
57 MODULE_PARM_DESC(rtrace_size, "size of rtrace log");
58
59 static ulong mem_address;
60 module_param(mem_address, ulong, 0400);
61 MODULE_PARM_DESC(mem_address,
62                 "start of reserved RAM used to store oops/panic logs");
63
64 static ulong mem_size;
65 module_param(mem_size, ulong, 0400);
66 MODULE_PARM_DESC(mem_size,
67                 "size of reserved RAM used to store oops/panic logs");
68
69 static unsigned int mem_type;
70 module_param(mem_type, uint, 0600);
71 MODULE_PARM_DESC(mem_type,
72                 "set to 1 to try to use unbuffered memory (default 0)");
73
74 static int dump_oops = 1;
75 module_param(dump_oops, int, 0600);
76 MODULE_PARM_DESC(dump_oops,
77                 "set to 1 to dump oopses, 0 to only dump panics (default 1)");
78
79 static int ramoops_ecc;
80 module_param_named(ecc, ramoops_ecc, int, 0600);
81 MODULE_PARM_DESC(ramoops_ecc,
82                 "if non-zero, the option enables ECC support and specifies "
83                 "ECC buffer size in bytes (1 is a special value, means 16 "
84                 "bytes ECC)");
85
86 struct ramoops_context {
87         struct persistent_ram_zone **przs;
88         struct persistent_ram_zone *cprz;
89         struct persistent_ram_zone *fprz;
90         struct persistent_ram_zone *rprz;
91         phys_addr_t phys_addr;
92         unsigned long size;
93         unsigned int memtype;
94         size_t record_size;
95         size_t console_size;
96         size_t ftrace_size;
97         size_t rtrace_size;
98         int dump_oops;
99         struct persistent_ram_ecc_info ecc_info;
100         unsigned int max_dump_cnt;
101         unsigned int dump_write_cnt;
102         /* _read_cnt need clear on ramoops_pstore_open */
103         unsigned int dump_read_cnt;
104         unsigned int console_read_cnt;
105         unsigned int ftrace_read_cnt;
106         unsigned int rtrace_read_cnt;
107         struct pstore_info pstore;
108 };
109
110 static struct platform_device *dummy;
111 static struct ramoops_platform_data *dummy_data;
112
113 static int ramoops_pstore_open(struct pstore_info *psi)
114 {
115         struct ramoops_context *cxt = psi->data;
116
117         cxt->dump_read_cnt = 0;
118         cxt->console_read_cnt = 0;
119         cxt->ftrace_read_cnt = 0;
120         cxt->rtrace_read_cnt = 0;
121         return 0;
122 }
123
124 static struct persistent_ram_zone *
125 ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
126                      u64 *id,
127                      enum pstore_type_id *typep, enum pstore_type_id type,
128                      bool update)
129 {
130         struct persistent_ram_zone *prz;
131         int i = (*c)++;
132
133         if (i >= max)
134                 return NULL;
135
136         prz = przs[i];
137         if (!prz)
138                 return NULL;
139
140         /* Update old/shadowed buffer. */
141         if (update)
142                 persistent_ram_save_old(prz);
143
144         if (!persistent_ram_old_size(prz))
145                 return NULL;
146
147         *typep = type;
148         *id = i;
149
150         return prz;
151 }
152
153 static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
154                                    int *count, struct timespec *time,
155                                    char **buf, struct pstore_info *psi)
156 {
157         ssize_t size;
158         ssize_t ecc_notice_size;
159         struct ramoops_context *cxt = psi->data;
160         struct persistent_ram_zone *prz;
161
162         prz = ramoops_get_next_prz(cxt->przs, &cxt->dump_read_cnt,
163                                    cxt->max_dump_cnt, id, type,
164                                    PSTORE_TYPE_DMESG, 1);
165         if (!prz)
166                 prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt,
167                                            1, id, type, PSTORE_TYPE_CONSOLE, 0);
168         if (!prz)
169                 prz = ramoops_get_next_prz(&cxt->fprz, &cxt->ftrace_read_cnt,
170                                            1, id, type, PSTORE_TYPE_FTRACE, 0);
171         if (!prz)
172                 prz = ramoops_get_next_prz(&cxt->rprz, &cxt->rtrace_read_cnt,
173                                            1, id, type, PSTORE_TYPE_RTRACE, 0);
174         if (!prz)
175                 return 0;
176
177         size = persistent_ram_old_size(prz);
178
179         /* ECC correction notice */
180         ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0);
181
182         if (!(size + ecc_notice_size))
183                 return 0;
184
185         *buf = kmalloc(size + ecc_notice_size + 1, GFP_KERNEL);
186         if (*buf == NULL)
187                 return -ENOMEM;
188
189         memcpy(*buf, persistent_ram_old(prz), size);
190         if (sscanf(*buf, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
191                         &time->tv_sec, &time->tv_nsec) != 2) {
192                 time->tv_sec = 0;
193                 time->tv_nsec = 0;
194         }
195         persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1);
196
197         return size + ecc_notice_size;
198 }
199
200 static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
201 {
202         char *hdr;
203         struct timespec timestamp;
204         size_t len;
205
206         /* Report zeroed timestamp if called before timekeeping has resumed. */
207         if (__getnstimeofday(&timestamp)) {
208                 timestamp.tv_sec = 0;
209                 timestamp.tv_nsec = 0;
210         }
211         hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
212                 (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000));
213         WARN_ON_ONCE(!hdr);
214         len = hdr ? strlen(hdr) : 0;
215         persistent_ram_write(prz, hdr, len);
216         kfree(hdr);
217
218         return len;
219 }
220
221 static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
222                                             enum kmsg_dump_reason reason,
223                                             u64 *id, unsigned int part,
224                                             const char *buf, size_t size,
225                                             struct pstore_info *psi)
226 {
227         struct ramoops_context *cxt = psi->data;
228         struct persistent_ram_zone *prz;
229         size_t hlen;
230
231         if (type == PSTORE_TYPE_CONSOLE) {
232                 if (!cxt->cprz)
233                         return -ENOMEM;
234                 persistent_ram_write(cxt->cprz, buf, size);
235                 return 0;
236         } else if (type == PSTORE_TYPE_FTRACE) {
237                 if (!cxt->fprz)
238                         return -ENOMEM;
239                 persistent_ram_write(cxt->fprz, buf, size);
240                 return 0;
241         } else if (type == PSTORE_TYPE_RTRACE) {
242                 if (!cxt->rprz)
243                         return -ENOMEM;
244                 persistent_ram_write(cxt->rprz, buf, size);
245                 return 0;
246         }
247
248         if (type != PSTORE_TYPE_DMESG)
249                 return -EINVAL;
250
251         /* Out of the various dmesg dump types, ramoops is currently designed
252          * to only store crash logs, rather than storing general kernel logs.
253          */
254         if (reason != KMSG_DUMP_OOPS &&
255             reason != KMSG_DUMP_PANIC)
256                 return -EINVAL;
257
258         /* Skip Oopes when configured to do so. */
259         if (reason == KMSG_DUMP_OOPS && !cxt->dump_oops)
260                 return -EINVAL;
261
262         /* Explicitly only take the first part of any new crash.
263          * If our buffer is larger than kmsg_bytes, this can never happen,
264          * and if our buffer is smaller than kmsg_bytes, we don't want the
265          * report split across multiple records.
266          */
267         if (part != 1)
268                 return -ENOSPC;
269
270         if (!cxt->przs)
271                 return -ENOSPC;
272
273         prz = cxt->przs[cxt->dump_write_cnt];
274
275         hlen = ramoops_write_kmsg_hdr(prz);
276         if (size + hlen > prz->buffer_size)
277                 size = prz->buffer_size - hlen;
278         persistent_ram_write(prz, buf, size);
279
280         cxt->dump_write_cnt = (cxt->dump_write_cnt + 1) % cxt->max_dump_cnt;
281
282         return 0;
283 }
284
285 static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count,
286                                 struct timespec time, struct pstore_info *psi)
287 {
288         struct ramoops_context *cxt = psi->data;
289         struct persistent_ram_zone *prz;
290
291         switch (type) {
292         case PSTORE_TYPE_DMESG:
293                 return -EINVAL;
294                 /* disable erase for the moment
295                 if (id >= cxt->max_dump_cnt)
296                         return -EINVAL;
297                 prz = cxt->przs[id];
298                 break;
299                 */
300         case PSTORE_TYPE_CONSOLE:
301                 prz = cxt->cprz;
302                 break;
303         case PSTORE_TYPE_FTRACE:
304                 prz = cxt->fprz;
305                 break;
306         case PSTORE_TYPE_RTRACE:
307                 prz = cxt->rprz;
308                 break;
309         default:
310                 return -EINVAL;
311         }
312
313         persistent_ram_free_old(prz);
314         persistent_ram_zap(prz);
315
316         return 0;
317 }
318
319 static struct ramoops_context oops_cxt = {
320         .pstore = {
321                 .owner  = THIS_MODULE,
322                 .name   = "ramoops",
323                 .open   = ramoops_pstore_open,
324                 .read   = ramoops_pstore_read,
325                 .write_buf      = ramoops_pstore_write_buf,
326                 .erase  = ramoops_pstore_erase,
327         },
328 };
329
330 static unsigned int
331 ramoops_pstore_get_count(struct persistent_ram_zone *przs[],
332                                    enum pstore_type_id pstore_type,
333                                    unsigned int max)
334 {
335         u64 id;
336         enum pstore_type_id type;
337         unsigned int count = 0;
338
339         while (ramoops_get_next_prz(przs, &count, max, &id, &type,
340                                     pstore_type, 0))
341                 ;
342         if (count)
343                 count--;
344         return count;
345 }
346
347 static void ramoops_free_przs(struct ramoops_context *cxt)
348 {
349         int i;
350
351         if (!cxt->przs)
352                 return;
353
354         for (i = 0; !IS_ERR_OR_NULL(cxt->przs[i]); i++)
355                 persistent_ram_free(cxt->przs[i]);
356         kfree(cxt->przs);
357 }
358
359 static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
360                              phys_addr_t *paddr, size_t dump_mem_sz)
361 {
362         int err = -ENOMEM;
363         int i;
364
365         if (!cxt->record_size)
366                 return 0;
367
368         if (*paddr + dump_mem_sz - cxt->phys_addr > cxt->size) {
369                 dev_err(dev, "no room for dumps\n");
370                 return -ENOMEM;
371         }
372
373         cxt->max_dump_cnt = dump_mem_sz / cxt->record_size;
374         if (!cxt->max_dump_cnt)
375                 return -ENOMEM;
376
377         cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_dump_cnt,
378                              GFP_KERNEL);
379         if (!cxt->przs) {
380                 dev_err(dev, "failed to initialize a prz array for dumps\n");
381                 return -ENOMEM;
382         }
383
384         for (i = 0; i < cxt->max_dump_cnt; i++) {
385                 size_t sz = cxt->record_size;
386
387                 cxt->przs[i] = persistent_ram_new(*paddr, sz, 0,
388                                                   &cxt->ecc_info,
389                                                   cxt->memtype);
390                 if (IS_ERR(cxt->przs[i])) {
391                         err = PTR_ERR(cxt->przs[i]);
392                         dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
393                                 sz, (unsigned long long)*paddr, err);
394                         goto fail_prz;
395                 }
396                 *paddr += sz;
397         }
398
399         cxt->dump_write_cnt = ramoops_pstore_get_count(cxt->przs,
400                                         PSTORE_TYPE_DMESG, cxt->max_dump_cnt);
401         cxt->dump_write_cnt %= cxt->max_dump_cnt;
402
403         return 0;
404 fail_prz:
405         ramoops_free_przs(cxt);
406         return err;
407 }
408
409 static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
410                             struct persistent_ram_zone **prz,
411                             phys_addr_t *paddr, size_t sz, u32 sig)
412 {
413         if (!sz)
414                 return 0;
415
416         if (*paddr + sz - cxt->phys_addr > cxt->size) {
417                 dev_err(dev, "no room for mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
418                         sz, (unsigned long long)*paddr,
419                         cxt->size, (unsigned long long)cxt->phys_addr);
420                 return -ENOMEM;
421         }
422
423         *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, cxt->memtype);
424         if (IS_ERR(*prz)) {
425                 int err = PTR_ERR(*prz);
426
427                 dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
428                         sz, (unsigned long long)*paddr, err);
429                 return err;
430         }
431
432         persistent_ram_zap(*prz);
433
434         *paddr += sz;
435
436         return 0;
437 }
438
439 void notrace ramoops_console_write_buf(const char *buf, size_t size)
440 {
441         struct ramoops_context *cxt = &oops_cxt;
442         persistent_ram_write(cxt->cprz, buf, size);
443 }
444
445 static int ramoops_probe(struct platform_device *pdev)
446 {
447         struct device *dev = &pdev->dev;
448         struct ramoops_platform_data *pdata = pdev->dev.platform_data;
449         struct ramoops_context *cxt = &oops_cxt;
450         size_t dump_mem_sz;
451         phys_addr_t paddr;
452         int err = -EINVAL;
453
454         /* Only a single ramoops area allowed at a time, so fail extra
455          * probes.
456          */
457         if (cxt->max_dump_cnt)
458                 goto fail_out;
459         if ((pdata->mem_size && pdata->record_size) == 0) {
460                 pr_err("The memory size and the record size must be non-zero\n");
461                 goto fail_out;
462         }
463 #ifdef CONFIG_PSTORE_CONSOLE
464         if (pdata->console_size == 0) {
465                 pr_err("PSTORE_CONSOLE is enabled, console size must be non-zero\n");
466                 goto fail_out;
467         }
468 #endif
469 #ifdef CONFIG_PSTORE_FTRACE
470         if (pdata->ftrace_size == 0) {
471                 pr_err("PSTORE_FTRACE is enabled, ftrace size must be non-zero\n");
472                 goto fail_out;
473         }
474 #endif
475 #ifdef CONFIG_PSTORE_RTRACE
476         if (pdata->rtrace_size == 0) {
477                 pr_err("PSTORE_RTRACE is enabled, rtrace size must be non-zero\n");
478                 goto fail_out;
479         }
480 #endif
481         if (pdata->mem_size && !is_power_of_2(pdata->mem_size))
482                 pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
483         if (pdata->record_size && !is_power_of_2(pdata->record_size))
484                 pdata->record_size = rounddown_pow_of_two(pdata->record_size);
485         if (pdata->console_size && !is_power_of_2(pdata->console_size))
486                 pdata->console_size = rounddown_pow_of_two(pdata->console_size);
487         if (pdata->ftrace_size && !is_power_of_2(pdata->ftrace_size))
488                 pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
489         if (pdata->rtrace_size && !is_power_of_2(pdata->rtrace_size))
490                 pdata->rtrace_size = rounddown_pow_of_two(pdata->rtrace_size);
491
492         cxt->size = pdata->mem_size;
493         cxt->phys_addr = pdata->mem_address;
494         cxt->memtype = pdata->mem_type;
495         cxt->record_size = pdata->record_size;
496         cxt->console_size = pdata->console_size;
497         cxt->ftrace_size = pdata->ftrace_size;
498         cxt->rtrace_size = pdata->rtrace_size;
499         cxt->dump_oops = pdata->dump_oops;
500         cxt->ecc_info = pdata->ecc_info;
501
502         paddr = cxt->phys_addr;
503
504         dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size -
505                         cxt->rtrace_size;
506         err = ramoops_init_przs(dev, cxt, &paddr, dump_mem_sz);
507         if (err)
508                 goto fail_out;
509
510 #ifdef CONFIG_PSTORE_CONSOLE
511         err = ramoops_init_prz(dev, cxt, &cxt->cprz, &paddr,
512                                cxt->console_size, 0);
513         if (err)
514                 goto fail_init_cprz;
515 #endif
516 #ifdef CONFIG_PSTORE_FTRACE
517         err = ramoops_init_prz(dev, cxt, &cxt->fprz, &paddr, cxt->ftrace_size,
518                                LINUX_VERSION_CODE);
519         if (err)
520                 goto fail_init_fprz;
521 #endif
522 #ifdef CONFIG_PSTORE_RTRACE
523         err = ramoops_init_prz(dev, cxt, &cxt->rprz, &paddr,
524                                cxt->rtrace_size, 0);
525         if (err)
526                 goto fail_init_rprz;
527 #endif
528         if (!cxt->przs && !cxt->cprz && !cxt->fprz && !cxt->rprz) {
529                 pr_err("memory size too small, minimum is %zu\n",
530                         cxt->console_size + cxt->record_size +
531                         cxt->ftrace_size + cxt->rtrace_size);
532                 err = -EINVAL;
533                 goto fail_cnt;
534         }
535
536         cxt->pstore.data = cxt;
537         /*
538          * Console can handle any buffer size, so prefer LOG_LINE_MAX. If we
539          * have to handle dumps, we must have at least record_size buffer. And
540          * for ftrace, bufsize is irrelevant (if bufsize is 0, buf will be
541          * ZERO_SIZE_PTR).
542          */
543         if (cxt->console_size)
544                 cxt->pstore.bufsize = 1024; /* LOG_LINE_MAX */
545         cxt->pstore.bufsize = max(cxt->record_size, cxt->pstore.bufsize);
546         cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL);
547         spin_lock_init(&cxt->pstore.buf_lock);
548         if (!cxt->pstore.buf) {
549                 pr_err("cannot allocate pstore buffer\n");
550                 err = -ENOMEM;
551                 goto fail_clear;
552         }
553
554         err = pstore_register(&cxt->pstore);
555         if (err) {
556                 pr_err("registering with pstore failed\n");
557                 goto fail_buf;
558         }
559
560         /*
561          * Update the module parameter variables as well so they are visible
562          * through /sys/module/ramoops/parameters/
563          */
564         mem_size = pdata->mem_size;
565         mem_address = pdata->mem_address;
566         record_size = pdata->record_size;
567         dump_oops = pdata->dump_oops;
568
569         pr_info("attached 0x%lx@0x%llx, ecc: %d/%d\n",
570                 cxt->size, (unsigned long long)cxt->phys_addr,
571                 cxt->ecc_info.ecc_size, cxt->ecc_info.block_size);
572
573         return 0;
574
575 fail_buf:
576         kfree(cxt->pstore.buf);
577 fail_clear:
578         cxt->pstore.bufsize = 0;
579         cxt->max_dump_cnt = 0;
580 fail_cnt:
581         kfree(cxt->rprz);
582 fail_init_rprz:
583         kfree(cxt->fprz);
584 fail_init_fprz:
585         kfree(cxt->cprz);
586 fail_init_cprz:
587         ramoops_free_przs(cxt);
588 fail_out:
589         return err;
590 }
591
592 static int __exit ramoops_remove(struct platform_device *pdev)
593 {
594 #if 0
595         /* TODO(kees): We cannot unload ramoops since pstore doesn't support
596          * unregistering yet.
597          */
598         struct ramoops_context *cxt = &oops_cxt;
599
600         iounmap(cxt->virt_addr);
601         release_mem_region(cxt->phys_addr, cxt->size);
602         cxt->max_dump_cnt = 0;
603
604         /* TODO(kees): When pstore supports unregistering, call it here. */
605         kfree(cxt->pstore.buf);
606         cxt->pstore.bufsize = 0;
607
608         return 0;
609 #endif
610         return -EBUSY;
611 }
612
613 static struct platform_driver ramoops_driver = {
614         .probe          = ramoops_probe,
615         .remove         = __exit_p(ramoops_remove),
616         .driver         = {
617                 .name   = "ramoops",
618                 .owner  = THIS_MODULE,
619         },
620 };
621
622 static void ramoops_register_dummy(void)
623 {
624         if (!mem_size)
625                 return;
626
627         pr_info("using module parameters\n");
628
629         dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL);
630         if (!dummy_data) {
631                 pr_info("could not allocate pdata\n");
632                 return;
633         }
634
635         dummy_data->mem_size = mem_size;
636         dummy_data->mem_address = mem_address;
637         dummy_data->mem_type = 0;
638         dummy_data->record_size = record_size;
639         dummy_data->console_size = ramoops_console_size;
640         dummy_data->ftrace_size = ramoops_ftrace_size;
641         dummy_data->rtrace_size = ramoops_rtrace_size;
642         dummy_data->dump_oops = dump_oops;
643         /*
644          * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC
645          * (using 1 byte for ECC isn't much of use anyway).
646          */
647         dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc;
648
649         dummy = platform_device_register_data(NULL, "ramoops", -1,
650                         dummy_data, sizeof(struct ramoops_platform_data));
651         if (IS_ERR(dummy)) {
652                 pr_info("could not create platform device: %ld\n",
653                         PTR_ERR(dummy));
654         }
655 }
656
657 static int __init ramoops_init(void)
658 {
659         ramoops_register_dummy();
660         return platform_driver_register(&ramoops_driver);
661 }
662 postcore_initcall(ramoops_init);
663
664 static void __exit ramoops_exit(void)
665 {
666         platform_driver_unregister(&ramoops_driver);
667         platform_device_unregister(dummy);
668         kfree(dummy_data);
669 }
670 module_exit(ramoops_exit);
671
672 MODULE_LICENSE("GPL");
673 MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>");
674 MODULE_DESCRIPTION("RAM Oops/Panic logger/driver");