public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Arun MURTHY <arun.murthy@stericsson.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"alan@lxorguk.ukuu.org.uk" <alan@lxorguk.ukuu.org.uk>
Subject: Re: [PATCHv5 1/4] modem_shm: Add Modem Access Framework
Date: Wed, 17 Oct 2012 12:15:49 -0700	[thread overview]
Message-ID: <20121017191549.GA18374@kroah.com> (raw)
In-Reply-To: <F45880696056844FA6A73F415B568C695B9C5CECE3@EXDCVYMBSTM006.EQ1STM.local>

On Wed, Oct 17, 2012 at 10:00:10AM +0200, Arun MURTHY wrote:
> > On Mon, Oct 15, 2012 at 10:58:37AM +0530, Arun Murthy wrote:
> > 
> > I'm going to ignore your .c logic, as there are things in it that I don't think is
> > correct.  But it all comes down to your data structures, if you fix them, then
> > the .c logic will become correct:

You still aren't understanding what I am trying to say here.

So, one final try...

> > > +
> > > +#include <linux/device.h>
> > > +
> > > +struct clients {
> > > +	struct device *dev;
> > 
> > Why is this a pointer?  It should be embedded in the structure.
> 
> This is the pointer to the clients's device structure. There will be a
> single entity for a modem but multiple clients. Hence this struct is 
> specific for each client.

But each "client" should be a device, so embed it in the structure.

> > > +	atomic_t cnt;
> > 
> > Why is this needed at all?  And if it's needed, why is it an atomic?
> > (hint, your use of atomic_t really isn't correct at all in this patch, it's not doing
> > what you think it is doing...)
> 
> Basically the operation done by this, i.e modem access/release has a lot of
> affect on the clients. Since we are accesing some modem registers without
> this modem request it might lead to system freeze. Hence such cross over
> scenarios are considered and the counter is increased/decreased after the
> operation(modem access/release). And reading of these variable are done
> especially during system suspend, where decision is taken based on the value
> of the counter read, hence any modification done should preside over read.
> Moreover since there are multiple clients, using atomic for a simple locking
> mechanism.

Hint, if you _ever_ say, "I'll use an atomic_t as a simple lock", you
are usually wrong.  But sometimes it can be done right.  So I went and
re-read your implementation.

You got it wrong.

So don't do this.

Seriously, an atomic value is not a lock, and, as you used it, it
doesn't even work properly.  So don't try to roll your own lock, either
use a lock, or use the built-in-reference-counting of the driver core,
which is what I keep saying here.

I'll say it again, don't do this.  Use the build-in reference count of
the struct device, that the kernel can manage for you, to handle this.
It will do it correctly, simply, and make your life a whole lot easier,
and better yet, will allow me to accept this code.

As it is, it is broken and wrong and quite buggy.

Please use the driver core properly.  I know it can be difficult, and
isn't the best documented body of code.  But it works, and works well,
and when people try to work around it thinking they don't need it, or
will just roll their own logic instead, they get it wrong and it causes
problems.  Just like this implementation shows.

So please, go back, consult with others on your team about how to do
this right.

If you have specific questions about the driver core that I can answer,
after you have read a few users of it (look at the bus code from
something "simple" for how to do this, don't look at USB) I will be glad
to help out.  But I feel that the previous review comments I have made
in this area, have been totally ignored, so I'm loath to try to do the
design work for you here.  You need to work it out so you feel
comfortable with it, not me.

good luck,

greg k-h

p.s. I'm sure your company/team/coworkers can help review your patches,
right?  Please run them by someone else first, that would have caught
the locking/atomic_t issue immediately.

  reply	other threads:[~2012-10-17 19:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-15  5:28 [PATCHv5 0/4] modem_shm: U8500 SHaRed Memory driver(SHRM) Arun Murthy
2012-10-15  5:28 ` [PATCHv5 1/4] modem_shm: Add Modem Access Framework Arun Murthy
2012-10-15 21:29   ` Greg KH
2012-10-17  8:00     ` Arun MURTHY
2012-10-17 19:15       ` Greg KH [this message]
2012-10-15  5:28 ` [PATCHv5 2/4] modem_shm: Register u8500 client for MAF Arun Murthy
2012-10-15  5:28 ` [PATCHv5 3/4] modem_shm: u8500-shm: U8500 Shared Memory Driver Arun Murthy
2012-10-15  5:28 ` [PATCHv5 4/4] Doc: Add u8500_shrm document Arun Murthy

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=20121017191549.GA18374@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arun.murthy@stericsson.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@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