(Reuters) - A U.S. appeals court on Thursday struck down a Florida law that barred doctors from asking patients about gun ownership, ruling that the law violated doctors’ right to free speech.

The decision, from the 11th U.S. Circuit Court of Appeals in Atlanta, reverses an earlier decision in the so-called “Docs v. Glocks” case by a three-judge panel of that court upholding the law.

The Florida attorney general’s office and an attorney representing the doctors challenging the law could not immediately be reached for comment.

The American Civil Liberties Union of Florida, which filed a friend-of-the-court brief on behalf of a group of medical and child welfare organizations opposing the law, praised the decision.

“We are thrilled that the court has finally put to bed the nonsensical and dangerous idea that a doctor speaking with a patient about gun safety somehow threatens the right to own a gun,” ACLU of Florida Executive Director Howard Simon said in a news release.

The so-called Firearm Owners’ Privacy Act, passed in 2011 by Florida’s Republican-led legislature, says that doctors can ask patients whether they own guns only if they have reason to believe in “good faith” that the information is medically relevant.

It was passed in response to several accounts from Florida residents of doctors refusing to provide care if they did not answer questions about their gun ownership.

Doctors who violate the law faced penalties including fines and permanent revocation of their medical licenses.

Doctors opposing the law have said they ask about gun ownership as a normal part of screening new patients, along with questions about drug and alcohol use, smoking, exercise and eating habits.

Soon after the law was passed, individual doctors and medical associations challenged it in court, arguing it violated their right to free speech under the First Amendment of the Constitution.

A federal judge agreed, ruling the law unconstitutional in 2012, and the state appealed.

A 2-1 panel of the 11th Circuit reversed that decision in July 2014, saying the law was a “legitimate regulation” of the medical profession intended to promote good medical care.

But the full 11th Circuit reversed that ruling 10-1, finding the state had not shown any valid reason for restricting doctors’ speech.

The court did uphold one part of the law, which bars doctors from discriminating against patients solely because they own guns.