TORONTO -- Ontario's top court has ruled that a man whose case prompted a constitutional challenge to a mandatory minimum sentence for a gun crime should not be sent back to jail.

Leroy Smickle was in his cousin's house in his boxers, posing for a Facebook picture with a loaded handgun, when police burst in with a search warrant for the cousin, who they believed had illegal firearms.

He was convicted of possession of a loaded prohibited firearm, but the trial judge ruled a three-year sentence -- the mandatory minimum enacted in 2008 -- would be cruel and unusual so she declared it unconstitutional.

The judge gave Smickle a one-year conditional sentence, but gave him seven months of credit for three months he spent in pre-sentence custody.

Late last year, Ontario's Appeal Court struck down the mandatory minimum as unconstitutional but said Smickle's sentence was "totally inadequate" and ordered his lawyers to return to court to argue his sentence.

In a ruling released today, the Appeal Court says Smickle completed his sentence long ago and has spent the last two years as a law-abiding father supporting his family.

The court says Smickle should have originally been sentenced to two years less a day, but it has imposed a permanent stay of the sentence, meaning Smickle won't be sent back to jail.

"When, as in this case, the sentencing of an accused has been delayed by a lengthy appellate process, and the accused has served the sentence imposed at trial, the imposition of a 'just sanction' demands that those factors be taken into account," the court wrote.

"The respondent completed the sentence imposed on him long ago. He has spent the last two years in legal limbo uncertain as to whether he would be required to return to jail and, if so, for how long. Those hardships must be taken into account."

Smickle is now working two jobs, developing his own business, has a "stable, loving relationship with his fiancee" and a close relationship with his two children, who he supports financially, the court noted.