All of lore.kernel.org
 help / color / mirror / Atom feed
From: mhornung.linux@gmail.com (mhornung.linux at gmail.com)
To: kernelnewbies@lists.kernelnewbies.org
Subject: drivers: staging: most: Locking question
Date: Mon, 18 Jul 2016 20:14:47 +0200	[thread overview]
Message-ID: <20160718181446.GA1650@googlemail.com> (raw)

Hello,

I have some questions about the locking techniques used inside
file drivers/staging/most/hdm-usb/hdm_usb.c.

The one and only call to function free_anchored_buffers is locked by a Mutex:

----------------------------------------------------------------------------
    	...
        mutex_lock(&mdev->io_mutex);
	free_anchored_buffers(mdev, channel);
	if (mdev->padding_active[channel])
		mdev->padding_active[channel] = false;

        if (mdev->conf[channel].data_type == MOST_CH_ASYNC) {
	        del_timer_sync(&mdev->link_stat_timer);
		cancel_work_sync(&mdev->poll_work_obj);
	}
	mutex_unlock(&mdev->io_mutex);
	...						
----------------------------------------------------------------------------

Then, inside function free_anchored_buffers, they use a (from my point of view)
somewhat complex spinlock variant:

----------------------------------------------------------------------------
static void free_anchored_buffers(struct most_dev *mdev, unsigned int channel)
{
	struct mbo *mbo;
	struct buf_anchor *anchor, *tmp;
	unsigned long flags;

	spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
	list_for_each_entry_safe(anchor, tmp, &mdev->anchor_list[channel],
				 list) {
		struct urb *urb = anchor->urb;

		spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
		if (likely(urb)) {
			mbo = urb->context;
			if (!irqs_disabled()) {
				usb_kill_urb(urb);
			} else {
				usb_unlink_urb(urb);
				wait_for_completion(&anchor->urb_compl);
			}
			if ((mbo) && (mbo->complete)) {
				mbo->status = MBO_E_CLOSE;
				mbo->processed_length = 0;
				mbo->complete(mbo);
			}
			usb_free_urb(urb);
		}
		spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
		list_del(&anchor->list);
		cancel_work_sync(&anchor->clear_work_obj);
		kfree(anchor);
	}
	spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
}
----------------------------------------------------------------------------

To my questions:

#1: What is the intention of locking a whole function with a Mutex and then
    using spinlocks inside the function? Wouldn't it be sufficient to use
    one locking technique?
#2: Why is the spinlock not just locking the whole list_for_each_entry part or
    just the list_del(&anchor->list)?


Thank you very much in advance.

With best regards

Michael

             reply	other threads:[~2016-07-18 18:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-18 18:14 mhornung.linux at gmail.com [this message]
2016-07-18 20:54 ` drivers: staging: most: Locking question Greg KH

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=20160718181446.GA1650@googlemail.com \
    --to=mhornung.linux@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.