Dual origin of defect magnetism in graphene and its reversible switching by molecular doping