source: rtems/cpukit/libblock/src/ramdisk-config.c @ 7a09a7a

4.104.11
Last change on this file since 7a09a7a was 7a09a7a, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 4, 2010 at 2:40:51 PM

2010-03-04 Joel Sherrill <joel.sherrill@…>

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