I agree with Fr. hαɾɾιson, but I would add one point: One does not have to be obedient to a heretical pope or bishop.
Paul IV, cuм Ex Apostolatus Officio:
I. the clergy, secular and religious;
II. the laity;
III. the Cardinals, even those who shall have taken part in the election of this very Pontiff previously deviating from the Faith or heretical or schismatical, or shall otherwise have consented and vouchsafed obedience to him and shall have venerated him;
IV. Castellans, Prefects, Captains and Officials, even of Our Beloved City and of the entire Ecclesiastical State, even if they shall be obliged and beholden to those thus promoted or elevated by homage, oath or security; shall be permitted at any time to withdraw with impunity from obedience and devotion to those thus promoted or elevated and to avoid them as warlocks, heathens, publicans, and heresiarchs (the same subject persons, nevertheless, remaining bound by the duty of fidelity and obedience to any future Bishops, Archbishops, Patriarchs, Primates, Cardinals and Roman Pontiff canonically entering).