I am not sure there is a clear answer. Grammatically, I think the Greek could be teased either way given how loose word order can be. In any case, both senses seem to have been understood in antiquity by those commenting on these verses in Greek.
Athanasius (4th c.), for example, wrote in his critique of the Councils of Ariminum and Seleucia:
Now, if certain others made excuses of the expressions of the Council, it might perhaps have been set down, either to ignorance or to caution. There is no question, for instance, about George of Cappadocia, who was expelled from Alexandria; a man, without character in years past, nor a Christian in any respect; but only pretending to the name to suit the times, and thinking religion to be a means of gain (III.37)
This would support the argument for the "godliness is gain" interpretation. Origen (2d/3d c.) seems to have held a similar interpretation, in the context of Corban (Mark 7:11):
And the Gospel testifies to their love of money, saying, But the
Pharisees who were lovers of money heard these things and they scoffed
at Him [Luke 16:14]. If, then, any one of those who are called elders among us, or
of those who are in any way rulers of the people, profess to give to
the poor under the name of the commonweal, rather than to be of those
who give to their kindred if they should chance to be in need of the
necessaries of life, and those who give cannot do both, this man might
with justice be called a brother of those Pharisees who made void the
word of God through their own tradition, and were accused by the
Saviour as hypocrites. And as a very powerful deterrent to any one
from being anxious to take from the account of the poor, and from
thinking that the piety of others is a way of gain we have not
only these things, but also that which is recorded about the traitor
Judas, who in appearance championed the cause of the poor, and said
with indignation, This ointment might have been sold for three
hundred pence and given to the poor [Mark 14:5, John 12:5], but in reality was a thief, and
having the bag took away what was put therein [John 12:6] (Commentary on Matthew XI.9)
On the other hand, there are other writers in antiquity that seemed to have held the other interpretation - that Paul was writing of those who thought "gain is godliness". Malchion of Antioch (3rd c.), for example, wrote against Paul of Samosata:
After other matters again, they tell us in the following terms of what manner of life he was:—But there is no need of judging his actions when he was outside (the Church), when he revolted from the faith and turned aside to spurious and illegitimate doctrines. Nor need we say any thing of such matters as this, that, whereas he was formerly poor and beggarly, having neither inherited a single possession from his fathers, nor acquired any property by art or by any trade, he has now come to have excessive wealth by his deeds of iniquity and sacrilege, and by those means by which he despoils and concusses the brethren, casting the injured unfairly in their suit, and promising to help them for a price, yet deceiving them all the while and to their loss, taking advantage of the readiness of those in difficulties to give in order to get deliverance from what troubled them, and thus supposing that gain is godliness.
This seems also to have been John Chrysostom's (4th c. Byzantine Greek) understanding:
Destitute of the truth, thinking that gain is godliness. Observe what evils are produced by strifes of words. The love of gain,
ignorance, and pride; for pride is engendered by ignorance.
From such
withdraw thyself. He does not say, engage and contend with them, but
withdraw thyself, turn away from them; as elsewhere he says, A man
that is an heretic after the first and second admonition reject
[Tit 3:10]. He shows that they do not so much err from ignorance, as
they owe their ignorance to their indolence. Those who are contentious
for the sake of money you will never persuade. They are only to be
persuaded, so long as you give, and even so you will never satisfy
their desires. (Homily XVII on 1 Timothy)