When Doyle wrote most of the Holmes stories cocaine was a popular and novel new drug, it wasn't until later that it's risks became widely known. In one of his later stories, "The Adventure of the Missing Three-Quarter", Doyle portrays it as an addiction that Watson weaned him of, but is still concerned that his friend may fall back into.

"For years I had gradually weaned him from that drug-mania which had threatened once to check his remarkable career. Now I knew that under ordinary conditions he no longer craved for this artificial stimulus, but I was well aware that the fiend was not dead but sleeping, and I have known that the sleep was a light one and the waking near when in periods of idleness I have seen the drawn look upon Holmes’ ascetic face, and the brooding of his deep-set and inscrutable eyes. Therefore I blessed this Mr. Overton, whoever he might be, since he had come with his enigmatic message to break that dangerous calm which brought more peril to my friend than all the storms of his tempestuous life."

- https://en.wikisource.org/wiki/The_Return_of_Sherlock_Holmes...