public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Carlos Chinea <carlos.chinea@nokia.com>
To: ext Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
	Andras Domokos <andras.domokos@nokia.com>
Subject: Re: [RFC PATCHv4 4/7] HSI: hsi_char: Add HSI char device driver
Date: Tue, 14 Dec 2010 19:24:28 +0200	[thread overview]
Message-ID: <1292347468.2529.220.camel@groo> (raw)
In-Reply-To: <20101214115600.62388d5d@lxorguk.ukuu.org.uk>

On Tue, 2010-12-14 at 11:56 +0000, ext Alan Cox wrote:
> > +#define HSI_CHST_RD(c)		((c)->state & HSI_CHST_RD_MASK)
> > +#define HSI_CHST_WR(c)		((c)->state & HSI_CHST_WR_MASK)
> > +
> > +#define HSI_CHST_OC_SET(c, v) \
> > +	do { \
> > +		(c)->state &= ~HSI_CHST_OC_MASK; \
> > +		(c)->state |= v; \
> > +	} while (0);
> > +
> > +#define HSI_CHST_RD_SET(c, v) \
> > +	do { \
> > +		(c)->state &= ~HSI_CHST_RD_MASK; \
> > +		(c)->state |= v; \
> > +	} while (0);
> > +
> > +#define HSI_CHST_WR_SET(c, v) \
> > +	do { \
> > +		(c)->state &= ~HSI_CHST_WR_MASK; \
> > +		(c)->state |= v; \
> > +	} while (0);
> 
> 
> These sort of macros just hide detail - eg the lack of internal locking,
> which can lead to problems later, plus they reference their arguments
> multiple times so may have weird side effects.
> 
> They should probably be inline functions so they at least type check and
> behave sanely, and their locking rules defintiely need documenting

Agree. We would change that.

> 
> 
> 
> > +static long hsi_char_ioctl(struct file *file, unsigned int cmd,
> > +							unsigned long arg)
> > +{
> > +	struct hsi_char_channel *channel = file->private_data;
> > +	unsigned int state;
> > +	struct hsi_config cfg;
> > +	struct hsc_rx_config rx_cfg;
> > +	struct hsc_tx_config tx_cfg;
> > +	long ret = 0;
> > +
> > +	if (HSI_CHST_OC(channel) != HSI_CHST_OPENED)
> > +		return -ENODEV;
> 
> -EIO is the traditional response in this case if the channel has been
> closed by the other end - ENODEV indicates there is no physical device
> present - not sure which is right here from the code.
> 

The initial idea of this code was to guard against underneath removal of
the device. That was the reason for the -ENODEV.

Now after, rechecking the code I think that we need also to lock the
device to avoid that the removal happening in the middle of the
function.

> 
> > +		} else if ((state == HSC_PM_ENABLE)
> > +				&& (channel->wlrefcnt > 0)) {
> > +			ret = hsi_stop_tx(channel->cl);
> > +			if (!ret)
> > +				channel->wlrefcnt--;
> 
> What locks this lot against races (ditto some of the other ioctl code)

Right. We will fix this also.

> 
> > +	refcnt = atomic_inc_return(&cl_data->refcnt);
> > +	if (refcnt == 1) {
> 
> You seem to construct a lot of clever stuff using atomic_inc_return and
> friends where it looks like test_and_set_bit - or even a mutex over
> open/close would be far easier to understand ?

Yep a mutex will be a better option here. It would also take care of the
next comment.

> 
> > +	ret = hsi_char_msgs_alloc(channel);
> > +
> > +	if (ret < 0) {
> > +		refcnt = atomic_dec_return(&cl_data->refcnt);
> > +		if (!refcnt)
> > +			hsi_release_port(channel->cl);
> > +		spin_lock_bh(&channel->lock);
> > +		HSI_CHST_OC_SET(channel, HSI_CHST_CLOSED);
> > +		goto out;
> > +	}
> > +	if (refcnt == 1)
> > +		cl_data->attached = 1;
> 
> What happens here if a second open passes the first, the attached will
> stay zero and other stuff will be in strange states but the open flag
> will be set ?
> 
> 
> > +	for (i = 0; i < HSI_CHAR_DEVS && channels_map[i] >= 0; i++) {
> > +		if (channels_map[i] >= HSI_CHAR_DEVS) {
> > +			pr_err("Invalid HSI/SSI channel specified");
> > +			return -EINVAL;
> > +		}
> > +		set_bit(channels_map[i], &ch_mask);
> 
> How will this integrate with hot discovery of SSI supporting devices ?
> 

For every SSI port there is an HSI char client device, which is the
device received through probe. The driver will export for every HSI char
client device, HSI_CHAR_DEVS char devices, one char device per channel.

The intention of this piece of code is to allow the user to configure
which channels the user wants to be available to userspace.

Thanks for the comments,
Carlos


  reply	other threads:[~2010-12-14 17:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-14 10:09 [RFC PATCHv4 0/7] HSI framework and drivers Carlos Chinea
2010-12-14 10:09 ` [RFC PATCHv4 1/7] HSI: hsi: Introducing HSI framework Carlos Chinea
2010-12-14 10:09 ` [RFC PATCHv4 2/7] HSI: omap_ssi: Introducing OMAP SSI driver Carlos Chinea
2010-12-18  0:30   ` Tony Lindgren
2010-12-20 16:38     ` Carlos Chinea
2010-12-14 10:09 ` [RFC PATCHv4 3/7] HSI: omap_ssi: Add OMAP SSI to the kernel configuration Carlos Chinea
2010-12-14 10:09 ` [RFC PATCHv4 4/7] HSI: hsi_char: Add HSI char device driver Carlos Chinea
2010-12-14 11:56   ` Alan Cox
2010-12-14 17:24     ` Carlos Chinea [this message]
2010-12-14 10:09 ` [RFC PATCHv4 5/7] HSI: hsi_char: Add HSI char device kernel configuration Carlos Chinea
2010-12-14 10:09 ` [RFC PATCHv4 6/7] HSI: Add HSI API documentation Carlos Chinea
2010-12-14 10:09 ` [RFC PATCHv4 7/7] HSI: hsi_char: Update ioctl-number.txt Carlos Chinea
2011-03-21  8:16 ` [RFC PATCHv4 0/7] HSI framework and drivers Linus Walleij
2011-03-22  9:50   ` Carlos Chinea
2011-05-12 12:17     ` Govindraj
2011-05-16 12:04       ` Linus Walleij
2011-05-17  8:39         ` Carlos Chinea
2011-06-07 15:09           ` Sebastian Reichel
2011-06-08  7:12             ` Carlos Chinea

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=1292347468.2529.220.camel@groo \
    --to=carlos.chinea@nokia.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=andras.domokos@nokia.com \
    --cc=linux-kernel@vger.kernel.org \
    --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