Linux resource limit, can soft limit exceed hard limit?

  html5, question
while(f > oldlimit) {
 int decr_step = 16;
 limit.rlim_cur = f;
 limit.rlim_max = f;
 if (setrlimit(RLIMIT_NOFILE,&limit) !  = -1) break;
 setrlimit_error = errno;
 /* We failed to set file limit to 'f'. Try with a
 * smaller limit decrementing by a few FDs per iteration. */
 if (f < decr_step) break;
 f -= decr_step;

The Internet said that the soft limit cannot exceed the hard limit. Why not change the soft limit to the same size as the hard limit? What else is the above code (redis source code) trying?

I guess it was because Redis didn’t want to check if he had changed the permissions of rlim_max, so he tried it directly. If the soft limit is directly changed to be as large as the hard limit, then it is necessary to judge if maxfiles > rlim_max, you can change rlim_max to be large, and if not, set rlim_cur to rlim_max. There is still a race between the check and the setup.