The patents are usually at least nominally related to a product, and the allocation of engineering to product is very intentional. You're correct that there's some loss in that process, and lots of funny business/perverse incentives besides, but engineers aren't generally patenting totally random things.