From 7022b8285fc3e61747996fa488241bb30cff3569 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Wed, 14 Mar 2012 07:59:50 +0000 Subject: [PATCH] remove alignment memory allocation from SDIO framework. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1995 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/drivers/sdio/block_dev.c | 36 ++++------------------------ components/drivers/sdio/mmcsd_core.c | 16 ++++++------- components/drivers/sdio/sd.c | 16 ++++--------- 3 files changed, 16 insertions(+), 52 deletions(-) diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index 362e1e3a28..d9f3793649 100644 --- a/components/drivers/sdio/block_dev.c +++ b/components/drivers/sdio/block_dev.c @@ -154,25 +154,7 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card, rt_uint32_t sector, } mmcsd_set_data_timeout(&data, card); - - if (((rt_uint32_t)buf & (32 - 1)) != 0) /* the buf address is not aligned to 32 */ - { - aligned_buf = rt_malloc_align(data.blks * data.blksize, 32); - - if (aligned_buf == RT_NULL) - { - rt_kprintf("allocate memory failed\n"); - return -RT_ENOMEM; - } - - if (dir)//write - rt_memcpy(aligned_buf, buf, data.blks*data.blksize); - - data.buf = aligned_buf; - } - else - data.buf = buf; - + data.buf = buf; mmcsd_send_request(host, &req); if (!controller_is_spi(card->host) && dir != 0) @@ -206,19 +188,9 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card, rt_uint32_t sector, rt_kprintf("mmcsd request blocks error\n"); rt_kprintf("%d,%d,%d, 0x%08x,0x%08x\n", cmd.err, data.err, stop.err, data.flags, sector); - if (((rt_uint32_t)buf & (32 - 1)) != 0) - rt_free_align(aligned_buf); - return -RT_ERROR; } - if (((rt_uint32_t)buf & (32 - 1)) != 0) - { - if (!dir)//read - rt_memcpy(buf, data.buf, data.blks*data.blksize); - rt_free_align(aligned_buf); - } - return RT_EOK; } @@ -257,7 +229,7 @@ static rt_size_t rt_mmcsd_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_s struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data; struct dfs_partition *part = &blk_dev->part; - if ( dev == RT_NULL ) + if (dev == RT_NULL) { rt_set_errno(-DFS_STATUS_EINVAL); return 0; @@ -342,7 +314,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) } /* get the first sector to read partition table */ - sector = (rt_uint8_t *)rt_malloc_align(SECTOR_SIZE, 32); + sector = (rt_uint8_t *) rt_malloc(SECTOR_SIZE); if (sector == RT_NULL) { rt_kprintf("allocate partition sector buffer failed\n"); @@ -444,7 +416,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) } /* release sector buffer */ - rt_free_align(sector); + rt_free(sector); return err; } diff --git a/components/drivers/sdio/mmcsd_core.c b/components/drivers/sdio/mmcsd_core.c index c6c95ec388..ad1483f54f 100644 --- a/components/drivers/sdio/mmcsd_core.c +++ b/components/drivers/sdio/mmcsd_core.c @@ -175,10 +175,10 @@ rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid) return 0; } - buf = rt_malloc_align(16, 32); + buf = (rt_uint8_t *)rt_malloc(16); if (!buf) { - rt_kprintf("malloc mem failed\n"); + rt_kprintf("allocate memory failed\n"); return -RT_ENOMEM; } @@ -214,13 +214,13 @@ rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid) if (cmd.err || data.err) { - rt_free_align(buf); + rt_free(buf); return -RT_ERROR; } for (i = 0;i < 4;i++) cid[i] = buf[i]; - rt_free_align(buf); + rt_free(buf); return 0; } @@ -248,10 +248,10 @@ rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd) return 0; } - buf = rt_malloc_align(16, 32); + buf = (rt_uint8_t*)rt_malloc(16); if (!buf) { - rt_kprintf("malloc mem failed\n"); + rt_kprintf("allocate memory failed\n"); return -RT_ENOMEM; } @@ -288,13 +288,13 @@ rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd) if (cmd.err || data.err) { - rt_free_align(buf); + rt_free(buf); return -RT_ERROR; } for (i = 0;i < 4;i++) csd[i] = buf[i]; - rt_free_align(buf); + rt_free(buf); return 0; } diff --git a/components/drivers/sdio/sd.c b/components/drivers/sdio/sd.c index 6e17b123f0..c00625a9e6 100644 --- a/components/drivers/sdio/sd.c +++ b/components/drivers/sdio/sd.c @@ -179,13 +179,12 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card) struct rt_mmcsd_data data; rt_uint8_t *buf; - buf = rt_malloc_align(64, 32); + buf = (rt_uint8_t*)rt_malloc(64); if (!buf) { rt_kprintf("alloc memory failed\n"); return -RT_ENOMEM; } - if (card->card_type != CARD_TYPE_SD) goto err; @@ -258,19 +257,12 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card) card->flags |= CARD_FLAG_HIGHSPEED; err: - rt_free_align(buf); + rt_free(buf); return 0; err1: - if (cmd.err) - { - err = cmd.err; - } - - if (data.err) - { - err = data.err; - } + if (cmd.err) err = cmd.err; + if (data.err) err = data.err; return err; }