I guess this is only fine when it's obvious that that's what he was thinking or something?
Yes, I think that is right. I've seen that done plenty of times myself, and so long as it is clear that the character is thinking (as it is here), I think you're fine with it. If you find that you write something that is unclear or confusing without a tag or other identifier, you can add in a tag or italics or something, or rewrite so that it is clear enough not to require them.