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

4.104.11
Last change on this file since c4c8efd was c4c8efd, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 19, 2010 at 2:23:03 AM

2010-01-18 Joel Sherrill <joel.sherrill@…>

Coverity Id 27

  • libblock/src/ramdisk-config.c: Coverity notes that the 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.
  • Property mode set to 100644
File size: 2.3 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 notes 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    return RTEMS_SUCCESSFUL;
86}
Note: See TracBrowser for help on using the repository browser.