Computer science researchers at Stanford University have done an analysis that Linux has far fewer bugs than commercial competitors.

Here’s the maths:

Commercial software has 20 – 30 bugs per 1,000 lines of code.
Linux Kernel has 0.17 bugs per 1,000 lines of code.

And most importantly, majority of the .17 bugs in the Linux kernel are already fixed.
Wired has an article:

Linux: Fewer Bugs Than Rivals