Dust is one of the most critical issues in assembly of Compact Camera Module(CCM) for mobile phones. Defect due to dust entry or dust deposit severely degrades image quality. There have been lots of literatures about the compensating of dust defect on images by image processing, but the discussion about where the dust locates is still deficient. Dust may sneak in the CCM in any step of packaging process, so the analysis of the dust location may be useful for improving of the production line. This work develops an optical inspection algorithm to detect the location of dust inside CCM based on imaging optics. A planar light source with uniformly emission is designed as the capture target. A series of defocused images are then taken and analyzed. According to the dependence of the image defect on the capture distance, the location of the dust can be well defined. This inspection algorithm provides an easy and efficient way to help manufacturers improve their packaging process.