source: rtems/cpukit/libblock/src/ramdisk-init.c @ 47a471a7

Last change on this file since 47a471a7 was 47a471a7, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 15, 2016 at 1:11:03 PM

libblock: Fix ramdisk::free_at_delete_request init

Avoid uninitialized ramdisk::free_at_delete_request. The error was
visible in sporadic libtests/block01 failures.

  • Property mode set to 100644
File size: 1.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) 2009-2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifdef HAVE_CONFIG_H
24  #include "config.h"
25#endif
26
27#include <stdlib.h>
28
29#include <rtems.h>
30#include <rtems/ramdisk.h>
31
32ramdisk *ramdisk_allocate(
33  void *area_begin,
34  uint32_t media_block_size,
35  rtems_blkdev_bnum media_block_count,
36  bool trace
37)
38{
39  struct ramdisk *rd = calloc(1, sizeof(*rd));
40
41  if (rd == NULL) {
42    return NULL;
43  }
44
45  if (area_begin == NULL) {
46    area_begin = calloc(media_block_count, media_block_size);
47    if (area_begin == NULL) {
48      free(rd);
49
50      return NULL;
51    }
52    rd->malloced = true;
53  } else {
54    rd->malloced = false;
55  }
56  rd->block_size = media_block_size;
57  rd->block_num = media_block_count;
58  rd->area = area_begin;
59  rd->trace = trace;
60  rd->initialized = true;
61
62  return rd;
63}
64
65void ramdisk_free(ramdisk *rd)
66{
67  if (rd != NULL) {
68    if (rd->malloced) {
69      free(rd->area);
70    }
71    free(rd);
72  }
73}
Note: See TracBrowser for help on using the repository browser.