Skip to content

Commit

Permalink
Use no_os functions for dynamic memory
Browse files Browse the repository at this point in the history
Use no_os_clloc, no_os_malloc, and no_os_free for dynamic memory
management.

Signed-off-by: George Mois <[email protected]>
  • Loading branch information
danmois authored and amiclaus committed Mar 13, 2023
1 parent 18e95a2 commit 4a8dcd9
Show file tree
Hide file tree
Showing 326 changed files with 1,744 additions and 1,313 deletions.
9 changes: 5 additions & 4 deletions drivers/accel/adxl313/adxl313.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "no_os_print_log.h"
#include "no_os_util.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"

/******************************************************************************/
/************************ Functions Declarations ******************************/
Expand Down Expand Up @@ -172,7 +173,7 @@ int adxl313_init(struct adxl313_dev **device,
uint8_t reg_value = 0;


dev = (struct adxl313_dev *)calloc(1, sizeof(*dev));
dev = (struct adxl313_dev *)no_os_calloc(1, sizeof(*dev));
if (!dev)
return -ENOMEM;

Expand Down Expand Up @@ -340,10 +341,10 @@ int adxl313_init(struct adxl313_dev **device,
no_os_spi_remove(dev->com_desc.spi_desc);
else
no_os_i2c_remove(dev->com_desc.i2c_desc);
free(dev);
no_os_free(dev);
return -EPIPE;
error_dev:
free(dev);
no_os_free(dev);
return -ENODEV;
}

Expand All @@ -364,7 +365,7 @@ int adxl313_remove(struct adxl313_dev *dev)
ret = no_os_i2c_remove(dev->com_desc.i2c_desc);

if (!ret)
free(dev);
no_os_free(dev);

return ret;
}
Expand Down
9 changes: 5 additions & 4 deletions drivers/accel/adxl313/iio_adxl313.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <stdio.h>
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "iio_adxl313.h"
#include "adxl313.h"

Expand Down Expand Up @@ -1038,7 +1039,7 @@ int adxl313_iio_init(struct adxl313_iio_dev **iio_dev,
int ret;
struct adxl313_iio_dev *desc;

desc = (struct adxl313_iio_dev *)calloc(1, sizeof(*desc));
desc = (struct adxl313_iio_dev *)no_os_calloc(1, sizeof(*desc));
if (!desc)
return -ENOMEM;

Expand Down Expand Up @@ -1084,11 +1085,11 @@ int adxl313_iio_init(struct adxl313_iio_dev **iio_dev,
return 0;

error_adxl313_init:
free(desc);
no_os_free(desc);
return ret;
error_config:
adxl313_remove(desc->adxl313_dev);
free(desc);
no_os_free(desc);
return ret;
}

Expand All @@ -1107,7 +1108,7 @@ int adxl313_iio_remove(struct adxl313_iio_dev *desc)
if (ret)
return ret;

free(desc);
no_os_free(desc);

return 0;
}
5 changes: 3 additions & 2 deletions drivers/accel/adxl345/adxl345.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
/******************************************************************************/
#include <stdlib.h>
#include "adxl345.h"
#include "no_os_alloc.h"

/******************************************************************************/
/************************ Functions Definitions *******************************/
Expand Down Expand Up @@ -133,7 +134,7 @@ int32_t adxl345_init(struct adxl345_dev **device,
struct adxl345_dev *dev;
int32_t status = 0;

dev = (struct adxl345_dev *)malloc(sizeof(*dev));
dev = (struct adxl345_dev *)no_os_malloc(sizeof(*dev));
if (!dev)
return -1;

Expand Down Expand Up @@ -171,7 +172,7 @@ int32_t adxl345_remove(struct adxl345_dev *dev)
else
ret = no_os_i2c_remove(dev->i2c_desc);

free(dev);
no_os_free(dev);

return ret;
}
Expand Down
9 changes: 5 additions & 4 deletions drivers/accel/adxl355/adxl355.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <errno.h>
#include "adxl355.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"

/******************************************************************************/
/************************ Variable Declarations ******************************/
Expand Down Expand Up @@ -155,7 +156,7 @@ int adxl355_init(struct adxl355_dev **device,
return -EINVAL;
}

dev = (struct adxl355_dev *)calloc(1, sizeof(*dev));
dev = (struct adxl355_dev *)no_os_calloc(1, sizeof(*dev));

if (!dev)
return -ENOMEM;
Expand Down Expand Up @@ -218,10 +219,10 @@ int adxl355_init(struct adxl355_dev **device,
no_os_spi_remove(dev->com_desc.spi_desc);
else
no_os_i2c_remove(dev->com_desc.i2c_desc);
free(dev);
no_os_free(dev);
return -1;
error_dev:
free(dev);
no_os_free(dev);
return ret;
}

Expand All @@ -241,7 +242,7 @@ int adxl355_remove(struct adxl355_dev *dev)
else
ret = no_os_i2c_remove(dev->com_desc.i2c_desc);

free(dev);
no_os_free(dev);

return ret;
}
Expand Down
9 changes: 5 additions & 4 deletions drivers/accel/adxl355/iio_adxl355.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "iio_adxl355.h"
#include "adxl355.h"
#include "no_os_units.h"
#include "no_os_alloc.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
Expand Down Expand Up @@ -1046,7 +1047,7 @@ int adxl355_iio_init(struct adxl355_iio_dev **iio_dev,
int ret;
struct adxl355_iio_dev *desc;

desc = (struct adxl355_iio_dev *)calloc(1, sizeof(*desc));
desc = (struct adxl355_iio_dev *)no_os_calloc(1, sizeof(*desc));
if (!desc)
return -ENOMEM;

Expand Down Expand Up @@ -1079,11 +1080,11 @@ int adxl355_iio_init(struct adxl355_iio_dev **iio_dev,
return 0;

error_adxl355_init:
free(desc);
no_os_free(desc);
return ret;
error_config:
adxl355_remove(desc->adxl355_dev);
free(desc);
no_os_free(desc);
return ret;
}

Expand All @@ -1102,7 +1103,7 @@ int adxl355_iio_remove(struct adxl355_iio_dev *desc)
if (ret)
return ret;

free(desc);
no_os_free(desc);

return 0;
}
5 changes: 3 additions & 2 deletions drivers/accel/adxl362/adxl362.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
/******************************************************************************/
#include <stdlib.h>
#include "adxl362.h"
#include "no_os_alloc.h"

/******************************************************************************/
/************************ Functions Definitions *******************************/
Expand All @@ -65,7 +66,7 @@ int32_t adxl362_init(struct adxl362_dev **device,
uint8_t reg_value = 0;
int32_t status = -1;

dev = (struct adxl362_dev *)malloc(sizeof(*dev));
dev = (struct adxl362_dev *)no_os_malloc(sizeof(*dev));
if (!dev)
return -1;

Expand Down Expand Up @@ -96,7 +97,7 @@ int32_t adxl362_remove(struct adxl362_dev *dev)

ret = no_os_spi_remove(dev->spi_desc);

free(dev);
no_os_free(dev);

return ret;
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/accel/adxl367/adxl367.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "adxl367.h"
#include "no_os_delay.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "no_os_print_log.h"

/******************************************************************************/
Expand Down Expand Up @@ -73,7 +74,7 @@ int adxl367_init(struct adxl367_dev **device,
uint8_t reg_value;
int status;

dev = (struct adxl367_dev *)calloc(1, sizeof(*dev));
dev = (struct adxl367_dev *)no_os_calloc(1, sizeof(*dev));
if (!dev)
return -1;

Expand Down Expand Up @@ -127,7 +128,7 @@ int adxl367_init(struct adxl367_dev **device,
else
no_os_i2c_remove(dev->i2c_desc);
comm_err:
free(dev);
no_os_free(dev);
pr_err("%s: Failed initialization.\n", __func__);
return -1;
}
Expand All @@ -148,7 +149,7 @@ int adxl367_remove(struct adxl367_dev *dev)
else
ret = no_os_i2c_remove(dev->i2c_desc);

free(dev);
no_os_free(dev);

return ret;
}
Expand Down
9 changes: 5 additions & 4 deletions drivers/accel/adxl367/iio_adxl367.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <stdio.h>
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "iio_adxl367.h"
#include "adxl367.h"
#include <string.h>
Expand Down Expand Up @@ -729,7 +730,7 @@ int adxl367_iio_init(struct adxl367_iio_dev **iio_dev,
int ret;
struct adxl367_iio_dev *desc;

desc = (struct adxl367_iio_dev *)calloc(1, sizeof(*desc));
desc = (struct adxl367_iio_dev *)no_os_calloc(1, sizeof(*desc));
if (!desc)
return -ENOMEM;

Expand Down Expand Up @@ -760,11 +761,11 @@ int adxl367_iio_init(struct adxl367_iio_dev **iio_dev,
return 0;

error_adxl367_init:
free(desc);
no_os_free(desc);
return ret;
error_config:
adxl367_remove(desc->adxl367_dev);
free(desc);
no_os_free(desc);
return ret;
}

Expand All @@ -783,7 +784,7 @@ int adxl367_iio_remove(struct adxl367_iio_dev *desc)
if (ret)
return ret;

free(desc);
no_os_free(desc);

return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/accel/adxl372/adxl372.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <stdbool.h>
#include <string.h>
#include "adxl372.h"
#include "no_os_alloc.h"

/******************************************************************************/
/************************** Functions Implementation **************************/
Expand Down Expand Up @@ -703,7 +704,7 @@ int32_t adxl372_init(struct adxl372_dev **device,
uint8_t dev_id, part_id, rev_id;
int32_t ret;

dev = (struct adxl372_dev *)malloc(sizeof(*dev));
dev = (struct adxl372_dev *)no_os_malloc(sizeof(*dev));
if (!dev)
goto error;

Expand Down Expand Up @@ -812,7 +813,7 @@ int32_t adxl372_init(struct adxl372_dev **device,
}
error:
printf("adxl372 initialization error (%d)\n", ret);
free(dev);
no_os_free(dev);
no_os_mdelay(1000);
return ret;
}
7 changes: 4 additions & 3 deletions drivers/adc-dac/ad74413r/ad74413r.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_alloc.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
Expand Down Expand Up @@ -1005,7 +1006,7 @@ int ad74413r_init(struct ad74413r_desc **desc,
if (!init_param)
return -EINVAL;

descriptor = calloc(1, sizeof(*descriptor));
descriptor = no_os_calloc(1, sizeof(*descriptor));
if (!descriptor)
return -ENOMEM;

Expand Down Expand Up @@ -1036,7 +1037,7 @@ int ad74413r_init(struct ad74413r_desc **desc,
comm_err:
no_os_spi_remove(descriptor->comm_desc);
err:
free(descriptor);
no_os_free(descriptor);

return ret;
}
Expand All @@ -1057,7 +1058,7 @@ int ad74413r_remove(struct ad74413r_desc *desc)
if (ret)
return ret;

free(desc);
no_os_free(desc);

return 0;
}
9 changes: 5 additions & 4 deletions drivers/adc-dac/ad74413r/iio_ad74413r.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "no_os_error.h"
#include "no_os_units.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "ad74413r.h"
#include "iio_ad74413r.h"

Expand Down Expand Up @@ -538,7 +539,7 @@ static int ad74413r_iio_setup_channels(struct ad74413r_iio_desc *iio_desc)
channel_buff_cnt += channel_map[config[i].function].num_channels;
}

chan_buffer = calloc(channel_buff_cnt, sizeof(*chan_buffer));
chan_buffer = no_os_calloc(channel_buff_cnt, sizeof(*chan_buffer));
if (!chan_buffer)
return -ENOMEM;

Expand Down Expand Up @@ -684,7 +685,7 @@ int ad74413r_iio_init(struct ad74413r_iio_desc **iio_desc,
if (!init_param || !init_param->ad74413r_init_param)
return -EINVAL;

descriptor = calloc(1, sizeof(*descriptor));
descriptor = no_os_calloc(1, sizeof(*descriptor));
if (!descriptor)
return -ENOMEM;

Expand Down Expand Up @@ -727,7 +728,7 @@ int ad74413r_iio_init(struct ad74413r_iio_desc **iio_desc,
return 0;
err:
ad74413r_remove(descriptor->ad74413r_desc);
free(descriptor);
no_os_free(descriptor);

return ret;
}
Expand All @@ -745,7 +746,7 @@ int ad74413r_iio_remove(struct ad74413r_iio_desc *desc)
if (ret)
return ret;

free(desc);
no_os_free(desc);

return 0;
}
Loading

0 comments on commit 4a8dcd9

Please sign in to comment.