Ally Financial swung to a loss in the second quarter as its mortgage unit Residential Capital limped through bankruptcy.

The bank reported an $898 million loss, down from a $113 million profit one year ago and a $310 million gain in the previous quarter.

Ally took a $1.2 billion charge from placing ResCap into bankruptcy in May.

According to the financial report Wednesday, Berkshire Hathaway replaced Ally as the stalking horse bidder on the failed mortgage unit's loan portfolio.

A bankruptcy court entered an injunction of 24 lawsuits against Ally and ResCap until Oct. 31.

The Ally mortgage unit operating outside of ResCap originated $5.9 billion in mortgages during the quarter, nearly half the $12.3 billion in home loans written one year ago.

Refinancing activity accounted for 82% of originations during the quarter.

Ally planned to shrink its mortgage department as the ResCap bankruptcy progresses. It will leave the warehouse lending business over the coming months, executives said in a conference call with investors Wednesday.

The bank will honor its contractual obligations during this process and will provide clients with opportunities for a reasonable time to find alternative funding sources. The wind-down should be completed by the end of the year.

"Ally Bank made this decision after careful consideration of all the available options and determined that this was the best course of action and in line with adjustments it has made in other areas of its mortgage operations," a spokeswoman said.

 The bank holds $124 million in reserves for repurchases soured mortgages from investors. Roughly $82 million in buyback claims are outstanding as of June 30.

"The ResCap Chapter 11 case continues to move forward, and plans to pursue alternatives for Ally's international operations are underway," said Ally CEO Michael Carpenter.