BMW has patched a security flaw that left 2.2 million cars, including Rolls Royce and Mini models, open to hackers.