I'm no expert in either kernel or C programming and I didn't test this patch, but it looks good to me.
Also, the resulting code is quite similar to the one Fedora is currently using - they accidentally fixed this bug in https://src.fedoraproject.org/rpms/kernel/c/5df4c5562f191b434edf57e8c92b176baad37cba. (Debian also seems to be affected: https://salsa.debian.org/kernel-team/linux/blob/4dcfa860/debian/patches/features/all/lockdown/0002-Add-a-SysRq-option-to-lift-kernel-lockdown.patch)
I'm no expert in either kernel or C programming and I didn't test this patch, but it looks good to me.
Also, the resulting code is quite similar to the one Fedora is currently using - they accidentally fixed this bug in https:/ /src.fedoraproj ect.org/ rpms/kernel/ c/5df4c5562f191 b434edf57e8c92b 176baad37cba. /salsa. debian. org/kernel- team/linux/ blob/4dcfa860/ debian/ patches/ features/ all/lockdown/ 0002-Add- a-SysRq- option- to-lift- kernel- lockdown. patch)
(Debian also seems to be affected: https:/