/usr/src/kernel is very RHEL specific.
Agreed, which is why I put it at the end of the search list.
Would this break non-RHEL systems?
None that I am aware of. I don't know of any other systems using /usr/src/kernels/. If there were, and they were doing it in an incompatible way, of course we could make this search dependent on the distro configure is being run on. That just doesn't seem necessary at this point so the complexity seems unnecessary at this point also.
On a system we could also end up with variants like PAE or XEN so it can be even more complex.
I'm not sure this is very likely. /usr/src/kernels/ is at the end of the search list and so only applies to a system that doesn't actually have a kernel matching $(uname -r) installed and as such the /lib/modules/$(uname -r)/{source,build} links are missing. – hence the need to keep looking for some kernel source. I can't imagine a system that this would be true on other than a mock-style (i.e. chroot) build environment and in such an environment, you would only populate it with the kernel-devel of the kernel you are wishing to build for.
Maybe there are cases I am not thinking of?
On a test with symlinks deleted from /lib/modules to see what would happen this patch doesn't even work. I get the following failure:
It appears the current logic looks in /usr/src/linux first and if there is no such dir it doesn't even get as far as looking in /usr/src/kernels.
There isn't any /usr/src/linux in RHEL/Centos installs