TORONTO -- A man with a marijuana grow-op in his basement has had his drug conviction thrown out because police had no right to enter his home -- even though his four-year-old had been found wandering alone near a busy intersection dressed only in a diaper, Ontario's top court ruled on Wednesday.

While officers said they went into the home in Barrie, Ont., to check that the child would be safe, the Court of Appeal found that to be a ruse. What they did, the court found, amounted to an illegal search and a breach of Harley Davidson's rights.

"Police can enter a home without a warrant if they have reasonable grounds to believe it is necessary to do so to protect a person's life or safety," the Appeal Court said. "(That) does not give the police sweeping authority to enter a home without a warrant to investigate whether a child's mother and father are good parents."

The case arose when a passing motorist called 911 one June morning to report the boy standing alone next to the busy road. By the time they arrived, the child's mom had him safely in her arms, court records say.

Davidson arrived soon after to say his son was autistic and tended to wander. Documents cite him as telling police his boy had managed to get out of the house despite a special lock on the door. Davidson agreed to allow police to look at the lock, but they then insisted on going inside, saying they were entitled to do so to check on the boy's well being, court records say.

Once inside, the officers smelled marijuana and began looking around, including in cupboards and the fridge. The lead investigator went to the basement and found growing marijuana plants, court records say. Police arrested Davidson and charged him with various drug-related offences.

At the start of his trial in 2014, Davidson argued among other things that police had violated his constitutional rights with the search -- an assertion Superior Court Justice John McIsaac rejected. Essentially, McIsaac found police were entitled to do a "protective sweep" of the home because of their "child-protection concerns."

McIsaac rejected any suggestion police were using the child as a ruse or pretext to "insinuate themselves into a suspected drug operation," according to court documents. He admitted the marijuana evidence and convicted Davidson.

On appeal, the prosecution argued the search was appropriate and justified. The Court of Appeal, however, saw it differently.

In quashing the conviction, the Appeal Court leaned on trial evidence from the lead investigator, who made it clear he had no concerns the boy was in serious danger in the home, and that he would have had no grounds to obtain a search warrant.

Justice John Laskin, writing for the Appeal Court, noted the Supreme Court has found police have a duty to investigate 911 calls and a limited right to enter a home without a warrant.

"Once inside the home, their authority is limited to ascertaining the reason for the (911) call and providing any needed assistance," Laskin said. "They do not have any further authority to search the home or intrude on a resident's privacy or property."

Laskin found the rights breaches were serious enough to merit throwing out the marijuana evidence, and entered an acquittal.