Skip to content

Commit

Permalink
mm/alloc: remove all unnecessary cast for alloc
Browse files Browse the repository at this point in the history
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
  • Loading branch information
anchao authored and xiaoxiang781216 committed Aug 30, 2023
1 parent db13d5e commit 664927c
Show file tree
Hide file tree
Showing 333 changed files with 485 additions and 566 deletions.
16 changes: 6 additions & 10 deletions Documentation/contributing/coding_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ may be used in the file provided that it is used consistently.
int short_name2; /* This is a very long comment describing subtle aspects of the short_name2 field */
};
struct some_medium_name_s *ptr = (struct some_medium_name_s *)malloc(sizeof(some_medium_name_s);
struct some_medium_name_s *ptr = malloc(sizeof(some_medium_name_s);
struct some_long_struct_name_s *ptr = (struct some_long_struct_name_s *)malloc(sizeof(some_long_struct_name_s);
struct some_long_struct_name_s *ptr = malloc(sizeof(some_long_struct_name_s);
ret = some_function_with_many parameters(long_parameter_name_1, long_parameter_name_2, long_parameter_name_3, long_parameter_name_4, long_parameter_name_5, long_parameter_name_6, long_parameter_name_7, long_parameter_name_8);
Expand Down Expand Up @@ -195,15 +195,11 @@ may be used in the file provided that it is used consistently.
* aspects of the short_name2 field. */
};
FAR struct some_medium_name_s *ptr = (FAR struct some_medium_name_s *)
malloc(sizeof(some_medium_name_s);
FAR struct some_medium_name_s *ptr = malloc(sizeof(some_medium_name_s);
FAR struct some_medium_name_s *ptr =
(FAR struct some_medium_name_s *)malloc(sizeof(some_medium_name_s);
FAR struct some_medium_name_s *ptr = malloc(sizeof(some_medium_name_s);
FAR struct some_long_struct_name_s *ptr =
(FAR struct some_long_struct_name_s *)
malloc(sizeof(some_long_struct_name_s);
FAR struct some_long_struct_name_s *ptr = malloc(sizeof(some_long_struct_name_s);
ret = some_function_with_many parameters(long_parameter_name_1,
long_parameter_name_2,
Expand Down Expand Up @@ -2279,7 +2275,7 @@ Use of ``goto``
goto errout;
}
...
ptr = (FAR struct some_struct_s *)malloc(sizeof(struct some_struct_s));
ptr = malloc(sizeof(struct some_struct_s));
if (!ptr)
{
ret = -ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/armv7-a/arm_addrenv_kstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ int up_addrenv_kstackalloc(struct tcb_s *tcb)

/* Allocate the kernel stack */

tcb->xcp.kstack = (uint32_t *)kmm_memalign(8, ARCH_KERNEL_STACKSIZE);
tcb->xcp.kstack = kmm_memalign(8, ARCH_KERNEL_STACKSIZE);
if (!tcb->xcp.kstack)
{
berr("ERROR: Failed to allocate the kernel stack\n");
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/cxd56_dmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ DMA_HANDLE cxd56_dmachannel(int ch, ssize_t maxsize)
n++;
}

dmach->list = (dmac_lli_t *)kmm_malloc(n * sizeof(dmac_lli_t));
dmach->list = kmm_malloc(n * sizeof(dmac_lli_t));
if (dmach->list == NULL)
{
dmainfo("Failed to kmm_malloc\n");
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/cxd56_emmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ int cxd56_emmcinitialize(void)
return -EIO;
}

buf = (uint8_t *)kmm_malloc(SECTOR_SIZE);
buf = kmm_malloc(SECTOR_SIZE);
if (buf)
{
putreg32(SECTOR_SIZE, EMMC_BYTCNT);
Expand Down
3 changes: 1 addition & 2 deletions arch/arm/src/cxd56xx/cxd56_geofence.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,7 @@ static int cxd56_geofence_register(const char *devpath)
struct cxd56_geofence_dev_s *priv;
int ret;

priv = (struct cxd56_geofence_dev_s *)kmm_zalloc(
sizeof(struct cxd56_geofence_dev_s));
priv = kmm_zalloc(sizeof(struct cxd56_geofence_dev_s));
if (!priv)
{
gnsserr("Failed to allocate instance\n");
Expand Down
11 changes: 5 additions & 6 deletions arch/arm/src/cxd56xx/cxd56_gnss.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ static int cxd56_gnss_save_backup_data(struct file *filep,
int n = 0;
int32_t offset = 0;

buf = (char *)kmm_malloc(CONFIG_CXD56_GNSS_BACKUP_BUFFER_SIZE);
buf = kmm_malloc(CONFIG_CXD56_GNSS_BACKUP_BUFFER_SIZE);
if (buf == NULL)
{
return -ENOMEM;
Expand Down Expand Up @@ -1054,7 +1054,7 @@ static int cxd56_gnss_check_cep_data(struct file *filep, unsigned long arg)

if (g_ceplen > 0)
{
g_cepdata = (char *)kmm_malloc(g_ceplen);
g_cepdata = kmm_malloc(g_ceplen);
}

if (!g_cepdata)
Expand Down Expand Up @@ -2267,7 +2267,7 @@ cxd56_gnss_read_cep_file(struct file *fp, int32_t offset,
goto err0;
}

buf = (char *)kmm_malloc(len);
buf = kmm_malloc(len);
if (buf == NULL)
{
ret = -ENOMEM;
Expand Down Expand Up @@ -2326,7 +2326,7 @@ static void cxd56_gnss_read_backup_file(int *retval)
size_t n;
int ret = 0;

buf = (char *)kmm_malloc(CONFIG_CXD56_GNSS_BACKUP_BUFFER_SIZE);
buf = kmm_malloc(CONFIG_CXD56_GNSS_BACKUP_BUFFER_SIZE);
if (buf == NULL)
{
ret = -ENOMEM;
Expand Down Expand Up @@ -3131,8 +3131,7 @@ static int cxd56_gnss_register(const char *devpath)
}
};

priv = (struct cxd56_gnss_dev_s *)kmm_zalloc(
sizeof(struct cxd56_gnss_dev_s));
priv = kmm_zalloc(sizeof(struct cxd56_gnss_dev_s));
if (!priv)
{
gnsserr("Failed to allocate instance\n");
Expand Down
3 changes: 1 addition & 2 deletions arch/arm/src/cxd56xx/cxd56_hostif.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ static int hif_initialize(struct hostif_buff_s *buffer)

/* Setup driver structure */

drv->dev =
(struct cxd56_hifdev_s *)kmm_malloc(sizeof(struct cxd56_hifdev_s) * num);
drv->dev = kmm_malloc(sizeof(struct cxd56_hifdev_s) * num);
if (drv->dev == NULL)
{
hiferr("ERROR: hostif allocation failed\n");
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/cxd56_icc.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static struct iccdev_s *icc_devnew(void)
struct iccdev_s *priv;
int i;

priv = (struct iccdev_s *)kmm_malloc(sizeof(struct iccdev_s));
priv = kmm_malloc(sizeof(struct iccdev_s));
if (!priv)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/cxd56_nxaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3783,7 +3783,7 @@ struct audio_lowerhalf_s *cxd56_initialize(
FAR struct cxd56_dev_s *priv;

audinfo("cxd56_initialize\n");
priv = (FAR struct cxd56_dev_s *)kmm_zalloc(sizeof(struct cxd56_dev_s));
priv = kmm_zalloc(sizeof(struct cxd56_dev_s));
if (priv)
{
priv->dev.ops = &g_audioops;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/cxd56_powermgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ void *cxd56_pm_register_callback(uint32_t target,

nxmutex_lock(&g_regcblock);

entry = (struct pm_cbentry_s *)kmm_malloc(sizeof(struct pm_cbentry_s));
entry = kmm_malloc(sizeof(struct pm_cbentry_s));
if (entry == NULL)
{
nxmutex_unlock(&g_regcblock);
Expand Down
6 changes: 3 additions & 3 deletions arch/arm/src/cxd56xx/cxd56_scu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ static struct seq_s *seq_new(void)

leave_critical_section(flags);

seq = (struct seq_s *)kmm_zalloc(sizeof(struct seq_s));
seq = kmm_zalloc(sizeof(struct seq_s));
if (!seq)
{
seq_free(sid);
Expand Down Expand Up @@ -1818,7 +1818,7 @@ static struct seq_s *deci_new(void)

leave_critical_section(flags);

deci = (struct decimator_s *)kmm_zalloc(sizeof(struct decimator_s));
deci = kmm_zalloc(sizeof(struct decimator_s));
if (!deci)
{
deci_free(sid);
Expand Down Expand Up @@ -1873,7 +1873,7 @@ static int seq_fifoinit(struct seq_s *seq, int fifoid, uint16_t fsize)
}
}

fifo = (struct scufifo_s *)kmm_zalloc(sizeof(struct scufifo_s));
fifo = kmm_zalloc(sizeof(struct scufifo_s));
if (!fifo)
{
return -ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/cxd56_sfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ struct mtd_dev_s *cxd56_sfc_initialize(void)

/* Allocate a buffer for the erase block cache */

priv->cache = (uint8_t *)kmm_malloc(SPIFI_BLKSIZE);
priv->cache = kmm_malloc(SPIFI_BLKSIZE);
if (!priv->cache)
{
/* Allocation failed! */
Expand Down
3 changes: 1 addition & 2 deletions arch/arm/src/cxd56xx/cxd56_textheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@

void *up_textheap_memalign(size_t align, size_t size)
{
void *ret;
ret = (void *)kmm_malloc(size);
void *ret = kmm_malloc(size);

#ifdef CONFIG_CXD56_USE_SYSBUS
if (ret)
Expand Down
11 changes: 4 additions & 7 deletions arch/arm/src/cxd56xx/cxd56_usbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ static struct usbdev_req_s *cxd56_epallocreq(struct usbdev_ep_s *ep)
#endif
usbtrace(TRACE_EPALLOCREQ, ((struct cxd56_ep_s *)ep)->epphy);

privreq = (struct cxd56_req_s *)kmm_malloc(sizeof(struct cxd56_req_s));
privreq = kmm_malloc(sizeof(struct cxd56_req_s));
if (!privreq)
{
usbtrace(TRACE_DEVERROR(CXD56_TRACEERR_ALLOCFAIL), 0);
Expand Down Expand Up @@ -2590,8 +2590,7 @@ static int cxd56_allocepbuffer(struct cxd56_ep_s *privep)
DEBUGASSERT(!privep->desc && !privep->buffer);
DEBUGASSERT(privep->epphy); /* Do not use for EP0 */

privep->desc =
(struct cxd56_data_desc_s *)kmm_malloc(sizeof(struct cxd56_data_desc_s));
privep->desc = kmm_malloc(sizeof(struct cxd56_data_desc_s));
if (!privep->desc)
{
return -1;
Expand Down Expand Up @@ -3394,8 +3393,7 @@ static int cxd56_usbdev_open(struct file *filep, const char *relpath,

/* Allocate the open file structure */

priv = (struct cxd56_usbdev_file_s *)kmm_zalloc(
sizeof(struct cxd56_usbdev_file_s));
priv = kmm_zalloc(sizeof(struct cxd56_usbdev_file_s));
if (!priv)
{
uerr("ERROR: Failed to allocate file attributes\n");
Expand Down Expand Up @@ -3489,8 +3487,7 @@ static int cxd56_usbdev_dup(const struct file *oldp,

/* Allocate a new container to hold the task and attribute selection */

newattr = (struct cxd56_usbdev_file_s *)kmm_malloc(
sizeof(struct cxd56_usbdev_file_s));
newattr = kmm_malloc(sizeof(struct cxd56_usbdev_file_s));
if (!newattr)
{
uerr("ERROR: Failed to allocate file attributes\n");
Expand Down
10 changes: 5 additions & 5 deletions arch/arm/src/dm320/dm320_framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ static int dm320_allocvideomemory(void)
{
#ifndef CONFIG_DM320_VID0_DISABLE
#ifndef CONFIG_DM320_DISABLE_PINGPONG
g_vid0base = (void *)kmm_malloc(2 * DM320_VID0_FBLEN);
g_vid0base = kmm_malloc(2 * DM320_VID0_FBLEN);
g_vid0ppbase = (char *)g_vid0base + DM320_VID0_FBLEN;
#else
g_vid0base = (void *)kmm_malloc(DM320_VID0_FBLEN);
g_vid0base = kmm_malloc(DM320_VID0_FBLEN);
#endif
if (!g_vid0base)
{
Expand All @@ -689,23 +689,23 @@ static int dm320_allocvideomemory(void)
#endif

#ifndef CONFIG_DM320_VID1_DISABLE
g_vid1base = (void *)kmm_malloc(DM320_VID1_FBLEN);
g_vid1base = kmm_malloc(DM320_VID1_FBLEN);
if (!g_vid1base)
{
goto errout;
}
#endif

#ifndef CONFIG_DM320_OSD0_DISABLE
g_osd0base = (void *)kmm_malloc(DM320_OSD0_FBLEN);
g_osd0base = kmm_malloc(DM320_OSD0_FBLEN);
if (!g_osd0base)
{
goto errout;
}
#endif

#ifndef CONFIG_DM320_OSD1_DISABLE
g_osd1base = (void *)kmm_malloc(DM320_OSD1_FBLEN);
g_osd1base = kmm_malloc(DM320_OSD1_FBLEN);
if (!g_osd1base)
{
goto errout;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/dm320/dm320_usbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ static struct usbdev_req_s *dm320_epallocreq(struct usbdev_ep_s *ep)

usbtrace(TRACE_EPALLOCREQ, ((struct dm320_ep_s *)ep)->epphy);

privreq = (struct dm320_req_s *)kmm_malloc(sizeof(struct dm320_req_s));
privreq = kmm_malloc(sizeof(struct dm320_req_s));
if (!privreq)
{
usbtrace(TRACE_DEVERROR(DM320_TRACEERR_ALLOCFAIL), 0);
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/efm32/efm32_usbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -4328,7 +4328,7 @@ static struct usbdev_req_s *efm32_ep_allocreq(struct usbdev_ep_s *ep)

usbtrace(TRACE_EPALLOCREQ, ((struct efm32_ep_s *)ep)->epphy);

privreq = (struct efm32_req_s *)kmm_malloc(sizeof(struct efm32_req_s));
privreq = kmm_malloc(sizeof(struct efm32_req_s));
if (!privreq)
{
usbtrace(TRACE_DEVERROR(EFM32_TRACEERR_ALLOCFAIL), 0);
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/src/efm32/efm32_usbhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -4277,7 +4277,7 @@ static int efm32_alloc(struct usbhost_driver_s *drvr,

/* There is no special memory requirement for the EFM32. */

alloc = (uint8_t *)kmm_malloc(CONFIG_EFM32_OTGFS_DESCSIZE);
alloc = kmm_malloc(CONFIG_EFM32_OTGFS_DESCSIZE);
if (!alloc)
{
return -ENOMEM;
Expand Down Expand Up @@ -4361,7 +4361,7 @@ static int efm32_ioalloc(struct usbhost_driver_s *drvr,

/* There is no special memory requirement */

alloc = (uint8_t *)kmm_malloc(buflen);
alloc = kmm_malloc(buflen);
if (!alloc)
{
return -ENOMEM;
Expand Down
23 changes: 8 additions & 15 deletions arch/arm/src/imxrt/imxrt_ehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -3955,8 +3955,7 @@ static int imxrt_epalloc(struct usbhost_driver_s *drvr,

/* Allocate a endpoint information structure */

epinfo = (struct imxrt_epinfo_s *)
kmm_zalloc(sizeof(struct imxrt_epinfo_s));
epinfo = kmm_zalloc(sizeof(struct imxrt_epinfo_s));
if (!epinfo)
{
usbhost_trace1(EHCI_TRACE1_EPALLOC_FAILED, 0);
Expand Down Expand Up @@ -4067,8 +4066,7 @@ static int imxrt_alloc(struct usbhost_driver_s *drvr,
* multiple of the cache line size in length.
*/

*buffer = (uint8_t *)kmm_memalign(ARMV7M_DCACHE_LINESIZE,
IMXRT_EHCI_BUFSIZE);
*buffer = kmm_memalign(ARMV7M_DCACHE_LINESIZE, IMXRT_EHCI_BUFSIZE);
if (*buffer)
{
*maxlen = IMXRT_EHCI_BUFSIZE;
Expand Down Expand Up @@ -4155,7 +4153,7 @@ static int imxrt_ioalloc(struct usbhost_driver_s *drvr,
*/

buflen = (buflen + DCACHE_LINEMASK) & ~DCACHE_LINEMASK;
*buffer = (uint8_t *)kumm_memalign(ARMV7M_DCACHE_LINESIZE, buflen);
*buffer = kumm_memalign(ARMV7M_DCACHE_LINESIZE, buflen);
return *buffer ? OK : -ENOMEM;
}

Expand Down Expand Up @@ -5058,10 +5056,8 @@ struct usbhost_connection_s *imxrt_ehci_initialize(int controller)
# ifndef CONFIG_IMXRT_EHCI_PREALLOCATE
/* Allocate a pool of free Queue Head (QH) structures */

g_qhpool =
(struct imxrt_qh_s *)kmm_memalign(32,
CONFIG_IMXRT_EHCI_NQHS *
sizeof(struct imxrt_qh_s));
g_qhpool = kmm_memalign(32, CONFIG_IMXRT_EHCI_NQHS *
sizeof(struct imxrt_qh_s));
if (!g_qhpool)
{
usbhost_trace1(EHCI_TRACE1_QHPOOLALLOC_FAILED, 0);
Expand All @@ -5081,10 +5077,8 @@ struct usbhost_connection_s *imxrt_ehci_initialize(int controller)
# ifndef CONFIG_IMXRT_EHCI_PREALLOCATE
/* Allocate a pool of free Transfer Descriptor (qTD) structures */

g_qtdpool =
(struct imxrt_qtd_s *)kmm_memalign(32,
CONFIG_IMXRT_EHCI_NQTDS *
sizeof(struct imxrt_qtd_s));
g_qtdpool = kmm_memalign(32, CONFIG_IMXRT_EHCI_NQTDS *
sizeof(struct imxrt_qtd_s));
if (!g_qtdpool)
{
usbhost_trace1(EHCI_TRACE1_QTDPOOLALLOC_FAILED, 0);
Expand All @@ -5096,8 +5090,7 @@ struct usbhost_connection_s *imxrt_ehci_initialize(int controller)
# if !defined(CONFIG_IMXRT_EHCI_PREALLOCATE) && !defined(CONFIG_USBHOST_INT_DISABLE)
/* Allocate the periodic framelist */

g_framelist = (uint32_t *)
kmm_memalign(4096, FRAME_LIST_SIZE * sizeof(uint32_t));
g_framelist = kmm_memalign(4096, FRAME_LIST_SIZE * sizeof(uint32_t));
if (!g_framelist)
{
usbhost_trace1(EHCI_TRACE1_PERFLALLOC_FAILED, 0);
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/imxrt/imxrt_usbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,7 @@ static struct usbdev_req_s *imxrt_epallocreq(struct usbdev_ep_s *ep)

usbtrace(TRACE_EPALLOCREQ, ((struct imxrt_ep_s *)ep)->epphy);

privreq = (struct imxrt_req_s *)kmm_malloc(sizeof(struct imxrt_req_s));
privreq = kmm_malloc(sizeof(struct imxrt_req_s));
if (!privreq)
{
usbtrace(TRACE_DEVERROR(IMXRT_TRACEERR_ALLOCFAIL), 0);
Expand Down
Loading

0 comments on commit 664927c

Please sign in to comment.