Backport the patch queued upstream for 5.16. The patch differs slightly from the upstream patch due to an upstream change that added a convenience function. Signed-off-by: Sander Vanheule <sander@svanheule.net>