public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/2] i2c-i801: Handle multiple instances instead of keeping global state
Date: Sun, 31 Oct 2010 11:33:34 +0100	[thread overview]
Message-ID: <20101031113334.3d48c3ad@endymion.delvare> (raw)
In-Reply-To: <1288481663.4570.19.camel-uXGAPMMVk8bAQYKIod7YupZV94DADvEd@public.gmane.org>

Hi David,

On Sat, 30 Oct 2010 19:34:23 -0400, David Woodhouse wrote:
> On Sat, 2010-10-30 at 18:24 +0200, Jean Delvare wrote:
> > An explanation why this change is needed would be nice.
> 
> Um, does it really need explaining? It's really poor form to keep driver
> state in global variables rather than per-instance, even if you *don't*
> actually have more than one device.

True enough. I've even been thinking of sending a similar patch long
ago. The problem is that it's hard to justify the additional cost of
dynamic memory allocation if there's no technical need for it. And
until Sandy Bridge, there wasn't.

> > > (...)
> > > @@ -429,22 +439,23 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
> > >   	/* Experience has shown that the block buffer can only be used for
> > >   	   SMBus (not I2C) block transactions, even though the datasheet
> > >   	   doesn't mention this limitation. */
> > > -	if ((i801_features & FEATURE_BLOCK_BUFFER)
> > > -	 && command != I2C_SMBUS_I2C_BLOCK_DATA
> > > -	 && i801_set_block_buffer_mode() == 0)
> > > -		result = i801_block_transaction_by_block(data, read_write,
> > > -							 hwpec);
> > > +	if ((priv->features & FEATURE_BLOCK_BUFFER)
> > > +	    && command != I2C_SMBUS_I2C_BLOCK_DATA
> > > +	    && i801_set_block_buffer_mode(priv) == 0)
> > 
> > Gratuitous reindentation of code.
> 
> The two continuation lines? I just fixed them to conform to the normal
> kernel indentation,

Normal according to who? I don't see anything wrong with them as they
were before, and it's used in other places of the driver, so it's not
an accident.

> while I was modifying the lines before and after.
> That's entirely normal practice, and not particularly gratuitous,
> surely?

When you send a patch to the wrong person at the wrong time, if you
want it accepted still, you should make it change as little things as
possible.

> > > @@ -457,81 +468,83 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
> > >   	int hwpec;
> > >   	int block = 0;
> > >   	int ret, xact = 0;
> > > +	struct i801_priv *priv = (void *)adap;
> > 
> > This is horrible and only works by accident (or misdesign if you
> > prefer). Please don't do this. I'm glad I insisted to review this
> > patch...
> > 
> > We have i2c_set/get_adapdata() for this. If you really care about the
> > extra cost, please use the proper container_of() construct. But I don't
> > think the cost is problematic.
> 
> It wasn't the cost I was thinking of; it was the simplicity. One
> allocation, one failure case, one error path. That's why this method is
> fairly common within the kernel.
> 
> However, I have no particular objection to doing separate allocations,
> even though it's not what I'd normally do. I'll send another version.

You got me wrong apparently. I have no objection to the single
structure allocation, this is indeed fairly common and a good thing to
avoid memory fragmentation. I have a strong objection on random casts
from one structure to another on the undocumented assumption that one
contains the other as its first member.

All you have to do to make me happy is:

	i2c_set_adapdata(adap, priv);

in the probe function and

	priv = i2c_get_adapdata(adap);

in this function (and i801_func).

-- 
Jean Delvare

      parent reply	other threads:[~2010-10-31 10:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-30 13:47 [PATCH 1/2] i2c-i801: Handle multiple instances instead of keeping global state David Woodhouse
     [not found] ` <alpine.LFD.2.00.1010301445490.7306-NkH8fLdbH5SKw1fGA2nhu27IUlhRatedral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2010-10-30 13:49   ` [PATCH 2/2] i2c-i801: Add PCI idents for Sandy Bridge SMBus controllers David Woodhouse
     [not found]     ` <alpine.LFD.2.00.1010301448240.7306-NkH8fLdbH5SKw1fGA2nhu27IUlhRatedral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2010-10-30 16:36       ` Jean Delvare
     [not found]         ` <20101030183635.4899246f-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-30 23:15           ` David Woodhouse
     [not found]             ` <1288480550.4570.5.camel-uXGAPMMVk8bAQYKIod7YupZV94DADvEd@public.gmane.org>
2010-10-31 10:20               ` Jean Delvare
2010-10-30 16:24   ` [PATCH 1/2] i2c-i801: Handle multiple instances instead of keeping global state Jean Delvare
     [not found]     ` <20101030182458.0849f295-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-30 23:00       ` Ben Dooks
     [not found]         ` <20101030230052.GP21564-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-10-30 23:12           ` David Woodhouse
     [not found]             ` <1288480327.4570.2.camel-uXGAPMMVk8bAQYKIod7YupZV94DADvEd@public.gmane.org>
2010-10-31  9:56               ` Jean Delvare
     [not found]                 ` <20101031105629.109dd2e2-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-31 14:28                   ` David Woodhouse
2010-10-30 23:34       ` David Woodhouse
     [not found]         ` <1288481663.4570.19.camel-uXGAPMMVk8bAQYKIod7YupZV94DADvEd@public.gmane.org>
2010-10-30 23:39           ` Ben Dooks
     [not found]             ` <20101030233930.GQ21564-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-10-30 23:47               ` David Woodhouse
     [not found]                 ` <1288482478.4570.23.camel-uXGAPMMVk8bAQYKIod7YupZV94DADvEd@public.gmane.org>
2010-10-31  9:19                   ` Jean Delvare
     [not found]                     ` <20101031101953.45b3dabf-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-31 14:11                       ` David Woodhouse
2010-10-31 10:01               ` Jean Delvare
     [not found]                 ` <20101031110158.1ff0f03c-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-31 14:15                   ` David Woodhouse
2010-10-31 10:33           ` Jean Delvare [this message]

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=20101031113334.3d48c3ad@endymion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.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