linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ohad Ben-Cohen <ohad@wizery.com>
To: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Cc: linux-omap@vger.kernel.org, h-kanigeri2@ti.com
Subject: Re: [PATCH 4/4] omap: mailbox: convert block api to kfifo
Date: Wed, 28 Apr 2010 14:25:41 +0300	[thread overview]
Message-ID: <g2wda15981b1004280425nd095bccelc5ca7d695d9e19b1@mail.gmail.com> (raw)
In-Reply-To: <20100428.141620.59684829.Hiroshi.DOYU@nokia.com>

On Wed, Apr 28, 2010 at 2:16 PM, Hiroshi DOYU <Hiroshi.DOYU@nokia.com> wrote:
> From: ext Ohad Ben-Cohen <ohad@wizery.com>
> Subject: Re: [PATCH 4/4] omap: mailbox: convert block api to kfifo
> Date: Wed, 28 Apr 2010 13:02:06 +0200
>
>>>> diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c
>>>> index 72b17ad..b1324f3 100644
>>>> --- a/arch/arm/plat-omap/mailbox.c
>>>> +++ b/arch/arm/plat-omap/mailbox.c
>>>> @@ -26,6 +26,7 @@
>>>>  #include <linux/device.h>
>>>>  #include <linux/delay.h>
>>>>  #include <linux/slab.h>
>>>> +#include <linux/kfifo.h>
>>>>
>>>>  #include <plat/mailbox.h>
>>>>
>>>> @@ -67,7 +68,7 @@ static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
>>>>  /*
>>>>   * message sender
>>>>   */
>>>> -static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
>>>> +static int __mbox_poll_for_space(struct omap_mbox *mbox)
>>>>  {
>>>>       int ret = 0, i = 1000;
>>>>
>>>> @@ -78,49 +79,54 @@ static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
>>>>                       return -1;
>>>>               udelay(1);
>>>>       }
>>>> -     mbox_fifo_write(mbox, msg);
>>>>       return ret;
>>>>  }
>>>>
>>>> -
>>>>  int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
>>>>  {
>>>> +     struct omap_mbox_queue *mq = mbox->txq;
>>>> +     int ret = 0, len;
>>>>
>>>> -     struct request *rq;
>>>> -     struct request_queue *q = mbox->txq->queue;
>>>> +     spin_lock(&mq->lock);
>>>>
>>>> -     rq = blk_get_request(q, WRITE, GFP_ATOMIC);
>>>> -     if (unlikely(!rq))
>>>> -             return -ENOMEM;
>>>> +     if (kfifo_avail(&mq->fifo) < sizeof(msg)) {
>>>> +             ret = -ENOMEM;
>>>> +             goto out;
>>>> +     }
>>>> +
>>>> +     len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
>>>> +     if (unlikely(len != sizeof(msg))) {
>>>> +             pr_err("%s: kfifo_in anomaly\n", __func__);
>>>> +             ret = -ENOMEM;
>>>> +     }
>>>>
>>>> -     blk_insert_request(q, rq, 0, (void *) msg);
>>>>       tasklet_schedule(&mbox->txq->tasklet);
>>>>
>>>> -     return 0;
>>>> +out:
>>>> +     spin_unlock(&mq->lock);
>>>> +     return ret;
>>>>  }
>>>>  EXPORT_SYMBOL(omap_mbox_msg_send);
>>>>
>>>>  static void mbox_tx_tasklet(unsigned long tx_data)
>>>>  {
>>>> -     int ret;
>>>> -     struct request *rq;
>>>>       struct omap_mbox *mbox = (struct omap_mbox *)tx_data;
>>>> -     struct request_queue *q = mbox->txq->queue;
>>>> -
>>>> -     while (1) {
>>>> -
>>>> -             rq = blk_fetch_request(q);
>>>> -
>>>> -             if (!rq)
>>>> -                     break;
>>>> +     struct omap_mbox_queue *mq = mbox->txq;
>>>> +     mbox_msg_t msg;
>>>> +     int ret;
>>>>
>>>> -             ret = __mbox_msg_send(mbox, (mbox_msg_t)rq->special);
>>>> -             if (ret) {
>>>> +     while (kfifo_len(&mq->fifo)) {
>>>> +             if (__mbox_poll_for_space(mbox)) {
>>>>                       omap_mbox_enable_irq(mbox, IRQ_TX);
>>>> -                     blk_requeue_request(q, rq);
>>>> -                     return;
>>>> +                     break;
>>>>               }
>>>> -             blk_end_request_all(rq, 0);
>>>> +
>>>> +             ret = kfifo_out(&mq->fifo, (unsigned char *)&msg,
>>>> +                                                             sizeof(msg));
>>>> +             if (unlikely(ret != sizeof(msg)))
>>>> +                     pr_err("%s: kfifo_out anomaly\n", __func__);
>>>
>>> No error recovery? same for other anomalies.
>>
>> I thought about it too, but eventually I think it doesn't really make
>> a lot of sense:
>> The only reason that kfifo_out/kfifo_in can fail here is if there's
>> not enough data/space (respectively).
>> Since we are checking for the availability of data/space before calling
>> kfifo_out/kfifo_in, it cannot really fail.
>> If it does fail, that's a critical bug that we cannot really recover from.
>> Only reasonable explanation can be a bug in the code (either ours or kfifo's),
>> and with such a bug it really feels futile to put some recovery.
>> So maybe we should really make this a WARN_ON.
>> What do you think ?
>
> Makes sense. What about BUG_ON if it shouldn't happen theoretically?

I'm not sure this bug is critical enough to panic and enforce the user
to reboot immediately - he can probably still do a clean shutdown here.

Thanks,
Ohad.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2010-04-28 11:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-27 17:56 [PATCH 0/4] omap: mailbox: cleanup & simplify Ohad Ben-Cohen
2010-04-27 17:56 ` [PATCH 1/4] omap: mailbox cleanup: convert rwlocks to spinlock Ohad Ben-Cohen
2010-04-28  7:50   ` Hiroshi DOYU
2010-04-28 10:41     ` Ohad Ben-Cohen
2010-04-29 12:44   ` Kanigeri, Hari
2010-04-29 13:14     ` Ohad Ben-Cohen
2010-04-29 13:35       ` Ohad Ben-Cohen
2010-04-27 17:56 ` [PATCH 2/4] omap: mailbox cleanup: split MODULE_AUTHOR line Ohad Ben-Cohen
2010-04-27 17:56 ` [PATCH 3/4] omap: mailbox: fix reverse likeliness Ohad Ben-Cohen
2010-04-27 17:56 ` [PATCH 4/4] omap: mailbox: convert block api to kfifo Ohad Ben-Cohen
2010-04-28  5:52   ` Hiroshi DOYU
2010-04-28 11:02     ` Ohad Ben-Cohen
2010-04-28 11:16       ` Hiroshi DOYU
2010-04-28 11:25         ` Ohad Ben-Cohen [this message]
2010-04-28 11:52           ` Hiroshi DOYU
2010-04-28 12:03             ` Ohad Ben-Cohen
2010-04-28  5:56   ` Hiroshi DOYU
2010-04-28 11:02     ` Ohad Ben-Cohen
  -- strict thread matches above, loose matches on Subject: below --
2010-05-03  9:41 [PATCH v2 " Ohad Ben-Cohen
2010-05-03 10:27 ` [PATCH " Ohad Ben-Cohen
2010-05-10  9:16 [PATCH 1/4] omap: mailbox: convert rwlocks to spinlock Hiroshi DOYU
2010-05-10  9:16 ` [PATCH 4/4] omap: mailbox: convert block api to kfifo Hiroshi DOYU

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=g2wda15981b1004280425nd095bccelc5ca7d695d9e19b1@mail.gmail.com \
    --to=ohad@wizery.com \
    --cc=Hiroshi.DOYU@nokia.com \
    --cc=h-kanigeri2@ti.com \
    --cc=linux-omap@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).