The Supreme Court yesterday endorsed a 40-year prison sentence for a Virginia man convicted of sale and possession of less than nine ounces of marijuana.

The justices overturned a lower court ruling that such a sentence was cruel and unusual punishment because of its length. It sent the case back to the Fourth U.S. Circuit Court of Appeals with instructions to reconsider it in light of another Supreme Court ruling last month: a decision upholding a life sentence for a man convicted of swindling $220.

The 1974 trial of Roger Trenton Davis attracted considerable media attention because of the length of the sentence and because his defenders believed he was being harassed for racial reasons.

Davis, who is black, was tried in the small rural southwestern Virginia town of Wytheville, where he was attacked by white youths for interracial dating. A cross was burned on his lawn.

The Wytheville jury sentenced Davis to 20 years each on the sale and possession charges and the state judge in the case ordered him to serve the two sentences consecutively.

U.S. District Court Judge James C. Turk threw the sentence out because he thought it grossly disproportionate to the crime. In doing so, Turk, and later the full appeals court, went out on a limb because neither the Supreme Court nor any other federal court had ever intervened in a state court's sentencing decision simply because it was too lengthy.

Yesterday, the Supreme Court cut the limb off. The decision cited by the justices in sending the case back held that federal judges have little business interfering in state sentences.Only an overriding constitutional question, such as illegal imposition of the death penalty, justifies such intervention, the court said in the case of Rummel vs Estelle.

The Appeals Court conceivably could stick to its earlier judgement that the 40-year sentence for Davis is cruel and unusual.

Then the Supreme Court probably would overrule the lower judges in more explicit terms, lawyers speculated yesterday. The message of Rummel v. Estelle, though complicated, was clear, lawyers said.

The principal evidence against Davis came from an inmate in a Virginia prison, who was allowed out of prison to act as a police informant and try to purchase drugs from Davis.

According to prosecutors, Davis sold the informant marijuana and LSD. He was only convicted of peddling the marijuana, however. Police also raided Davis' home after the informant's buy and found more marijuana, prosecutors said.

His sentence came at a time of anti-drug fervor in rural southwestern Virginia that sent a number of young people from the area to state institutions for relatively minor drug offenses.