I am currently studying from Modern Physics for Scientists and Engineers by Taylor et al. They derive the DeBroglie relation $p=h/\lambda$ from setting mass $m=0$ in the energy-momentum relation $E^2=m^2c^4+p^2c^2$, resulting in $E=pc$, then $p=E/c$. This was originally done to show particle-wave duality for photons. However, later they apply $\lambda=h/p$ to find the wavelength of electron waves.
My question is how can this equation be used if electrons have mass? In fact in an example demonstrating the short wavelengths of electron waves, they give an energy $K$ and use the equation $\lambda=h/\sqrt{2mK}$. Is using the DeBroglie relation for matter waves pertinent or misleading?