summaryrefslogtreecommitdiffstats
path: root/bsps/sparc/shared/can
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 /bsps/sparc/shared/can
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.
Diffstat (limited to '')
-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
4 files changed, 15 insertions, 17 deletions
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;
}