Tidy up, cache return value of a function, and add an assertion;
shouldn't make any functional difference.

Approved by:	re (gjb)
Sponsored by:	FreeBSD Foundation