LDD3
中提到驱动代码返回ERESTARTSYS
和EINTR
时如何选择:
Note the check on the return value of down_interruptible; if it returns nonzero, the operation was interrupted. The usual thing to do in this situation is to return -ERESTARTSYS。 Upon seeing this return code, the higher layers of the kernel will either restart the call from the beginning or return the error to the user. If you return -ERESTARTSYS , you must first undo any user-visible changes that might have been made, so that the right thing happens when the system call is retried. If you cannot undo things in this manner, you should return -EINTR instead.
即如果可以把用户看到的设备状态完全回滚到执行驱动代码之前,则返回ERESTARTSYS
,否则返回EINTR
。因为EINTR
错误可以使系统调用失败,并且返回错误码为EINTR
给应用程序。而ERESTARTSYS
有可能会让kernel
重新发起操作,而不会惊动应用程序。可以参考这篇帖子。