What about fixing the interface instead? For example if user_mask_ptr NULL, then sys_sched_{get,set}affinity return the bitmap size.
I will probably make it loop and double the buffer until EINVAL
ends or it passes a page and add a nasty comment.
I agree that a loop is needed. And yes someone didn't do a very
good job of designing this interface.