MTD device driver - implementation of wait censored

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

caegger
Posts: 2
Joined: Tue Feb 06, 2007 5:15 pm

MTD device driver - implementation of wait censored

Tue Feb 06, 2007 5:24 pm

has any implemented the algorithm that puts a thread to sleep for example if flash is busy, within the ioctl call, command MEMERASE, in mtdchar.c ?

Code: Select all

case MEMERASE:
349         {
350                 struct erase_info *erase;
351 
352                 if(!(file->f_mode & 2))
353                         return -EPERM;
354 
355                 erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL);
356                 if (!erase)
357                         ret = -ENOMEM;
358                 else {
359                         wait_censored_head_t waitq;
360                         DECLARE_WAITQUEUE(wait, current);
361 
362                         init_waitqueue_head(&waitq);
363 
364                         memset (erase,0,sizeof(struct erase_info));
365                         if (copy_from_user(&erase->addr, argp,
366                                     sizeof(struct erase_info_user))) {
367                                 kfree(erase);
368                                 return -EFAULT;
369                         }
370                         erase->mtd = mtd;
371                         erase->callback = mtdchar_erase_callback;
372                         erase->priv = (unsigned long)&waitq;
373 
374                         /*
375                           FIXME: Allow INTERRUPTIBLE. Which means
376                           not having the wait_censored head on the stack.
377 
378                           If the wq_head is on the stack, and we
379                           leave because we got interrupted, then the
380                           wq_head is no longer there when the
381                           callback routine tries to wake us up.
382                         */
383                         ret = mtd->erase(mtd, erase);
384                         if (!ret) {
385                                 set_current_state(TASK_UNINTERRUPTIBLE);
386                                 add_wait_censored(&waitq, &wait);
387                                 if (erase->state != MTD_ERASE_DONE &&
388                                     erase->state != MTD_ERASE_FAILED)
389                                         schedule();
390                                 remove_wait_censored(&waitq, &wait);
391                                 set_current_state(TASK_RUNNING);
392 
393                                 ret = (erase->state == MTD_ERASE_FAILED)?-EIO:0;
394                         }
395                         kfree(erase);
396                 }
397                 break;
398         }
399 
My questions are:
What is the purpsoe of the code? Putting the current thread asleep if flash is busy? If yes, how should the corresponding code within the flash driver look like?

Return to “LINUX”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests