PaulStoffregen / SD

70 stars 41 forks source link

check alignment for DMA buffers #17

Closed tsandmann closed 5 years ago

tsandmann commented 5 years ago

I really like the idea of using DMA to access the SD card, but you should check the user-supplied buffers to SDHC_CardReadBlock(() and SDHC_CardWriteBlock() for a correct alignment to prevent data corruption. The least 2 significant bits of SDHC_DSADDR are always 0 on a K66 device, therefore the buffer address has to be 4 byte aligned.

FrankBoesing commented 5 years ago

no need to check it this way.. if you just delete the lower bits the program will crash too because it will overwrite other variables.

tsandmann commented 5 years ago

no need to check it this way.. if you just delete the lower bits the program will crash too because it will overwrite other variables.

but SDHC_CardWriteBlock() would write wrong data to the SD card then resulting in corrupted data on the card.

FrankBoesing commented 5 years ago

Yes, It does writes wrong data, if you move the buffer... and the user does not know about it. So where is this better?

FrankBoesing commented 5 years ago

its even worse.

tsandmann commented 5 years ago

Yes, that's why it just checks the alignment and returns -1 to inform the user, if the alignment is wrong. Or do I miss anything here?

FrankBoesing commented 5 years ago

oops, forgot about the return.. you're right. forget it.