source: rtems/tools/cpu/nios2/memory.c @ 17f71fc7

5
Last change on this file since 17f71fc7 was 17f71fc7, checked in by Martin Galvan <martin.galvan@…>, on 09/02/15 at 21:54:22

tools/cpu/nios2/memory.c: Fix uninitialized use of variable memory

Updates #2405.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.org/license/LICENSE.
7 */
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#include "ptf.h"
14#include "devices.h"
15#include "memory.h"
16
17memory_desc *find_memory(device_desc *devices)
18{
19  struct ptf *p;
20  struct ptf_item pi;
21  memory_desc *tmd;
22  memory_desc *memory = NULL;
23
24  /********************************************************/
25  /* Check which of the devices are memory, sort by size */
26
27  if(devices)
28  {
29    struct ptf *p, *s;
30    struct ptf_item pi;
31    device_desc *dd;
32
33    for(dd = devices; dd; dd=dd->next)
34    {
35      p = ptf_find(dd->ptf->sub, &pi, item, "Is_Memory_Device", "1");
36      if(p != NULL && pi.level>0)
37      {
38        s = pi.item[pi.level-1];
39        p = ptf_find(s, &pi, item, "Base_Address", 0);
40      };
41
42      if(p != NULL)
43      {
44        tmd = (memory_desc*)malloc(sizeof(memory_desc));
45
46        if(tmd != NULL)
47        {
48          tmd->base = strtoul(p->value, 0, 0);
49
50          p = ptf_find(s, &pi, item, "Address_Span", 0);
51          if(p != 0)
52          {
53            tmd->size = strtoul(p->value, 0, 0);
54          }
55          else
56          {
57            tmd->size = 0;
58            p = ptf_find(s, &pi, item, "Address_Width", 0);
59            if(p) tmd->size = 1 << strtoul(p->value, 0, 0);
60            p = ptf_find(s, &pi, item, "Data_Width", 0);
61            if(p) tmd->size *= (strtoul(p->value, 0, 0) >> 3);
62          };
63
64          if(tmd->size == 0)
65          {
66            free(tmd);
67          }
68          else
69          {
70            tmd->dev = dd;
71
72            if(memory == NULL)
73            {
74              tmd->next = NULL;
75              memory = tmd;
76            }
77            else
78            {
79              if(tmd->size > memory->size)
80              {
81                tmd->next = memory;
82                memory = tmd;
83              }
84              else
85              {
86                memory_desc *uplink = memory;
87                while(uplink->next != NULL && uplink->next->size > tmd->size) uplink=uplink->next;
88                tmd->next = uplink->next;
89                uplink->next = tmd;
90              };
91            };
92          };
93        };
94      };
95    };
96  };
97
98  return memory;
99}
100
101
Note: See TracBrowser for help on using the repository browser.