Berry phase and adiabaticity of a spin diffusing in a nonuniform magnetic field