Defect-induced defect-mediated magnetism in ZnO and carbon