How do I get this FromToRotation code to work properly?

My code has a custom variable called gravity. The player is supposed to align with this gravity so that the players -transform.up == gravity.normalized. Instead the player object spins around like crazy.

if (-transform.up != gravity.normalized) {
    transform.rotation *= Quaternion.FromToRotation(-transform.up, gravity.normalized);
    Debug.Log(-transform.up); //should print gravity.normalized but does not
}

(Note: the player is not guaranteed to be upright, the rotation changes throughout the game. so maybe theres an issue with global vs local rotation that i don’t understand…?)

The solution was to change to order. Less pretty this way but more functional. Thanks to Hellium for pointing this out.

transform.rotation = Quaternion.FromToRotation(-transform.up, gravity) * transform.rotation;