It is possible that Gandalf was in physical pain throughout LOTR and the Hobbit. Since the closet things to a pain killers back then were herbs and Pipeweed, the pain probably made Gandalf cranky on more than one occasion. (especially after the incident with Saruman.) Of course, its entirely debatable on whether or not this pain was the
real reason he used his staff to walk around with.