summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-11-26 15:55:38 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-12-21 14:54:13 +0100
commit11f3b9a535ced87882a9792b01b3b7800d355482 (patch)
tree7e641e16744706f9d72a411e775429a30a7b02e5
parentspcxx01: Add test case (diff)
downloadrtems-11f3b9a535ced87882a9792b01b3b7800d355482.tar.bz2
bsps/sparc: Add grlib_malloc(), grlib_calloc()
This avoids a dependency to errno in device driver code.
-rw-r--r--bsps/sparc/include/bsp/gr1553rt.h2
-rw-r--r--bsps/sparc/include/grlib_impl.h27
-rw-r--r--bsps/sparc/shared/1553/b1553brm.c11
-rw-r--r--bsps/sparc/shared/1553/b1553rt.c9
-rw-r--r--bsps/sparc/shared/1553/gr1553b.c10
-rw-r--r--bsps/sparc/shared/1553/gr1553bc.c23
-rw-r--r--bsps/sparc/shared/1553/gr1553bm.c5
-rw-r--r--bsps/sparc/shared/1553/gr1553rt.c21
-rw-r--r--bsps/sparc/shared/amba/ambapp.c4
-rw-r--r--bsps/sparc/shared/analog/gradcdac.c5
-rw-r--r--bsps/sparc/shared/ascs/grascs.c6
-rw-r--r--bsps/sparc/shared/btimer/gptimer.c5
-rw-r--r--bsps/sparc/shared/can/canmux.c4
-rw-r--r--bsps/sparc/shared/can/grcan.c7
-rw-r--r--bsps/sparc/shared/can/occan.c13
-rw-r--r--bsps/sparc/shared/can/satcan.c8
-rw-r--r--bsps/sparc/shared/drvmgr/ambapp_bus_grlib.c4
-rw-r--r--bsps/sparc/shared/gpio/gpiolib.c5
-rw-r--r--bsps/sparc/shared/gpio/grgpio.c4
-rw-r--r--bsps/sparc/shared/i2c/i2cmst.c5
-rw-r--r--bsps/sparc/shared/iommu/griommu.c4
-rw-r--r--bsps/sparc/shared/irq/genirq.c15
-rw-r--r--bsps/sparc/shared/mem/mctrl.c5
-rw-r--r--bsps/sparc/shared/net/greth.c18
-rw-r--r--bsps/sparc/shared/pci/gr_701.c3
-rw-r--r--bsps/sparc/shared/pci/gr_rasta_adcdac.c3
-rw-r--r--bsps/sparc/shared/pci/gr_rasta_io.c3
-rw-r--r--bsps/sparc/shared/pci/gr_tmtc_1553.c3
-rw-r--r--bsps/sparc/shared/pci/grpci2dma.c9
-rw-r--r--bsps/sparc/shared/pwm/grpwm.c7
-rw-r--r--bsps/sparc/shared/slink/grslink.c12
-rw-r--r--bsps/sparc/shared/spi/spictrl.c5
-rw-r--r--bsps/sparc/shared/spw/grspw.c15
-rw-r--r--bsps/sparc/shared/spw/grspw_pkt.c11
-rw-r--r--bsps/sparc/shared/time/grctm.c5
-rw-r--r--bsps/sparc/shared/time/spwcuc.c7
-rw-r--r--bsps/sparc/shared/tmtc/grtc.c5
-rw-r--r--bsps/sparc/shared/tmtc/grtm.c8
38 files changed, 176 insertions, 140 deletions
diff --git a/bsps/sparc/include/bsp/gr1553rt.h b/bsps/sparc/include/bsp/gr1553rt.h
index 55237b5dfd..5d52e84c11 100644
--- a/bsps/sparc/include/bsp/gr1553rt.h
+++ b/bsps/sparc/include/bsp/gr1553rt.h
@@ -74,7 +74,7 @@ struct gr1553rt_list {
/* !!Must be last in data structure!!
* !!Array must at least be of length bd_cnt!!
*/
- unsigned short bds[1]; /* Array of BDIDs, -1 unused/end */
+ unsigned short bds[0]; /* Array of BDIDs */
};
/* GR1553B-RT Driver configuration options used when calling gr1553rt_config().
diff --git a/bsps/sparc/include/grlib_impl.h b/bsps/sparc/include/grlib_impl.h
index 2760c68626..755f635911 100644
--- a/bsps/sparc/include/grlib_impl.h
+++ b/bsps/sparc/include/grlib_impl.h
@@ -10,6 +10,7 @@
#define GRLIB_IMPL_H
#include <rtems/score/basedefs.h>
+#include <rtems/malloc.h>
/*
* Use interrupt lock primitives compatible with SMP defined in RTEMS 4.11.99
@@ -63,6 +64,32 @@
extern "C" {
#endif
+#if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) >= 0x050000)
+
+RTEMS_INLINE_ROUTINE void *grlib_malloc(size_t size)
+{
+ return rtems_malloc(size);
+}
+
+RTEMS_INLINE_ROUTINE void *grlib_calloc(size_t nelem, size_t elsize)
+{
+ return rtems_calloc(nelem, elsize);
+}
+
+#else
+
+RTEMS_INLINE_ROUTINE void *grlib_malloc(size_t size)
+{
+ return malloc(size);
+}
+
+RTEMS_INLINE_ROUTINE void *grlib_calloc(size_t nelem, size_t elsize)
+{
+ return calloc(nelem, elsize);
+}
+
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/bsps/sparc/shared/1553/b1553brm.c b/bsps/sparc/shared/1553/b1553brm.c
index 8a5efaf9df..216397b334 100644
--- a/bsps/sparc/shared/1553/b1553brm.c
+++ b/bsps/sparc/shared/1553/b1553brm.c
@@ -31,6 +31,8 @@
#include <ambapp.h>
#include <drvmgr/ambapp_bus.h>
+#include <grlib_impl.h>
+
/* Uncomment for debug output */
/*#define DEBUG 1
#define FUNCDEBUG 1*/
@@ -309,10 +311,9 @@ int b1553brm_init2(struct drvmgr_dev *dev)
brm_priv *priv;
DBG("B1553BRM[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(brm_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
@@ -472,7 +473,7 @@ int b1553brm_device_init(brm_priv *pDev)
/* Use dynamically allocated memory + 128k for
* alignment
*/
- mem = (unsigned int)malloc(size + 128 * 1024);
+ mem = (unsigned int)grlib_malloc(size + 128 * 1024);
if (!mem){
printk("BRM: Failed to allocate HW memory\n\r");
return -1;
@@ -631,7 +632,7 @@ static rtems_device_driver rt_init(brm_priv *brm) {
brm->bcmem = NULL;
brm->rtmem = (void *)brm->mem;
- brm->rt_event = (struct rt_msg *) malloc(EVENT_QUEUE_SIZE*sizeof(struct rt_msg));
+ brm->rt_event = grlib_malloc(EVENT_QUEUE_SIZE*sizeof(*brm->rt_event));
if (brm->rt_event == NULL) {
DBG("BRM driver failed to allocated memory.");
@@ -759,7 +760,7 @@ static rtems_device_driver bm_init(brm_priv *brm) {
brm->bcmem = NULL;
brm->rtmem = NULL;
- brm->bm_event = (struct bm_msg *) malloc(EVENT_QUEUE_SIZE*sizeof(struct bm_msg));
+ brm->bm_event = grlib_malloc(EVENT_QUEUE_SIZE*sizeof(*brm->bm_event));
if (brm->bm_event == NULL) {
DBG("BRM driver failed to allocated memory.");
diff --git a/bsps/sparc/shared/1553/b1553rt.c b/bsps/sparc/shared/1553/b1553rt.c
index b076abdc5d..9d2a22d70b 100644
--- a/bsps/sparc/shared/1553/b1553rt.c
+++ b/bsps/sparc/shared/1553/b1553rt.c
@@ -23,6 +23,8 @@
#include <ambapp.h>
#include <drvmgr/ambapp_bus.h>
+#include <grlib_impl.h>
+
/* Uncomment for debug output */
/*#define DEBUG 1*/
@@ -167,10 +169,9 @@ int b1553rt_init2(struct drvmgr_dev *dev)
rt_priv *priv;
DBG("B1553RT[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(rt_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
@@ -318,7 +319,7 @@ int b1553rt_device_init(rt_priv *pDev)
/* Use dynamically allocated memory,
* 4k DMA memory + 4k for alignment
*/
- mem = (unsigned int)malloc(4 * 1024 * 2);
+ mem = (unsigned int)grlib_malloc(4 * 1024 * 2);
if ( !mem ){
printk("RT: Failed to allocate HW memory\n\r");
return -1;
@@ -458,7 +459,7 @@ static rtems_device_driver rt_init(rt_priv *rt)
free(rt->rt_event);
rt->rt_event = NULL;
- rt->rt_event = (struct rt_msg *) malloc(EVENT_QUEUE_SIZE*sizeof(struct rt_msg));
+ rt->rt_event = grlib_malloc(EVENT_QUEUE_SIZE*sizeof(*rt->rt_event));
if (rt->rt_event == NULL) {
DBG("RT driver failed to allocated memory.");
diff --git a/bsps/sparc/shared/1553/gr1553b.c b/bsps/sparc/shared/1553/gr1553b.c
index c05d53a4f9..ba75398f63 100644
--- a/bsps/sparc/shared/1553/gr1553b.c
+++ b/bsps/sparc/shared/1553/gr1553b.c
@@ -13,6 +13,8 @@
#include <bsp/gr1553b.h>
+#include <grlib_impl.h>
+
/* Driver Manager interface for BC, RT, BM, BRM, BC-BM and RT-BM */
#define GR1553B_WRITE_REG(adr, val) *(volatile uint32_t *)(adr) = (val)
@@ -219,7 +221,7 @@ static int gr1553_init3(struct drvmgr_dev *dev)
struct gr1553_device_feature *feat;
struct gr1553b_regs *regs;
- priv = malloc(sizeof(struct gr1553_device));
+ priv = grlib_malloc(sizeof(*priv));
if ( priv == NULL )
return DRVMGR_NOMEM;
priv->dev = dev;
@@ -234,7 +236,7 @@ static int gr1553_init3(struct drvmgr_dev *dev)
if ( GR1553B_READ_REG(&regs->bm_stat) & GR1553B_BM_STAT_BMSUP ) {
priv->features |= FEAT_BM;
- feat = malloc(sizeof(struct gr1553_device_feature));
+ feat = grlib_malloc(sizeof(*feat));
feat->dev = priv;
/* Init Minor and Next */
gr1553_list_add(&gr1553_bm_root, feat);
@@ -242,7 +244,7 @@ static int gr1553_init3(struct drvmgr_dev *dev)
if ( GR1553B_READ_REG(&regs->bc_stat) & GR1553B_BC_STAT_BCSUP ) {
priv->features |= FEAT_BC;
- feat = malloc(sizeof(struct gr1553_device_feature));
+ feat = grlib_malloc(sizeof(*feat));
feat->dev = priv;
/* Init Minor and Next */
gr1553_list_add(&gr1553_bc_root, feat);
@@ -250,7 +252,7 @@ static int gr1553_init3(struct drvmgr_dev *dev)
if ( GR1553B_READ_REG(&regs->rt_stat) & GR1553B_RT_STAT_RTSUP ) {
priv->features |= FEAT_RT;
- feat = malloc(sizeof(struct gr1553_device_feature));
+ feat = grlib_malloc(sizeof(*feat));
feat->dev = priv;
/* Init Minor and Next */
gr1553_list_add(&gr1553_rt_root, feat);
diff --git a/bsps/sparc/shared/1553/gr1553bc.c b/bsps/sparc/shared/1553/gr1553bc.c
index 099976f958..c7faba436d 100644
--- a/bsps/sparc/shared/1553/gr1553bc.c
+++ b/bsps/sparc/shared/1553/gr1553bc.c
@@ -90,14 +90,13 @@ struct gr1553bc_list_cfg gr1553bc_def_cfg =
int gr1553bc_list_alloc(struct gr1553bc_list **list, int max_major)
{
- int size;
+ size_t size;
struct gr1553bc_list *l;
- size = sizeof(struct gr1553bc_list) + max_major * sizeof(void *);
- l = malloc(size);
+ size = sizeof(*l) + max_major * sizeof(void *);
+ l = grlib_calloc(1, size);
if ( l == NULL )
return -1;
- memset(l, 0, size);
l->major_cnt = max_major;
*list = l;
@@ -310,7 +309,7 @@ int gr1553bc_list_table_alloc
} else {
if (bdtab_custom == NULL) {
/* Allocate descriptors */
- list->_table = malloc(size + (GR1553BC_BD_ALIGN-1));
+ list->_table = grlib_malloc(size + (GR1553BC_BD_ALIGN-1));
if ( list->_table == NULL )
return -1;
} else {
@@ -508,15 +507,16 @@ int gr1553bc_major_alloc_skel
{
struct gr1553bc_major *maj;
struct gr1553bc_minor *minor;
- int size, i;
+ size_t size;
+ int i;
if ( (cfg == NULL) || (major == NULL) || (cfg->minor_cnt <= 0) )
return -1;
/* Allocate Major Frame description, but no descriptors */
- size = sizeof(struct gr1553bc_major) + cfg->minor_cnt *
- (sizeof(struct gr1553bc_minor) + sizeof(void *));
- maj = (struct gr1553bc_major *)malloc(size);
+ size = sizeof(*maj) + cfg->minor_cnt *
+ (sizeof(*minor) + sizeof(void *));
+ maj = grlib_malloc(size);
if ( maj == NULL )
return -1;
@@ -1248,14 +1248,13 @@ void *gr1553bc_open(int minor)
if ( pdev == NULL )
goto fail;
- irq_log_p = malloc(GR1553BC_IRQLOG_SIZE*2);
+ irq_log_p = grlib_malloc(GR1553BC_IRQLOG_SIZE*2);
if ( irq_log_p == NULL )
goto fail;
- priv = malloc(sizeof(struct gr1553bc_priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( priv == NULL )
goto fail;
- memset(priv, 0, sizeof(struct gr1553bc_priv));
/* Init BC device */
priv->pdev = pdev;
diff --git a/bsps/sparc/shared/1553/gr1553bm.c b/bsps/sparc/shared/1553/gr1553bm.c
index 040dbf0d92..1897a16f79 100644
--- a/bsps/sparc/shared/1553/gr1553bm.c
+++ b/bsps/sparc/shared/1553/gr1553bm.c
@@ -129,10 +129,9 @@ void *gr1553bm_open(int minor)
if ( pdev == NULL )
goto fail;
- priv = malloc(sizeof(struct gr1553bm_priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( priv == NULL )
goto fail;
- memset(priv, 0, sizeof(struct gr1553bm_priv));
/* Init BC device */
priv->pdev = pdev;
@@ -209,7 +208,7 @@ int gr1553bm_config(void *bm, struct gr1553bm_config *cfg)
} else {
if (cfg->buffer_custom == NULL) {
/* Allocate new buffer dynamically */
- priv->buffer = malloc(priv->buffer_size + 8);
+ priv->buffer = grlib_malloc(priv->buffer_size + 8);
if (priv->buffer == NULL)
return -1;
} else {
diff --git a/bsps/sparc/shared/1553/gr1553rt.c b/bsps/sparc/shared/1553/gr1553rt.c
index 7f2e75af3e..8a869c9152 100644
--- a/bsps/sparc/shared/1553/gr1553rt.c
+++ b/bsps/sparc/shared/1553/gr1553rt.c
@@ -239,7 +239,8 @@ int gr1553rt_list_init
)
{
struct gr1553rt_priv *priv = rt;
- int i, size;
+ size_t size;
+ int i;
struct gr1553rt_sw_bd *swbd;
unsigned short index;
struct gr1553rt_list *list;
@@ -253,9 +254,9 @@ int gr1553rt_list_init
list = *plist;
if ( list == NULL ) {
/* Dynamically allocate LIST */
- size = offsetof(struct gr1553rt_list, bds) +
- (cfg->bd_cnt * sizeof(unsigned short));
- list = (struct gr1553rt_list *)malloc(size);
+ size = sizeof(*list) +
+ (cfg->bd_cnt * sizeof(list->bds[0]));
+ list = grlib_malloc(size);
if ( list == NULL )
return -1;
*plist = list;
@@ -661,10 +662,9 @@ void *gr1553rt_open(int minor)
if ( pdev == NULL )
goto fail;
- priv = malloc(sizeof(struct gr1553rt_priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( priv == NULL )
goto fail;
- memset(priv, 0, sizeof(struct gr1553rt_priv));
/* Assign a device private to RT device */
priv->pdev = pdev;
@@ -786,7 +786,8 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
);
} else {
if (priv->cfg.evlog_buffer == NULL) {
- priv->evlog_buffer = malloc(priv->cfg.evlog_size * 2);
+ priv->evlog_buffer = grlib_malloc(
+ priv->cfg.evlog_size * 2);
if (priv->evlog_buffer == NULL)
return -1;
} else {
@@ -826,7 +827,7 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
);
} else {
if ( priv->cfg.bd_buffer == NULL ) {
- priv->bd_buffer = malloc(size + 0xf);
+ priv->bd_buffer = grlib_malloc(size + 0xf);
if (priv->bd_buffer == NULL)
return -1;
} else {
@@ -849,7 +850,7 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
#if (RTBD_MAX == 0)
/* Allocate software description of */
- priv->swbds = malloc(priv->cfg.bd_count * sizeof(struct gr1553rt_sw_bd));
+ priv->swbds = grlib_malloc(priv->cfg.bd_count * sizeof(*priv->swbds));
if ( priv->swbds == NULL ) {
return -1;
}
@@ -869,7 +870,7 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
16 * 32);
} else {
if (priv->cfg.satab_buffer == NULL) {
- priv->satab_buffer = malloc((16 * 32) * 2);
+ priv->satab_buffer = grlib_malloc((16 * 32) * 2);
if (priv->satab_buffer == NULL)
return -1;
} else {
diff --git a/bsps/sparc/shared/amba/ambapp.c b/bsps/sparc/shared/amba/ambapp.c
index e3c777a5f5..4fb8405103 100644
--- a/bsps/sparc/shared/amba/ambapp.c
+++ b/bsps/sparc/shared/amba/ambapp.c
@@ -16,6 +16,8 @@
#include <ambapp.h>
#include <bsp.h>
+#include <grlib_impl.h>
+
#define AMBA_CONF_AREA 0xff000
#define AMBA_AHB_SLAVE_CONF_AREA (1 << 11)
#define AMBA_APB_SLAVES 16
@@ -30,7 +32,7 @@ static struct ambapp_dev *ambapp_alloc_dev_struct(int dev_type)
size += sizeof(struct ambapp_apb_info);
else
size += sizeof(struct ambapp_ahb_info); /* AHB */
- dev = (struct ambapp_dev *)calloc(1, size);
+ dev = grlib_calloc(1, size);
if (dev != NULL)
dev->dev_type = dev_type;
return dev;
diff --git a/bsps/sparc/shared/analog/gradcdac.c b/bsps/sparc/shared/analog/gradcdac.c
index 07fb2ee9dd..bbe6620060 100644
--- a/bsps/sparc/shared/analog/gradcdac.c
+++ b/bsps/sparc/shared/analog/gradcdac.c
@@ -29,6 +29,8 @@
*/
#include <bsp/debug_defs.h>
+#include <grlib_impl.h>
+
struct gradcdac_priv {
struct gradcdac_regs *regs; /* Must be first */
struct drvmgr_dev *dev;
@@ -99,10 +101,9 @@ int gradcdac_init2(struct drvmgr_dev *dev)
DBG("GRADCDAC[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(struct gradcdac_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
diff --git a/bsps/sparc/shared/ascs/grascs.c b/bsps/sparc/shared/ascs/grascs.c
index 11663b2ccc..1c7599575e 100644
--- a/bsps/sparc/shared/ascs/grascs.c
+++ b/bsps/sparc/shared/ascs/grascs.c
@@ -13,6 +13,8 @@
#include <ambapp.h>
#include <bsp/grascs.h>
+#include <grlib_impl.h>
+
#ifndef GAISLER_ASCS
#define GAISLER_ASCS 0x043
#endif
@@ -196,12 +198,12 @@ int ASCS_init(void) {
DBG("ASCS_init: Starting initialization of ASCS core\n");
/* Allocate memory for config, status and capability struct */
- if((cfg = (GRASCS_cfg*)malloc(sizeof(GRASCS_cfg))) == NULL) {
+ if((cfg = grlib_malloc(sizeof(*cfg))) == NULL) {
DBG("ASCS_init: Could not allocate memory for cfg struc\n");
return -1;
}
- if((cfg->caps = (GRASCS_caps*)calloc(1,sizeof(GRASCS_caps))) == NULL) {
+ if((cfg->caps = grlib_calloc(1,sizeof(*cfg->caps))) == NULL) {
DBG("ASCS_init: Could not allocate memory for caps struc\n");
goto init_error1;
}
diff --git a/bsps/sparc/shared/btimer/gptimer.c b/bsps/sparc/shared/btimer/gptimer.c
index 08e498178e..6174acc007 100644
--- a/bsps/sparc/shared/btimer/gptimer.c
+++ b/bsps/sparc/shared/btimer/gptimer.c
@@ -54,6 +54,8 @@
#include <rtems/score/smpimpl.h>
#endif
+#include <grlib_impl.h>
+
/* GPTIMER Core Configuration Register (READ-ONLY) */
#define GPTIMER_CFG_TIMERS_BIT 0
#define GPTIMER_CFG_IRQ_BIT 3
@@ -231,10 +233,9 @@ int gptimer_init1(struct drvmgr_dev *dev)
*/
size = sizeof(struct gptimer_priv) +
timer_cnt*sizeof(struct gptimer_timer);
- priv = dev->priv = (struct gptimer_priv *)malloc(size);
+ priv = dev->priv = grlib_calloc(1, size);
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, size);
priv->dev = dev;
priv->regs = regs;
diff --git a/bsps/sparc/shared/can/canmux.c b/bsps/sparc/shared/can/canmux.c
index 1d9d371157..ca2125aefd 100644
--- a/bsps/sparc/shared/can/canmux.c
+++ b/bsps/sparc/shared/can/canmux.c
@@ -19,6 +19,8 @@
#include <bsp/canmux.h>
#include <ambapp.h>
+#include <grlib_impl.h>
+
#ifndef GAISLER_CANMUX
#define GAISLER_CANMUX 0x081
#endif
@@ -140,7 +142,7 @@ static rtems_device_driver canmux_initialize(rtems_device_major_number major, rt
rtems_fatal_error_occurred(status);
/* Create private structure */
- if ((priv = malloc(sizeof(struct canmux_priv))) == NULL) {
+ if ((priv = grlib_malloc(sizeof(*priv))) == NULL) {
printk("CAN_MUX driver could not allocate memory for priv structure\n\r");
return -1;
}
diff --git a/bsps/sparc/shared/can/grcan.c b/bsps/sparc/shared/can/grcan.c
index 6762c96b44..03faec915c 100644
--- a/bsps/sparc/shared/can/grcan.c
+++ b/bsps/sparc/shared/can/grcan.c
@@ -256,10 +256,9 @@ int grcan_init2(struct drvmgr_dev *dev)
DBG("GRCAN[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
if (GRCAN_COUNT_MAX <= grcan_count)
return DRVMGR_ENORES;
- priv = dev->priv = malloc(sizeof(struct grcan_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
@@ -1113,7 +1112,7 @@ static int grcan_alloc_buffers(struct grcan_priv *pDev, int rx, int tx)
pDev->tx = (struct grcan_msg *)pDev->_tx;
} else {
if (adr == 0) {
- pDev->_tx = malloc(pDev->txbuf_size +
+ pDev->_tx = grlib_malloc(pDev->txbuf_size +
BUFFER_ALIGNMENT_NEEDS);
if (!pDev->_tx)
return -1;
@@ -1157,7 +1156,7 @@ static int grcan_alloc_buffers(struct grcan_priv *pDev, int rx, int tx)
pDev->rx = (struct grcan_msg *)pDev->_rx;
} else {
if (adr == 0) {
- pDev->_rx = malloc(pDev->rxbuf_size +
+ pDev->_rx = grlib_malloc(pDev->rxbuf_size +
BUFFER_ALIGNMENT_NEEDS);
if (!pDev->_rx)
return -1;
diff --git a/bsps/sparc/shared/can/occan.c b/bsps/sparc/shared/can/occan.c
index b45b11dc72..c0bc315db1 100644
--- a/bsps/sparc/shared/can/occan.c
+++ b/bsps/sparc/shared/can/occan.c
@@ -80,7 +80,7 @@ typedef struct {
int full; /* 1 = base contain cnt CANMsgs, tail==head */
CANMsg *tail, *head;
CANMsg *base;
- char fifoarea[0];
+ CANMsg fifoarea[0];
} occan_fifo;
/* PELICAN */
@@ -448,10 +448,9 @@ int occan_init2(struct drvmgr_dev *dev)
occan_priv *priv;
DBG("OCCAN[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(occan_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
return DRVMGR_OK;
@@ -1881,15 +1880,11 @@ void occan_interrupt(void *arg)
static occan_fifo *occan_fifo_create(int cnt)
{
occan_fifo *fifo;
- fifo = malloc(sizeof(occan_fifo)+cnt*sizeof(CANMsg));
+ fifo = grlib_calloc(1, sizeof(*fifo)+cnt*sizeof(CANMsg));
if ( fifo ){
fifo->cnt = cnt;
- fifo->full = 0;
- fifo->ovcnt = 0;
- fifo->base = (CANMsg *)&fifo->fifoarea[0];
+ fifo->base = &fifo->fifoarea[0];
fifo->tail = fifo->head = fifo->base;
- /* clear CAN Messages */
- memset(fifo->base,0,cnt * sizeof(CANMsg));
}
return fifo;
}
diff --git a/bsps/sparc/shared/can/satcan.c b/bsps/sparc/shared/can/satcan.c
index 1655a36e36..9cc27fc0dc 100644
--- a/bsps/sparc/shared/can/satcan.c
+++ b/bsps/sparc/shared/can/satcan.c
@@ -19,6 +19,8 @@
#include <bsp/satcan.h>
#include <ambapp.h>
+#include <grlib_impl.h>
+
#ifndef GAISLER_SATCAN
#define GAISLER_SATCAN 0x080
#endif
@@ -146,7 +148,7 @@ static rtems_device_driver satcan_initialize(rtems_device_major_number major, rt
*/
static void almalloc(unsigned char **alptr, void **ptr, int sz)
{
- *ptr = calloc(1,2*sz);
+ *ptr = rtems_calloc(1,2*sz);
*alptr = (unsigned char *) (((int)*ptr+sz) & ~(sz-1));
}
@@ -682,13 +684,13 @@ int satcan_register(satcan_config *conf)
DBG("SatCAN: satcan_register called\n\r");
/* Create private structure */
- if ((priv = malloc(sizeof(struct satcan_priv))) == NULL) {
+ if ((priv = grlib_malloc(sizeof(*priv))) == NULL) {
printk("SatCAN driver could not allocate memory for priv structure\n\r");
return -1;
}
DBG("SatCAN: Creating local copy of config structure\n\r");
- if ((priv->cfg = malloc(sizeof(satcan_config))) == NULL) {
+ if ((priv->cfg = grlib_malloc(sizeof(*priv->cfg))) == NULL) {
printk("SatCAN driver could not allocate memory for cfg structure\n\r");
return 1;
}
diff --git a/bsps/sparc/shared/drvmgr/ambapp_bus_grlib.c b/bsps/sparc/shared/drvmgr/ambapp_bus_grlib.c
index 73fd465aec..1db0d06aeb 100644
--- a/bsps/sparc/shared/drvmgr/ambapp_bus_grlib.c
+++ b/bsps/sparc/shared/drvmgr/ambapp_bus_grlib.c
@@ -24,6 +24,8 @@
#include <bsp.h>
#include <bsp/irq.h>
+#include <grlib_impl.h>
+
#define DBG(args...)
/*#define DBG(args...) printk(args)*/
@@ -151,7 +153,7 @@ static int ambapp_grlib_init1(struct drvmgr_dev *dev)
DBG("AMBAPP GRLIB: intializing\n");
- config = malloc(sizeof(struct ambapp_config));
+ config = grlib_malloc(sizeof(*config));
if ( !config )
return RTEMS_NO_MEMORY;
diff --git a/bsps/sparc/shared/gpio/gpiolib.c b/bsps/sparc/shared/gpio/gpiolib.c
index 38bc9633d0..700f27a266 100644
--- a/bsps/sparc/shared/gpio/gpiolib.c
+++ b/bsps/sparc/shared/gpio/gpiolib.c
@@ -14,6 +14,8 @@
#include <bsp/gpiolib.h>
+#include <grlib_impl.h>
+
struct gpiolib_port;
struct gpiolib_port {
@@ -78,11 +80,10 @@ int gpiolib_drv_register(struct gpiolib_drv *drv, void *handle)
if ( !drv || !drv->ops )
return -1;
- port = malloc(sizeof(*port));
+ port = grlib_calloc(1, sizeof(*port));
if ( port == NULL )
return -1;
- memset(port, 0, sizeof(*port));
port->handle = handle;
port->minor = port_nr++;
port->drv = drv;
diff --git a/bsps/sparc/shared/gpio/grgpio.c b/bsps/sparc/shared/gpio/grgpio.c
index 7b02298fa4..b235ba273d 100644
--- a/bsps/sparc/shared/gpio/grgpio.c
+++ b/bsps/sparc/shared/gpio/grgpio.c
@@ -22,6 +22,7 @@
#include <bsp/gpiolib.h>
#include <ambapp.h>
#include <grlib.h>
+#include <grlib_impl.h>
/*#define DEBUG 1*/
@@ -117,10 +118,9 @@ int grgpio_init1(struct drvmgr_dev *dev)
if ( status < 0 )
return DRVMGR_FAIL;
- priv = dev->priv = malloc(sizeof(struct grgpio_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
if ( grgpio_device_init(priv) ) {
diff --git a/bsps/sparc/shared/i2c/i2cmst.c b/bsps/sparc/shared/i2c/i2cmst.c
index 9e386f7cb6..3f11d879aa 100644
--- a/bsps/sparc/shared/i2c/i2cmst.c
+++ b/bsps/sparc/shared/i2c/i2cmst.c
@@ -22,6 +22,8 @@
#include <bsp/i2cmst.h>
+#include <grlib_impl.h>
+
/* Enable debug printks? */
/*#define DEBUG*/
@@ -339,10 +341,9 @@ int i2cmst_init2(struct drvmgr_dev *dev)
DBG("I2CMST[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(gr_i2cmst_prv_t));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
diff --git a/bsps/sparc/shared/iommu/griommu.c b/bsps/sparc/shared/iommu/griommu.c
index c6c87df6d6..69d8672057 100644
--- a/bsps/sparc/shared/iommu/griommu.c
+++ b/bsps/sparc/shared/iommu/griommu.c
@@ -19,6 +19,8 @@
#include <bsp.h>
#include <bsp/griommu.h>
+#include <grlib_impl.h>
+
/*#define STATIC*/
#define STATIC static
@@ -1027,7 +1029,7 @@ void * griommu_apv_new(void)
}
/* Allocate APV */
- unsigned int * orig_ptr = (unsigned int *) malloc(
+ unsigned int * orig_ptr = grlib_malloc(
(GRIOMMU_APV_SIZE/priv->pagesize) + GRIOMMU_APV_ALIGN);
if (orig_ptr == NULL) return NULL;
diff --git a/bsps/sparc/shared/irq/genirq.c b/bsps/sparc/shared/irq/genirq.c
index bba642e701..6ddd442f73 100644
--- a/bsps/sparc/shared/irq/genirq.c
+++ b/bsps/sparc/shared/irq/genirq.c
@@ -15,6 +15,8 @@
#include <string.h>
#include <bsp/genirq.h>
+#include <grlib_impl.h>
+
struct genirq_handler_entry {
struct genirq_handler_entry *next; /* Next ISR entry for this IRQ number */
genirq_handler isr; /* ISR function called upon IRQ */
@@ -31,21 +33,20 @@ struct genirq_priv {
/* Maximum number of interrupt */
int genirq_max;
/* IRQ Table index N reflect IRQ number N */
- struct genirq_irq_entry genirq_table[1]; /* Length depends on */
+ struct genirq_irq_entry genirq_table[0]; /* Length depends on */
};
genirq_t genirq_init(int number_of_irqs)
{
- int size;
+ size_t size;
struct genirq_priv *priv;
- size = sizeof(int) +
- number_of_irqs * sizeof(struct genirq_irq_entry);
+ size = sizeof(*priv) +
+ number_of_irqs * sizeof(priv->genirq_table[0]);
- priv = (struct genirq_priv *)malloc(size);
+ priv = grlib_calloc(1, size);
if ( !priv )
return NULL;
- memset(priv, 0, size);
priv->genirq_max = number_of_irqs - 1;
return priv;
@@ -86,7 +87,7 @@ void *genirq_alloc_handler(genirq_handler isr, void *arg)
{
struct genirq_handler_entry *newentry;
- newentry = malloc(sizeof(struct genirq_handler_entry));
+ newentry = grlib_malloc(sizeof(*newentry));
if ( newentry ) {
/* Initialize ISR entry */
newentry->isr = isr;
diff --git a/bsps/sparc/shared/mem/mctrl.c b/bsps/sparc/shared/mem/mctrl.c
index 42c81c45cc..47422a7ee2 100644
--- a/bsps/sparc/shared/mem/mctrl.c
+++ b/bsps/sparc/shared/mem/mctrl.c
@@ -22,6 +22,8 @@
#include <bsp/mctrl.h>
+#include <grlib_impl.h>
+
#define MEMSET(priv, start, c, length) memset((void *)start, c, length)
#define DBG(args...)
@@ -105,10 +107,9 @@ static int mctrl_init1(struct drvmgr_dev *dev)
unsigned int start, length;
DBG("MCTRL[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(struct mctrl_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* Get device information from AMBA PnP information */
diff --git a/bsps/sparc/shared/net/greth.c b/bsps/sparc/shared/net/greth.c
index 830d6b2475..a1e038842c 100644
--- a/bsps/sparc/shared/net/greth.c
+++ b/bsps/sparc/shared/net/greth.c
@@ -43,8 +43,6 @@
#include <netinet/in.h>
#include <netinet/if_ether.h>
-#include <grlib_impl.h>
-
#ifdef malloc
#undef malloc
#endif
@@ -52,6 +50,8 @@
#undef free
#endif
+#include <grlib_impl.h>
+
#if defined(__m68k__)
extern m68k_isr_entry set_vector( rtems_isr_entry, rtems_vector_number, int );
#else
@@ -216,7 +216,7 @@ int greth_process_tx(struct greth_softc *sc);
static char *almalloc(int sz, int alignment)
{
char *tmp;
- tmp = calloc(1, sz + (alignment-1));
+ tmp = grlib_calloc(1, sz + (alignment-1));
tmp = (char *) (((int)tmp+alignment) & ~(alignment -1));
return(tmp);
}
@@ -635,8 +635,8 @@ auto_neg_done:
regs->txdesc = (int) sc->txdesc_remote;
regs->rxdesc = (int) sc->rxdesc_remote;
- sc->rxmbuf = calloc(sc->rxbufs, sizeof(*sc->rxmbuf));
- sc->txmbuf = calloc(sc->txbufs, sizeof(*sc->txmbuf));
+ sc->rxmbuf = grlib_calloc(sc->rxbufs, sizeof(*sc->rxmbuf));
+ sc->txmbuf = grlib_calloc(sc->txbufs, sizeof(*sc->txmbuf));
for (i = 0; i < sc->txbufs; i++)
{
@@ -645,7 +645,7 @@ auto_neg_done:
drvmgr_translate_check(
sc->dev,
CPUMEM_TO_DMA,
- (void *)malloc(GRETH_MAXBUF_LEN),
+ (void *)grlib_malloc(GRETH_MAXBUF_LEN),
(void **)&sc->txdesc[i].addr,
GRETH_MAXBUF_LEN);
}
@@ -1503,10 +1503,9 @@ int greth_init2(struct drvmgr_dev *dev)
struct greth_softc *priv;
DBG("GRETH[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(struct greth_softc));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init3() */
@@ -1535,8 +1534,7 @@ int greth_init3(struct drvmgr_dev *dev)
SPIN_INIT(&sc->devlock, sc->devName);
/* Register GRETH device as an Network interface */
- ifp = malloc(sizeof(struct rtems_bsdnet_ifconfig));
- memset(ifp, 0, sizeof(*ifp));
+ ifp = grlib_cmalloc(1, sizeof(*ifp));
ifp->name = sc->devName;
ifp->drv_ctrl = sc;
diff --git a/bsps/sparc/shared/pci/gr_701.c b/bsps/sparc/shared/pci/gr_701.c
index 3e2109fbf5..03f3020db0 100644
--- a/bsps/sparc/shared/pci/gr_701.c
+++ b/bsps/sparc/shared/pci/gr_701.c
@@ -316,11 +316,10 @@ int gr701_init1(struct drvmgr_dev *dev)
uint32_t bar0, bar1, bar0_size, bar1_size;
int resources_cnt;
- priv = malloc(sizeof(struct gr701_priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
dev->priv = priv;
priv->dev = dev;
diff --git a/bsps/sparc/shared/pci/gr_rasta_adcdac.c b/bsps/sparc/shared/pci/gr_rasta_adcdac.c
index 8a58438287..1c46510772 100644
--- a/bsps/sparc/shared/pci/gr_rasta_adcdac.c
+++ b/bsps/sparc/shared/pci/gr_rasta_adcdac.c
@@ -380,11 +380,10 @@ int gr_rasta_adcdac_init1(struct drvmgr_dev *dev)
union drvmgr_key_value *value;
int resources_cnt;
- priv = malloc(sizeof(struct gr_rasta_adcdac_priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
dev->priv = priv;
priv->dev = dev;
diff --git a/bsps/sparc/shared/pci/gr_rasta_io.c b/bsps/sparc/shared/pci/gr_rasta_io.c
index 78f6eefa20..fed4b368ac 100644
--- a/bsps/sparc/shared/pci/gr_rasta_io.c
+++ b/bsps/sparc/shared/pci/gr_rasta_io.c
@@ -559,11 +559,10 @@ int gr_rasta_io_init1(struct drvmgr_dev *dev)
union drvmgr_key_value *value;
int resources_cnt;
- priv = malloc(sizeof(struct gr_rasta_io_priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
dev->priv = priv;
priv->dev = dev;
diff --git a/bsps/sparc/shared/pci/gr_tmtc_1553.c b/bsps/sparc/shared/pci/gr_tmtc_1553.c
index f68188bc9e..a8181b6429 100644
--- a/bsps/sparc/shared/pci/gr_tmtc_1553.c
+++ b/bsps/sparc/shared/pci/gr_tmtc_1553.c
@@ -299,11 +299,10 @@ int gr_tmtc_1553_init1(struct drvmgr_dev *dev)
*/
((struct pci_dev_info *)dev->businfo)->irq = ((struct amba_dev_info *)dev->parent->dev->businfo)->info.irq;
- priv = malloc(sizeof(struct gr_tmtc_1553_priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
dev->priv = priv;
priv->dev = dev;
diff --git a/bsps/sparc/shared/pci/grpci2dma.c b/bsps/sparc/shared/pci/grpci2dma.c
index 92c2038de0..0bc06ff50d 100644
--- a/bsps/sparc/shared/pci/grpci2dma.c
+++ b/bsps/sparc/shared/pci/grpci2dma.c
@@ -1285,7 +1285,7 @@ STATIC int grpci2dma_data_print(struct grpci2_bd_data * data)
void * grpci2dma_channel_new(int number)
{
/* Allocate memory */
- unsigned int * orig_ptr = (unsigned int *) malloc(
+ unsigned int * orig_ptr = (unsigned int *) grlib_malloc(
(GRPCI2DMA_BD_CHAN_SIZE)*number + GRPCI2DMA_BD_CHAN_ALIGN);
if (orig_ptr == NULL) return NULL;
@@ -1317,7 +1317,7 @@ void grpci2dma_channel_delete(void * chan)
void * grpci2dma_data_new(int number)
{
/* Allocate memory */
- unsigned int * orig_ptr = (unsigned int *) malloc(
+ unsigned int * orig_ptr = (unsigned int *) grlib_malloc(
(GRPCI2DMA_BD_DATA_SIZE)*number + GRPCI2DMA_BD_DATA_ALIGN);
if (orig_ptr == NULL) return NULL;
@@ -1375,13 +1375,10 @@ int grpci2dma_init(
return -1;
/* Allocate and init Memory for DMA */
- int size = sizeof(struct grpci2dma_priv);
- priv = (struct grpci2dma_priv *) malloc(size);
+ priv = grlib_calloc(1, sizeof(*priv));
if (priv == NULL)
return DRVMGR_NOMEM;
- /* Initialize all fields */
- memset(priv, 0, size);
priv->regs = regs;
strncpy(&priv->devname[0], "grpci2dma0", DEVNAME_LEN);
diff --git a/bsps/sparc/shared/pwm/grpwm.c b/bsps/sparc/shared/pwm/grpwm.c
index 302df73e83..87e40663c5 100644
--- a/bsps/sparc/shared/pwm/grpwm.c
+++ b/bsps/sparc/shared/pwm/grpwm.c
@@ -22,6 +22,8 @@
#include <bsp/grpwm.h>
#include <ambapp.h>
+#include <grlib_impl.h>
+
/* #define DEBUG 1 */
#ifdef DEBUG
@@ -222,7 +224,7 @@ int grpwm_init2(struct drvmgr_dev *dev)
DBG("GRPWM[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(struct grpwm_priv));
+ priv = dev->priv = grlib_malloc(sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
memset(priv, 0, sizeof(*priv));
@@ -789,10 +791,9 @@ int grpwm_device_init(struct grpwm_priv *priv)
/* Find the number of PWM channels */
priv->channel_cnt = 1 + ((regs->cap1 & GRPWM_CAP_NPWM) >> GRPWM_CAP_NPWM_BIT);
- pwm = malloc(sizeof(*pwm)*priv->channel_cnt);
+ pwm = grlib_calloc(priv->channel_cnt, sizeof(*pwm));
if ( !pwm )
return -1;
- memset(pwm, 0, sizeof(*pwm)*priv->channel_cnt);
/* Init all PWM channels */
sepirq = ((regs->cap1 & GRPWM_CAP_SEP) >> GRPWM_CAP_SEP_BIT);
diff --git a/bsps/sparc/shared/slink/grslink.c b/bsps/sparc/shared/slink/grslink.c
index 22a29546d0..07335786e5 100644
--- a/bsps/sparc/shared/slink/grslink.c
+++ b/bsps/sparc/shared/slink/grslink.c
@@ -26,6 +26,8 @@
#include <bsp/grslink.h>
#include <ambapp.h>
+#include <grlib_impl.h>
+
#ifndef GAISLER_SLINK
#define GAISLER_SLINK 0x02F
#endif
@@ -101,12 +103,12 @@ static int SLINK_createqueues(int size)
SLINK_queue *q;
int i, j;
- if ((q = malloc(SLINK_NUMQUEUES*sizeof(SLINK_queue))) == NULL)
+ if ((q = grlib_malloc(SLINK_NUMQUEUES*sizeof(*q))) == NULL)
goto slink_qiniterr1;
for (i = 0; i < SLINK_NUMQUEUES; i++) {
q[i].size = size;
- if ((q[i].buf = malloc(size*sizeof(int))) == NULL)
+ if ((q[i].buf = grlib_malloc(size*sizeof(int))) == NULL)
goto slink_qiniterr2;
q[i].first = q[i].last = q[i].buf;
q[i].max = q[i].buf + (size-1);
@@ -345,7 +347,7 @@ int SLINK_init(unsigned int nullwrd, int parity, int qsize,
rtems_status_code st;
/* Allocate private config structure */
- if (cfg == NULL && (cfg = malloc(sizeof(SLINK_cfg))) == NULL) {
+ if (cfg == NULL && (cfg = grlib_malloc(sizeof(*cfg))) == NULL) {
DBG("SLINK_init: Could not allocate cfg structure\n");
goto slink_initerr1;
}
@@ -369,7 +371,7 @@ int SLINK_init(unsigned int nullwrd, int parity, int qsize,
cfg->reg = (SLINK_regs*)base;
/* Allocate status structure and initialize members */
- if ((cfg->status = calloc(1, sizeof(SLINK_status))) == NULL) {
+ if ((cfg->status = grlib_calloc(1, sizeof(*cfg->status))) == NULL) {
DBG("SLINK_init: Could not allocate status structure\n");
goto slink_initerr2;
}
@@ -378,7 +380,7 @@ int SLINK_init(unsigned int nullwrd, int parity, int qsize,
#ifdef SLINK_COLLECT_STATISTICS
/* Allocate statistics structure and initialize members */
- if ((cfg->stats = calloc(1, sizeof(SLINK_stats))) == NULL) {
+ if ((cfg->stats = grlib_calloc(1, sizeof(*cfg->stats))) == NULL) {
DBG("SLINK_init: Could not allocate statistics structure\n");
goto slink_initerr3;
}
diff --git a/bsps/sparc/shared/spi/spictrl.c b/bsps/sparc/shared/spi/spictrl.c
index 0c940d3374..6f5ffefe25 100644
--- a/bsps/sparc/shared/spi/spictrl.c
+++ b/bsps/sparc/shared/spi/spictrl.c
@@ -24,6 +24,8 @@
#include <rtems/libi2c.h>
+#include <grlib_impl.h>
+
/*#define DEBUG 1*/
#ifdef DEBUG
@@ -216,10 +218,9 @@ int spictrl_init2(struct drvmgr_dev *dev)
DBG("SPICTRL[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(struct spictrl_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
diff --git a/bsps/sparc/shared/spw/grspw.c b/bsps/sparc/shared/spw/grspw.c
index 661ec6c01d..846af8c6b5 100644
--- a/bsps/sparc/shared/spw/grspw.c
+++ b/bsps/sparc/shared/spw/grspw.c
@@ -17,13 +17,14 @@
#include <assert.h>
#include <ctype.h>
#include <rtems/bspIo.h>
-#include <rtems/malloc.h>
#include <ambapp.h>
#include <drvmgr/drvmgr.h>
#include <drvmgr/ambapp_bus.h>
#include <bsp/grspw.h>
+#include <grlib_impl.h>
+
#define DBGSPW_IOCALLS 1
#define DBGSPW_TX 2
#define DBGSPW_RX 4
@@ -385,10 +386,9 @@ int grspw_init2(struct drvmgr_dev *dev)
SPACEWIRE_DBG("GRSPW[%d] on bus %s\n", dev->minor_drv,
dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(GRSPW_DEV));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
@@ -628,7 +628,8 @@ static int grspw_buffer_alloc(GRSPW_DEV *pDev)
if (pDev->rx_dma_area == 0) {
if (pDev->_ptr_rxbuf0)
free((void *)pDev->_ptr_rxbuf0);
- pDev->_ptr_rxbuf0 = (unsigned int) malloc(pDev->rxbufsize * pDev->rxbufcnt+4);
+ pDev->_ptr_rxbuf0 = (unsigned int) grlib_malloc(
+ pDev->rxbufsize * pDev->rxbufcnt+4);
pDev->ptr_rxbuf0 = (char *)((pDev->_ptr_rxbuf0+7)&~7);
if ( !pDev->ptr_rxbuf0 )
return 1;
@@ -657,7 +658,8 @@ static int grspw_buffer_alloc(GRSPW_DEV *pDev)
if (pDev->tx_data_dma_area == 0) {
if (pDev->ptr_txdbuf0)
free(pDev->ptr_txdbuf0);
- pDev->ptr_txdbuf0 = (char *) malloc(pDev->txdbufsize * pDev->txbufcnt);
+ pDev->ptr_txdbuf0 = (char *) grlib_malloc(
+ pDev->txdbufsize * pDev->txbufcnt);
if (!pDev->ptr_txdbuf0)
return 1;
} else {
@@ -685,7 +687,8 @@ static int grspw_buffer_alloc(GRSPW_DEV *pDev)
if (pDev->tx_hdr_dma_area == 0) {
if (pDev->ptr_txhbuf0)
free(pDev->ptr_txhbuf0);
- pDev->ptr_txhbuf0 = (char *) malloc(pDev->txhbufsize * pDev->txbufcnt);
+ pDev->ptr_txhbuf0 = (char *) grlib_malloc(
+ pDev->txhbufsize * pDev->txbufcnt);
if (!pDev->ptr_txhbuf0)
return 1;
} else {
diff --git a/bsps/sparc/shared/spw/grspw_pkt.c b/bsps/sparc/shared/spw/grspw_pkt.c
index 113684b1fe..ce8478de65 100644
--- a/bsps/sparc/shared/spw/grspw_pkt.c
+++ b/bsps/sparc/shared/spw/grspw_pkt.c
@@ -20,7 +20,6 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <malloc.h>
#include <rtems/bspIo.h>
#include <drvmgr/drvmgr.h>
@@ -549,7 +548,7 @@ void *grspw_open(int dev_no)
goto out;
}
} else {
- priv->bd_mem_alloced = (unsigned int)malloc(bdtabsize + BDTAB_ALIGN - 1);
+ priv->bd_mem_alloced = (unsigned int)grlib_malloc(bdtabsize + BDTAB_ALIGN - 1);
if (priv->bd_mem_alloced == 0) {
priv = NULL;
goto out;
@@ -1685,7 +1684,7 @@ void *grspw_dma_open(void *d, int chan_no)
/* Allocate memory for the two descriptor rings */
size = sizeof(struct grspw_ring) * (GRSPW_RXBD_NR + GRSPW_TXBD_NR);
- dma->rx_ring_base = (struct grspw_rxring *)malloc(size);
+ dma->rx_ring_base = grlib_malloc(size);
dma->tx_ring_base = (struct grspw_txring *)&dma->rx_ring_base[GRSPW_RXBD_NR];
if (dma->rx_ring_base == NULL)
goto err;
@@ -3056,7 +3055,7 @@ static int grspw2_init3(struct drvmgr_dev *dev)
struct grspw_priv *priv;
struct amba_dev_info *ambadev;
struct ambapp_core *pnpinfo;
- int i, size;
+ int i;
unsigned int ctrl, icctrl, numi;
union drvmgr_key_value *value;
@@ -3144,11 +3143,9 @@ static int grspw2_init3(struct drvmgr_dev *dev)
priv->hwsup.ndma_chans = value->i;
/* Allocate and init Memory for all DMA channels */
- size = sizeof(struct grspw_dma_priv) * priv->hwsup.ndma_chans;
- priv->dma = (struct grspw_dma_priv *) malloc(size);
+ priv->dma = grlib_calloc(priv->hwsup.ndma_chans, sizeof(*priv->dma));
if (priv->dma == NULL)
return DRVMGR_NOMEM;
- memset(priv->dma, 0, size);
for (i=0; i<priv->hwsup.ndma_chans; i++) {
priv->dma[i].core = priv;
priv->dma[i].index = i;
diff --git a/bsps/sparc/shared/time/grctm.c b/bsps/sparc/shared/time/grctm.c
index 39fc972bb9..e740f7a7d5 100644
--- a/bsps/sparc/shared/time/grctm.c
+++ b/bsps/sparc/shared/time/grctm.c
@@ -15,6 +15,8 @@
#include <bsp/grctm.h>
+#include <grlib_impl.h>
+
/* Private structure of GRCTM driver */
struct grctm_priv {
struct drvmgr_dev *dev;
@@ -351,10 +353,9 @@ static int grctm_init2(struct drvmgr_dev *dev)
struct grctm_priv *priv;
struct grctm_regs *regs;
- priv = (struct grctm_priv *)malloc(sizeof(*priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( priv == NULL )
return -1;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
dev->priv = priv;
diff --git a/bsps/sparc/shared/time/spwcuc.c b/bsps/sparc/shared/time/spwcuc.c
index 082ced0772..354322910e 100644
--- a/bsps/sparc/shared/time/spwcuc.c
+++ b/bsps/sparc/shared/time/spwcuc.c
@@ -13,9 +13,11 @@
#include <drvmgr/ambapp_bus.h>
#include <stdlib.h>
#include <string.h>
-
+
#include <bsp/spwcuc.h>
+#include <grlib_impl.h>
+
/* Private structure of SPWCUC driver. */
struct spwcuc_priv {
struct drvmgr_dev *dev;
@@ -311,10 +313,9 @@ static int spwcuc_init2(struct drvmgr_dev *dev)
struct spwcuc_priv *priv;
struct spwcuc_regs *regs;
- priv = (struct spwcuc_priv *)malloc(sizeof(*priv));
+ priv = grlib_calloc(1, sizeof(*priv));
if ( priv == NULL )
return -1;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
dev->priv = priv;
diff --git a/bsps/sparc/shared/tmtc/grtc.c b/bsps/sparc/shared/tmtc/grtc.c
index 4e877465ab..35f67f6a4c 100644
--- a/bsps/sparc/shared/tmtc/grtc.c
+++ b/bsps/sparc/shared/tmtc/grtc.c
@@ -15,7 +15,6 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <malloc.h>
#include <rtems/bspIo.h>
#include <drvmgr/drvmgr.h>
@@ -617,7 +616,7 @@ static int grtc_data_avail(struct grtc_priv *pDev)
static void *grtc_memalign(unsigned int boundary, unsigned int length, void *realbuf)
{
- *(int *)realbuf = (int)malloc(length+(~GRTC_ASR_BUFST)+1);
+ *(int *)realbuf = (int)grlib_malloc(length+(~GRTC_ASR_BUFST)+1);
DBG("GRTC: Alloced %d (0x%x) bytes, requested: %d\n",length+(~GRTC_ASR_BUFST)+1,length+(~GRTC_ASR_BUFST)+1,length);
return (void *)(((*(unsigned int *)realbuf)+(~GRTC_ASR_BUFST)+1) & ~(boundary-1));
}
@@ -1779,7 +1778,7 @@ static rtems_device_driver grtc_ioctl(rtems_device_major_number major, rtems_dev
if ( pDev->pools ) {
free(pDev->pools);
}
- pDev->pools = malloc(pocfg->pool_cnt * sizeof(struct grtc_frame_pool));
+ pDev->pools = grlib_malloc(pocfg->pool_cnt * sizeof(*pDev->pools));
if ( !pDev->pools ) {
pDev->pool_cnt = 0;
return RTEMS_NO_MEMORY;
diff --git a/bsps/sparc/shared/tmtc/grtm.c b/bsps/sparc/shared/tmtc/grtm.c
index 10a4f6eb00..a7f7889dc5 100644
--- a/bsps/sparc/shared/tmtc/grtm.c
+++ b/bsps/sparc/shared/tmtc/grtm.c
@@ -15,7 +15,6 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <malloc.h>
#include <rtems/bspIo.h>
#include <drvmgr/drvmgr.h>
@@ -449,10 +448,9 @@ static int grtm_init2(struct drvmgr_dev *dev)
struct grtm_priv *priv;
DBG("GRTM[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
- priv = dev->priv = malloc(sizeof(struct grtm_priv));
+ priv = dev->priv = grlib_calloc(1, sizeof(*priv));
if ( !priv )
return DRVMGR_NOMEM;
- memset(priv, 0, sizeof(*priv));
priv->dev = dev;
/* This core will not find other cores, so we wait for init2() */
@@ -584,7 +582,7 @@ static int grtm_device_init(struct grtm_priv *pDev)
}
memset(pDev->bds, 0, 0x400);
- pDev->_ring = malloc(sizeof(struct grtm_ring) * 128);
+ pDev->_ring = grlib_malloc(sizeof(*pDev->_ring) * 128);
if ( !pDev->_ring ) {
return -1;
}
@@ -692,7 +690,7 @@ static void grtm_hw_get_default_modes(struct grtm_ioc_config *cfg, struct grtm_i
static void *grtm_memalign(unsigned int boundary, unsigned int length, void *realbuf)
{
- *(int *)realbuf = (int)malloc(length+boundary);
+ *(int *)realbuf = (int)grlib_malloc(length+boundary);
DBG("GRTM: Alloced %d (0x%x) bytes, requested: %d\n",length+boundary,length+boundary,length);
return (void *)(((*(unsigned int *)realbuf)+boundary) & ~(boundary-1));
}