Commit ef2d12ce authored by Udi Atar's avatar Udi Atar Committed by Mauro Carvalho Chehab

V4L/DVB (12450): Siano: Fixed SDIO compilation bugs

Fixed SDIO compilation bugs
Also fixed a memory overrun issue in buffer management.
Signed-off-by: default avatarUdi Atar <udia@siano-ms.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent f2e26ae7
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#define SMSSDIO_DATA 0x00 #define SMSSDIO_DATA 0x00
#define SMSSDIO_INT 0x04 #define SMSSDIO_INT 0x04
#define SMSSDIO_BLOCK_SIZE 128
static const struct sdio_device_id smssdio_ids[] = { static const struct sdio_device_id smssdio_ids[] = {
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_STELLAR), {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_STELLAR),
...@@ -85,7 +86,8 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size) ...@@ -85,7 +86,8 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size)
sdio_claim_host(smsdev->func); sdio_claim_host(smsdev->func);
while (size >= smsdev->func->cur_blksize) { while (size >= smsdev->func->cur_blksize) {
ret = sdio_write_blocks(smsdev->func, SMSSDIO_DATA, buffer, 1); ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
buffer, smsdev->func->cur_blksize);
if (ret) if (ret)
goto out; goto out;
...@@ -94,8 +96,8 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size) ...@@ -94,8 +96,8 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size)
} }
if (size) { if (size) {
ret = sdio_write_bytes(smsdev->func, SMSSDIO_DATA, ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
buffer, size); buffer, size);
} }
out: out:
...@@ -125,23 +127,23 @@ static void smssdio_interrupt(struct sdio_func *func) ...@@ -125,23 +127,23 @@ static void smssdio_interrupt(struct sdio_func *func)
*/ */
isr = sdio_readb(func, SMSSDIO_INT, &ret); isr = sdio_readb(func, SMSSDIO_INT, &ret);
if (ret) { if (ret) {
dev_err(&smsdev->func->dev, sms_err("Unable to read interrupt register!\n");
"Unable to read interrupt register!\n");
return; return;
} }
if (smsdev->split_cb == NULL) { if (smsdev->split_cb == NULL) {
cb = smscore_getbuffer(smsdev->coredev); cb = smscore_getbuffer(smsdev->coredev);
if (!cb) { if (!cb) {
dev_err(&smsdev->func->dev, sms_err("Unable to allocate data buffer!\n");
"Unable to allocate data buffer!\n");
return; return;
} }
ret = sdio_read_blocks(smsdev->func, cb->p, SMSSDIO_DATA, 1); ret = sdio_memcpy_fromio(smsdev->func,
cb->p,
SMSSDIO_DATA,
SMSSDIO_BLOCK_SIZE);
if (ret) { if (ret) {
dev_err(&smsdev->func->dev, sms_err("Error %d reading initial block!\n", ret);
"Error %d reading initial block!\n", ret);
return; return;
} }
...@@ -152,7 +154,10 @@ static void smssdio_interrupt(struct sdio_func *func) ...@@ -152,7 +154,10 @@ static void smssdio_interrupt(struct sdio_func *func)
return; return;
} }
size = hdr->msgLength - smsdev->func->cur_blksize; if (hdr->msgLength > smsdev->func->cur_blksize)
size = hdr->msgLength - smsdev->func->cur_blksize;
else
size = 0;
} else { } else {
cb = smsdev->split_cb; cb = smsdev->split_cb;
hdr = cb->p; hdr = cb->p;
...@@ -162,23 +167,24 @@ static void smssdio_interrupt(struct sdio_func *func) ...@@ -162,23 +167,24 @@ static void smssdio_interrupt(struct sdio_func *func)
smsdev->split_cb = NULL; smsdev->split_cb = NULL;
} }
if (hdr->msgLength > smsdev->func->cur_blksize) { if (size) {
void *buffer; void *buffer;
size = ALIGN(size, 128); buffer = cb->p + (hdr->msgLength - size);
buffer = cb->p + hdr->msgLength; size = ALIGN(size, SMSSDIO_BLOCK_SIZE);
BUG_ON(smsdev->func->cur_blksize != 128); BUG_ON(smsdev->func->cur_blksize != SMSSDIO_BLOCK_SIZE);
/* /*
* First attempt to transfer all of it in one go... * First attempt to transfer all of it in one go...
*/ */
ret = sdio_read_blocks(smsdev->func, buffer, ret = sdio_memcpy_fromio(smsdev->func,
SMSSDIO_DATA, size / 128); buffer,
SMSSDIO_DATA,
size);
if (ret && ret != -EINVAL) { if (ret && ret != -EINVAL) {
smscore_putbuffer(smsdev->coredev, cb); smscore_putbuffer(smsdev->coredev, cb);
dev_err(&smsdev->func->dev, sms_err("Error %d reading data from card!\n", ret);
"Error %d reading data from card!\n", ret);
return; return;
} }
...@@ -191,12 +197,12 @@ static void smssdio_interrupt(struct sdio_func *func) ...@@ -191,12 +197,12 @@ static void smssdio_interrupt(struct sdio_func *func)
*/ */
if (ret == -EINVAL) { if (ret == -EINVAL) {
while (size) { while (size) {
ret = sdio_read_blocks(smsdev->func, ret = sdio_memcpy_fromio(smsdev->func,
buffer, SMSSDIO_DATA, 1); buffer, SMSSDIO_DATA,
smsdev->func->cur_blksize);
if (ret) { if (ret) {
smscore_putbuffer(smsdev->coredev, cb); smscore_putbuffer(smsdev->coredev, cb);
dev_err(&smsdev->func->dev, sms_err("Error %d reading "
"Error %d reading "
"data from card!\n", ret); "data from card!\n", ret);
return; return;
} }
...@@ -269,7 +275,7 @@ static int smssdio_probe(struct sdio_func *func, ...@@ -269,7 +275,7 @@ static int smssdio_probe(struct sdio_func *func,
if (ret) if (ret)
goto release; goto release;
ret = sdio_set_block_size(func, 128); ret = sdio_set_block_size(func, SMSSDIO_BLOCK_SIZE);
if (ret) if (ret)
goto disable; goto disable;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment