
21 Cal.App.4th 873 (1994)
26 Cal. Rptr.2d 439
DONALD B. SILIGO et al., Plaintiffs and Appellants,
v.
JOHN D. CASTELLUCCI et al., Defendants and Respondents.
Docket No. H010061.
Court of Appeals of California, Sixth District.
January 10, 1994.
*875 COUNSEL
Graham & James, Paul A. Dezurick, Kristen J. Thorsness and Suzanne E. Curtis for Plaintiffs and Appellants.
Kenneth P. Roberts for Defendants and Respondents.
OPINION
ELIA, J.
In an action arising from the sale of a business the trial court rendered a judgment in favor of the plaintiff-seller (Siligo) and against the defendant-buyer (Castellucci).[1] The judgment awarded Siligo limited contractual attorney fees by denying the bulk of fees which were apportioned to defense of a cross-complaint for fraud; it also ordered some of the attorney fees subject to a contractual provision limiting recovery of a deficiency after foreclosure; it finally ordered judicial foreclosure of a parcel of real property giving Castellucci deficiency judgment credit for diminution in the value of the property due to petroleum contamination. Siligo appeals. He challenges *876 the propriety of the (1) attorney fee apportionment, (2) attorney fee application to the deficiency limitation, and (3) deficiency judgment credit. We reverse the judgment.

Background
Siligo sold business assets to Castellucci via a series of agreements to be performed over time. The assets included bulk petroleum storage plants and a gasoline station. After the sale closed, Castellucci accused Siligo of concealing that there had been a leak in a storage tank at the gas station and ceased performing his obligations under the agreements. Siligo filed suit. The parties settled the litigation by renegotiating the purchase price and agreements. They also signed a general release. Afterward, Castellucci discovered petroleum contamination at one of the bulk storage plants and stopped performing his obligations under the new agreements. Siligo filed this action for breach of contract. Castellucci answered and asserted an affirmative defense alleging fraud in that Siligo knew of the contamination at the time of the sale but concealed its existence from Castellucci. The answer alleged that the amount required to clean up the contamination would exceed $250,000, and the prayer sought a setoff of this amount against any sums found due from Castellucci to Siligo. Castellucci also filed a cross-complaint for the same fraud alleged in the answer seeking damages for the cost to clean up the contamination, lost business, and diminution of the value of the storage property due to the contamination. Siligo prevailed at a summary adjudication hearing where the trial court ruled that Castellucci breached a consulting agreement and a stock put agreement and that the general release barred Castellucci's affirmative defense and cross-complaint unless the release was obtained by fraud. On this issue, Siligo prevailed before a jury. The jury found that Siligo falsely represented that the property was without contamination but that he did not know his statement was false nor did he recklessly make the statement without knowing whether it was true or false.
Castellucci's liability was $300,000 under the consulting agreement and $500,000 under the put agreement. The put agreement, however, provided that Siligo's sole remedy for default under that contract was to foreclose certain deeds of trust, including one against the contaminated property, and be limited to a remaining balance due of $300,000. The issues of judicial foreclosure and attorney fees were submitted to the trial court following the jury verdict.


*877 Attorney Fee Apportionment

Siligo sought $400,000 in attorney fees under clauses of the consulting and put agreements.[2] In proving up this amount Siligo submitted his attorneys' invoices. The invoices revealed that Siligo's attorneys separated the attorney fees into two categories: one for services rendered for the prosecution of the breach of contract action and one for services rendered for the defense of the fraud cross-complaint.[3]
(1) That Siligo's fees were capable of being divided in this manner motivated the trial court to make the same division in its award. It cited Stout v. Turney (1978) 22 Cal.3d 718 [150 Cal. Rptr. 637, 586 P.2d 1228] for the general proposition that a tort action for fraud arising out of a contract is not an action "on the contract" within the meaning of Civil Code section 1717.[4] It then reasoned: "If the causes of action are separate and the fees can be allocated then the prevailing party is only entitled to those fees related to the contract." In the judgment, the trial court awarded Siligo $80,000 for his attorney fees.
This reasoning is erroneous.
First, Civil Code section 1717 does not independently bar an award for attorney fees in a tort action. Code of Civil Procedure section 1021 states in pertinent part: "Except as attorney's fees are specifically provided for by statute, the measure and mode of compensation of attorneys ... is left to the agreement, express or implied, of the parties...." Under this statute "`[t]he parties to a contract may validly agree to allow for the award of attorney's fees, even though the suit is based on tort rather than *878 contract.' [Citations.]" (Lerner v. Ward (1993) 13 Cal. App.4th 155, 161 [16 Cal. Rptr.2d 486].)[5]
Second, California law is settled that an obligation to pay attorney fees incurred in the enforcement of a contract "includes attorneys' fees incurred in defending against a challenge to the underlying validity of the obligation." (Finalco, Inc. v. Roosevelt (1991) 235 Cal. App.3d 1301, 1308 [3 Cal. Rptr.2d 865].)
In Wagner v. Benson (1980) 101 Cal. App.3d 27 [161 Cal. Rptr. 516], the plaintiffs sued a bank for fraud and negligence in connection with a loan transaction, and the bank filed a cross-complaint to collect the balance due under the promissory notes signed in the transaction. The bank prevailed on the complaint and cross-complaint, but the trial court limited the bank's award of attorney fees to the fees incurred in suing on the promissory notes. The Court of Appeal reversed. It reasoned: "Here the parties have agreed to compensate the prevailing party for reasonable costs incurred in collecting the balance due on the notes. However, the Bank's collection efforts were interrelated with its defense against the [plaintiffs'] fraud allegations. Defense of the charge of fraud was necessary in the Bank's efforts to collect the notes [citations]." (Id. at p. 37.)
Similar is IMO Development Corp. v. Dow Corning Corp. (1982) 135 Cal. App.3d 451 [185 Cal. Rptr. 341]. There, the purchaser of real estate sued the seller for breach of contract and declaratory relief as to the enforceability of a waiver clause, and the seller cross-complained for recovery on a promissory note. The buyer filed an answer to the cross-complaint pleading an affirmative defense alleging that the waiver clause was unenforceable. The seller prevailed on the complaint and cross-complaint, but the trial court refused to award the seller his fees incurred in defending the declaratory relief action. The court reversed. It reasoned that the seller was required to defend the declaratory relief action in order to collect the note because the *879 declaratory relief claim was an affirmative defense to the seller's action on the note: "In our view, the cost of litigating the issue raised by [the buyer's waiver] defense constituted part of the cost of collection, and [the seller] should have been awarded attorney fees on that issue. The fact that the waiver issue was raised by the declaratory relief cause of action is of no legal significance. [The buyer] argued to the trial court that it was not necessary for [the seller] to attempt to enforce the waiver provision of the sales agreement in order to collect the note. The short answer to such contention is that [the seller] was required to litigate the enforceability of [the buyer's] waiver because [the buyer] alleged the invalidity of that waiver as an affirmative defense to the cross-complaint. Both causes of action were inextricably intertwined, as were the documents from which they arose." (Id. at p. 463; see also Hughes Tool Co. v. Max Hinrichs Seed Co. (1980) 112 Cal. App.3d 194, 203 [169 Cal. Rptr. 160] ["Here, the complaint and cross-complaint refer to integral parts of the same transaction, which includes an authorization for attorneys' fees. Although [the] cross-complaint largely sounds in tort, the practical effect of the success of its claim is the defeat of [the] effort to collect on the note. Hence an award of attorneys' fees ... is based on [a] defense to the action on the note."]; Finalco, Inc. v. Roosevelt, supra, 235 Cal. App.3d at p. 1307 ["Finalco's defense to Roosevelt's action under the federal securities laws was not `incidental' to the prosecution of its cross-complaint to recover on the note. Roosevelt sought to rescind the purchase of the units on the basis of Finalco's alleged violation of federal securities laws. Not only was Finalco obliged to file a complaint to recover on the note, it was obliged to defend against Roosevelt's allegations of securities fraud in order to succeed on its complaint."].)
Thus, the pivotal point in the analysis whether a prevailing party is entitled to recover contractual attorney fees for defending against a competing noncontractual claim (when the language of the agreement does not encompass noncontractual claims or is ambiguous) is not whether the fees can be apportioned between the theories but whether a defense against the noncontractual claim is necessary to succeed on the contractual claim.
Here, Castellucci argues that his fraud cross-complaint did not seek rescission or otherwise attack enforceability of the consulting and put agreements. The cross-complaint sought, so the argument goes, only monetary damages independent of the validity of the underlying obligations.
In our view, Castellucci's argument is superficial.
Castellucci defended against Siligo's action to enforce the consulting and put agreements by alleging fraud and filed a cross-complaint alleging the *880 same fraud. The trial court ruled in the summary adjudication order that Siligo was entitled to prevail in the absence of fraud. Siligo was required to defend against fraud in order to succeed on his complaint to enforce the agreements. The practical success of Siligo's defense was the enforceability of the agreements. The cost of litigating the issue raised by Castellucci therefore constituted part of the cost of enforcing the contracts. The trial court therefore erred in apportioning its award of attorney fees between the offensive and defensive aspects of this case.

Attorney Fees Application to the Deficiency Limitation
The put agreement gave Siligo the right to require Castellucci to purchase his shares of SVOCO, Inc., for $720,000 payable over time. The agreement recited that Castellucci's obligation was secured by interests in three deeds of trust conveyed to Siligo. It further provided: "In the event of default the entire remaining balance shall become due and payable if said default is not curred [sic] within 10 business days of receipt of notice of default. Siligo hereby agrees that his sole remedy in the event of default shall be: [¶] A. To foreclose under the deeds of trust; [¶] B. After foreclosure and giving credit to ... Castellucci for the full market value of said property (less precedent debt) to collect from ... Castellucci the remaining balance due up to, but not more than, the sum of $300,000.00. Should the remaining balance due (after credits applied) exceed the sum of $300,000.00, Siligo shall and hereby does waive any right to collect from ... Castellucci any such sums in excess of $300,000.00."
The judgment allocated one-half of the attorney fees awarded as due under the consulting agreement and one-half as due under the put agreement. It also ordered that the fees due under the put agreement are inclusive of the $300,000 deficiency limitation.[6]
(2) "Preliminarily we note that in reviewing a trial court's interpretation of a written instrument where no conflicting extrinsic evidence is received, an appellate court is not bound by the lower court's ruling but must give the writing its own independent interpretation." (Wallis v. Farmers Group, Inc. (1990) 220 Cal. App.3d 718, 729 [269 Cal. Rptr. 299].)
We also note the following principles of law. "A contract must be so interpreted as to give effect to the mutual intention of the parties as it existed *881 at the time of contracting, so far as the same is ascertainable and lawful." (Civ. Code, § 1636.) "The language of a contract is to govern its interpretation, if the language is clear and explicit, and does not involve an absurdity." (Civ. Code, § 1638.) "When a contract is reduced to writing, the intention of the parties is to be ascertained from the writing alone, if possible; subject, however, to the other provisions of this Title." (Civ. Code, § 1639.) "The whole of a contract is to be taken together, so as to give effect to every part, if reasonably practicable, each clause helping to interpret the other." (Civ. Code, § 1641.) "A contract must receive such an interpretation as will make it lawful, operative, definite, reasonable, and capable of being carried into effect, if it can be done without violating the intention of the parties." (Civ. Code, § 1643.) "The words of a contract are to be understood in their ordinary and popular sense, rather than according to their strict legal meaning; unless used by the parties in a technical sense, or unless a special meaning is given to them by usage, in which case the latter must be followed." (Civ. Code, § 1644.) "However broad may be the terms of a contract, it extends only to those things concerning which it appears that the parties intended to contract." (Civ. Code, § 1648.) "Repugnancy in a contract must be reconciled, if possible, by such an interpretation as will give some effect to the repugnant clauses, subordinate to the general intent and purpose of the whole contract." (Civ. Code, § 1652.) "Stipulations which are necessary to make a contract reasonable, or conformable to usage, are implied, in respect to matters concerning which the contract manifests no contrary intention." (Civ. Code, § 1655.)
(3) Here, the deficiency limitation clause states that after default the "entire remaining balance" is due and after foreclosure Siligo can collect from Castellucci "the remaining balance due up to, but not more than, the sum of $300,000.00." It also states that Siligo "does waive any right to collect from ... Castellucci any such sums in excess of $300,000.00." (Italics added.)
Thus, the clause applies to the "entire remaining balance" due on default and "the remaining balance due" after foreclosure. The clause is ambiguous, however, because it fails to define these terms.
Siligo argues that the terms refer to the amount due under the stock purchase price. Castellucci counters by claiming that the judgment, which includes attorney fees, preceded foreclosure and thus set the remaining balance due.
We agree with Siligo.
First, what ultimately resulted in this case, i.e., a judgment liquidating Castellucci's debt including attorney fees, sheds no light on what the parties meant when they contracted about the "remaining balance."
*882 Second, the deficiency limitation clause first uses "remaining balance" in its ordinary and popular sense, i.e., the principal amount due under a contract after a default and before litigation. It then uses the term in connection with a foreclosure without specifying that "remaining balance" has a special meaning that includes litigation expenses, which are expenses ordinarily supplemental to the relief underlying litigation.
Third, the attorney fee clause, in contrast to the deficiency limitation clause, singles out litigation expenses for special treatment. It therefore appears that when the parties intended to contract about litigation expenses they specifically said so.
Fourth, the attorney fee clause allows a fee award "in addition to any other relief which may be granted." The ordinary meaning of these words is simply that if litigation results and relief is granted an award of attorney fees is supplemental to the underlying contractual relief.
Fifth, the purpose of the attorney fee clause would be frustrated by Castellucci's interpretation. The clause would never operate to give Siligo the contemplated supplemental benefits unless Castellucci's deficiency liability fell below $300,000. Although there is nothing inherently wrong with a specific contractual provision that leads to this result, an interpretation that leads to this result tends to nullify rather than give effect to the attorney fee clause.
In short, at the time the parties contracted they first used the term "remaining balance" in reference to the principal amount due under the contract upon default; they knew how to provide for litigation expenses and they did not when they talked of the "remaining balance"; the attorney fee clause provided for litigation and allows for relief in addition to contractual relief; and, an interpretation excluding the fees from the deficiency limitation clause tends to give effect instead of nullify the import of the attorney fee clause.
We therefore conclude that the trial court erred in applying the put agreement attorney fees to the deficiency limitation clause.

Deficiency Judgment Credit
The judgment ordered foreclosure of the deeds of trust securing the put agreement. It also retained jurisdiction to determine the amount of any *883 deficiency and render a money judgment against Castellucci for any such deficiency up to $300,000.[7]
Siligo complains about the trial court's remarks made in a minute order: "Foreclosure is equitable in nature. The evidence presented establishes that Siligo knew or should have known that there was contamination at the Salinas plant but that his failure to disclose this was not fraudulent. The jury's verdict was appropriate. However, this is not to say Siligo was without fault. He was negligent in not informing Castellucci of the contamination problems with the City and when the pit was dug even if he thought they were not as serious as they were later determined to be. It was his operation of the plant that either caused or contributed to the contamination; no fault is attributable to Castellucci. Knowing this, Siligo accepted the property as security in the condition which it existed, and which he knew or should have known it existed, at the time the release was executed. As a result the risk of any impairment of the security or dimunition [sic] of the value of the property as a result of the contamination should fall on Siligo, not Castellucci."
Siligo argues that the trial court's plan to credit Castellucci with the market value of the property as if it were uncontaminated is inconsistent with the release and the theory of trial which assertedly did not involve negligence.
We decline to review this issue because there has been no final judgment on the deficiency judgment aspects of this case. (Code Civ. Proc., §§ 904.1 [generally, an appeal is from a judgment], 577 [judgment is the final determination of the rights of the parties].) The amount of any deficiency judgment is an issue to be adjudicated after the foreclosure sale upon proper application by Siligo. (Ante, fn. 7.) The trial court's announced intention implicates how it intends to sort out the evidence at the deficiency judgment hearing and is obviously not "dispositive and... the trial court's last word on the subject...." (Nimmagadda v. Krishnamurthy (1992) 3 Cal. App.4th 1505, 1509 [5 Cal. Rptr.2d 351].)
The judgment and order of sale is reversed and the matter is remanded. The trial court is directed to enter an amended judgment which additionally awards Siligo reasonable attorney fees for the defensive aspects of this case and provides that the awards for attorney fees are supplemental to the *884 underlying contractual relief awarded Siligo. The trial court is also directed to award Siligo reasonable attorney fees for this appeal. Siligo is awarded costs on appeal.
Premo, Acting P.J., and Wunderlich, J., concurred.
A petition for a rehearing was denied February 15, 1994, and respondents' petition for review by the Supreme Court was denied May 12, 1994.
NOTES
[1]  The plaintiffs in this case are Donald and Susan Siligo and Salinas Valley Oil Company, a California corporation. The defendants are John Castellucci, SVOCO, Inc., and Sulphur Mountain Oil Company, a California limited partnership. For convenience we sometimes refer to the litigants and their positions in terms of "Siligo" and "Castellucci" although one or more of the affiliated business entities may be the actual party benefited or burdened. Also for convenience we approximate the amounts of money sought, owing, and awarded since precise figures are unnecessary to our analyses.
[2]  The clause in the consulting agreement states: "If any action at law or in equity is necessary to enforce or interpret the terms of this Consulting Agreement, the prevailing party shall be entitled to reasonable attorneys' fees, costs and necessary disbursements in addition to any other relief to which such party may be entitled." The clause in the put agreement states: "If legal action is instituted to interpret or enforce this Agreement, the prevailing party shall be entitled to recover reasonable attorneys' fees and costs in addition to any other relief which may be granted."
[3]  Siligo was insured for Castellucci's fraud claims, and the itemization of the defense fees was used to obtain reimbursement from the insurance company.
[4]  Civil Code section 1717 states in pertinent part: "(a) In any action on a contract, where the contract specifically provides that attorney's fees and costs, which are incurred to enforce that contract, shall be awarded either to one of the parties or to the prevailing party, then the party who is determined to be the party prevailing on the contract, whether he or she is the party specified in the contract or not, shall be entitled to reasonable attorney's fees in addition to other costs."
[5]  Here, the consulting agreement allows attorney fees "[i]n any action or proceeding arising out of this Agreement." This language is clearly sufficient to encompass Castellucci's fraud action. (Xuereb v. Marcus & Millichap, Inc. (1992) 3 Cal. App.4th 1338, 1342-1343 [5 Cal. Rptr.2d 154] [clause allowing fees in any lawsuit or other legal proceeding to which the agreement gives rise broad enough to encompass both contract and tort actions]; Lerner v. Ward, supra, 13 Cal. App.4th at pp. 159-161 [clause allowing fees in any action or proceeding arising out of the agreement broad enough to include fraud action arising out of the agreement].) The put agreement is more problematic in allowing attorney fees "[i]f legal action is instituted to interpret or enforce this Agreement." This language requires an analysis whether Castellucci's fraud action can properly be considered as an action to "interpret or enforce" the put agreement. Our analysis whether Siligo's defense of Castellucci's cross-complaint constituted resistance to a challenge to the underlying contractual obligation necessarily addresses this question.
[6]  This fact is not clear from the face of the judgment, but the parties refer to the trial court's minute order granting Siligo's motion for attorney fees as an interpretive aid and agree that the judgment contemplates that the award for attorney fees attributable to the put agreement is subject to the deficiency limitation.
[7]  A judgment of foreclosure must either state that there shall be no judgment for a deficiency or name the defendants against whom a deficiency judgment may be ordered. If a deficiency judgment is available, the plaintiff must file an application for a deficiency judgment within three months of the date of the foreclosure sale and present evidence at a hearing. (Code Civ. Proc., § 726, subd. (a).)
