46-22-101. Applicability of writ of habeas corpus. (1) Except as provided in subsection (2), every person imprisoned or otherwise restrained of liberty within this state may prosecute a writ of habeas corpus to inquire into the cause of imprisonment or restraint and, if illegal, to be delivered from the imprisonment or restraint.
(2) The writ of habeas corpus is not available to attack the validity of the conviction or sentence of a person who has been adjudged guilty of an offense in a court of record and has exhausted the remedy of appeal. The relief under this chapter is not available to attack the legality of an order revoking a suspended or deferred sentence.