1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/**
* @file
*
* @ingroup rtems_ramdisk
*
* @brief RAM disk block device implementation.
*/
/*
* Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
* Author: Victor V. Vengerov <vvv@oktet.ru>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <rtems.h>
#include <rtems/libio.h>
#include <rtems/ramdisk.h>
rtems_device_driver
ramdisk_initialize(
rtems_device_major_number major,
rtems_device_minor_number minor __attribute__((unused)),
void *arg __attribute__((unused)))
{
rtems_device_minor_number i;
rtems_ramdisk_config *c = rtems_ramdisk_configuration;
struct ramdisk *r;
rtems_status_code rc;
rc = rtems_disk_io_initialize();
if (rc != RTEMS_SUCCESSFUL)
return rc;
/*
* Coverity Id 27 notes that this calloc() is a resource leak.
*
* This is allocating memory for a RAM disk which will persist for
* the life of the system. RTEMS has no "de-initialize" driver call
* so there is no corresponding free(r). Coverity is correct that
* it is never freed but this is not a problem.
*/
r = calloc(rtems_ramdisk_configuration_size, sizeof(struct ramdisk));
r->trace = false;
for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++)
{
dev_t dev = rtems_filesystem_make_dev_t(major, i);
char name [] = RAMDISK_DEVICE_BASE_NAME "a";
name [sizeof(RAMDISK_DEVICE_BASE_NAME)] += i;
r->block_size = c->block_size;
r->block_num = c->block_num;
if (c->location == NULL)
{
r->malloced = true;
r->area = malloc(r->block_size * r->block_num);
if (r->area == NULL) /* No enough memory for this disk */
{
r->initialized = false;
continue;
}
else
{
r->initialized = true;
}
}
else
{
r->malloced = false;
r->initialized = true;
r->area = c->location;
}
rc = rtems_disk_create_phys(dev, c->block_size, c->block_num,
ramdisk_ioctl, r, name);
if (rc != RTEMS_SUCCESSFUL)
{
if (r->malloced)
{
free(r->area);
}
r->initialized = false;
}
}
return RTEMS_SUCCESSFUL;
}
|