문제

In a Linux Kernel Module I am trying to change code that says:

down(&semaphore1);

down(&semaphore2);

   critical code here!

up(&semaphore2);

up(&semaphore1);

To use down_interruptible();

if(down_interruptible(&semaphore1))
   return -ERESTARTSYS;

if(down_interruptible(&semaphore2))
   return -ERESTARTSYS;

   critical code here!

up(&semaphore2);

up(&semaphore1);

Is this the correct way to switch from the "depricated" down to down_interruptible?

I don't understand what return -ERESTARTSYS; does, but to me it seems that it makes my kernel module exit and allow the kernel to do some other stuff until my kernel module is awaken again, is that it?

도움이 되었습니까?

해결책

All fine, except one: you must release semaphore1 before second return:

if(down_interruptible(&semaphore1))
   return -ERESTARTSYS;

if(down_interruptible(&semaphore2)) {
   up(&semaphore1);
   return -ERESTARTSYS;
}

   critical code here!

up(&semaphore2);

up(&semaphore1);

Description about usage ERESTARTSYS see the answer.

In general, down_interruptible could be interrupted by signal to userspace application. Returning ERESTARTSYS you tell the kernel to handle signal and to call driver again. Unless you release semaphore1 second call to driver would block on semaphore1.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top