LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Tilman Schmidt <tilman@imap.cc>
Cc: Karsten Keil <kkeil@suse.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	i4ldeveloper@listserv.isdn4linux.de,
	linux-serial@vger.kernel.org, Hansjoerg Lipp <hjlipp@web.de>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>, Greg KH <greg@kroah.com>
Subject: Re: [PATCH] drivers/isdn/gigaset: new M101 driver
Date: Sat, 3 Feb 2007 17:56:23 -0800	[thread overview]
Message-ID: <20070203175623.72a171a1.akpm@linux-foundation.org> (raw)
In-Reply-To: <45C537B9.7080704@imap.cc>

On Sun, 04 Feb 2007 02:32:41 +0100 Tilman Schmidt <tilman@imap.cc> wrote:

> >> +	spin_lock_irqsave(&cs->cmdlock, flags);
> >> +	cb = cs->cmdbuf;
> >> +	spin_unlock_irqrestore(&cs->cmdlock, flags);
> > 
> > It is doubtful if the locking here does anything useful.
> 
> It assures atomicity when reading the cs->cmdbuf pointer.

I think it's bogus.  If the quantity being copied here is more than 32-bits
then yes, a lock is appropriate.  But if it's a single word then it's
unlikely that the locking does anything useful.  Or there might be a bug
here.

> >> +	spin_lock_irqsave(&cs->cmdlock, flags);
> >> +	cb->prev = cs->lastcmdbuf;
> >> +	if (cs->lastcmdbuf)
> >> +		cs->lastcmdbuf->next = cb;
> >> +	else {
> >> +		cs->cmdbuf = cb;
> >> +		cs->curlen = len;
> >> +	}
> >> +	cs->cmdbytes += len;
> >> +	cs->lastcmdbuf = cb;
> >> +	spin_unlock_irqrestore(&cs->cmdlock, flags);
> > 
> > Would the use of list_heads simplify things here?
> 
> I don't think so. The operations in list.h do not keep track of
> the total byte count, and adding that in a race-free way appears
> non-trivial.

Maintaining a byte count isn't related to maintaining a list.

> >> +			down(&cs->hw.ser->dead_sem);
> > 
> > Does this actually use the semaphore's counting feature?  If not, can we
> > switch it to a mutex?
> 
> I stole that code from the PPP line discipline. It is to assure all
> other ldisc methods have completed before the close method proceeds.
> This doesn't look like a case for a mutex to me, but I'm open to
> suggestions if it's important to avoid a semaphore here.

If a sleeping lock is being used as a mutex, please use a mutex.  We prefer
that semaphores only be used in those situations where their counting
feature is being used.

Reasons: a) mutexes have better runtime debugging support and b) Ingo had
some plans to reimplement semaphores in an arch-neutral way and for some
reason reducing the number of callers would help that.  I forget what the
reason was, actually.

> >> +	tail = atomic_read(&inbuf->tail);
> >> +	head = atomic_read(&inbuf->head);
> >> +	gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
> >> +		head, tail, count);
> >> +
> >> +	if (head <= tail) {
> >> +		n = RBUFSIZE - tail;
> >> +		if (count >= n) {
> >> +			/* buffer wraparound */
> >> +			memcpy(inbuf->data + tail, buf, n);
> >> +			tail = 0;
> >> +			buf += n;
> >> +			count -= n;
> >> +		} else {
> >> +			memcpy(inbuf->data + tail, buf, count);
> >> +			tail += count;
> >> +			buf += count;
> >> +			count = 0;
> >> +		}
> >> +	}
> > 
> > Perhaps the (fairly revolting) circ_buf.h can be used for this stuff.
> 
> It probably could, but IMHO readability would suffer rather than improve.
> 

How about kernel/kfifo.c?


  reply	other threads:[~2007-02-04  1:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200702012112.l11LCOO4016557@lx1.pxnet.com>
2007-02-02  1:13 ` Andrew Morton
2007-02-03 16:09   ` Greg KH
2007-02-04  0:26     ` Tilman Schmidt
2007-02-12 18:47       ` Greg KH
2007-02-12 23:49         ` Tilman Schmidt
2007-02-04  1:32   ` Tilman Schmidt
2007-02-04  1:56     ` Andrew Morton [this message]
2007-02-05  1:42       ` Tilman Schmidt
2007-02-05  4:58         ` Andrew Morton
2007-02-05 12:29           ` Tilman Schmidt

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=20070203175623.72a171a1.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=hjlipp@web.de \
    --cc=i4ldeveloper@listserv.isdn4linux.de \
    --cc=kkeil@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=tilman@imap.cc \
    --subject='Re: [PATCH] drivers/isdn/gigaset: new M101 driver' \
    /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

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).