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

5
Last change on this file since 47a471a7 was 47a471a7, checked in by Sebastian Huber <sebastian.huber@…>, on 01/15/16 at 13:11:03

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
RevLine 
[1560d12]1/**
2 * @file
3 *
4 * @ingroup rtems_ramdisk
5 *
6 * @brief RAM disk block device implementation.
7 */
8
9/*
[5e88538]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>
[1560d12]17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
[c499856]20 * http://www.rtems.org/license/LICENSE.
[1560d12]21 */
22
[694c3ac6]23#ifdef HAVE_CONFIG_H
[5e88538]24  #include "config.h"
[694c3ac6]25#endif
26
[1560d12]27#include <stdlib.h>
28
29#include <rtems.h>
30#include <rtems/ramdisk.h>
31
32ramdisk *ramdisk_allocate(
33  void *area_begin,
[48680bb1]34  uint32_t media_block_size,
35  rtems_blkdev_bnum media_block_count,
[1560d12]36  bool trace
37)
38{
[47a471a7]39  struct ramdisk *rd = calloc(1, sizeof(*rd));
[1560d12]40
41  if (rd == NULL) {
42    return NULL;
43  }
44
45  if (area_begin == NULL) {
[48680bb1]46    area_begin = calloc(media_block_count, media_block_size);
[1560d12]47    if (area_begin == NULL) {
48      free(rd);
49
50      return NULL;
51    }
52    rd->malloced = true;
53  } else {
54    rd->malloced = false;
55  }
[48680bb1]56  rd->block_size = media_block_size;
57  rd->block_num = media_block_count;
[1560d12]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.