In case the SD card corrupted you should test it for defects.
- Copy all your data from the SD to a computer. Reformat the SD to FAT32, 32kb cluster size, if bigger than 32GB and using Windows with guiformat.
- Check your SD Windows, Linux, OS X.
- If you get any errors replace the SD.
- If you get no errors copy your files back on the SD.
What makes you think there is malware ("a virus") on the SD? As far as I know, no "real" malware for the 2|3DS came out (besides Gateway bricking code).
If you are talking about malware on your computer you should troubleshoot that first.
Reformatting the SD does not remove the CFW from the 3DS. No need to start from the beginning. If your current setup can't be restored – for whatever reason, repeat the finalizing setup
on an SD which is known to work(tested).