linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Rosin <peda@lysator.liu.se>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-kernel@vger.kernel.org, Peter Rosin <peda@axentia.se>,
	Jonathan Corbet <corbet@lwn.net>,
	Peter Korsgaard <peter.korsgaard@barco.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	Antti Palosaari <crope@iki.fi>,
	Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
	Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Grant Likely <grant.likely@linaro.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"David S. Miller" <davem@davemloft.net>,
	Kalle Valo <kvalo@codeaurora.org>, Joe Perches <joe@perches.com>,
	Jiri Slaby <jslaby@suse.com>,
	Daniel Baluta <daniel.baluta@intel.com>,
	Adriana Reus <adriana.reus@intel.com>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	Matt Ranostay <matt.ranostay@intel.com>,
	Krzysztof Kozlowski <k.kozlowski@samsung.com>,
	Terry Heo <terryheo@google.com>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Tommi Rantala <tt.rantala@gmail.com>,
	linux-i2c@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-iio@vger.kernel.org, linux-media@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v6 01/24] i2c-mux: add common data for every i2c-mux instance
Date: Wed, 13 Apr 2016 15:37:50 +0200	[thread overview]
Message-ID: <570E4BAE.7060108@lysator.liu.se> (raw)
In-Reply-To: <20160411204630.GA10401@katana>

Hi!

On 2016-04-11 22:46, Wolfram Sang wrote:
> Hi Peter,
> 
> first high-level review:
> 
>> +int i2c_mux_reserve_adapters(struct i2c_mux_core *muxc, int adapters)
> 
> I'd suggest to rename 'adapters' into 'num_adapters' throughout this
> patch. I think it makes the code a lot easier to understand.

Hmm, you mean just the variable names, right? And not function names
such as i2c_mux_reserve_(num_)adapters?

>> +{
>> +	struct i2c_adapter **adapter;
>> +
>> +	if (adapters <= muxc->max_adapters)
>> +		return 0;
>> +
>> +	adapter = devm_kmalloc_array(muxc->dev,
>> +				     adapters, sizeof(*adapter),
>> +				     GFP_KERNEL);
>> +	if (!adapter)
>> +		return -ENOMEM;
>> +
>> +	if (muxc->adapter) {
>> +		memcpy(adapter, muxc->adapter,
>> +		       muxc->max_adapters * sizeof(*adapter));
>> +		devm_kfree(muxc->dev, muxc->adapter);
>> +	}
>> +
>> +	muxc->adapter = adapter;
>> +	muxc->max_adapters = adapters;
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(i2c_mux_reserve_adapters);
> 
> Despite that I wonder why not using some of the realloc functions, I

When I wrote it, I found no devm_ version of realloc. I'm not finding
anything now either...

> wonder even more if we couldn't supply num_adapters to i2c_mux_alloc()
> and reserve the memory statically. i2c busses are not
> dynamic/hot-pluggable so that should be good enough?

Yes, that would work, but it would take some restructuring in some of
the drivers that currently don't know how many child adapters they
are going to need when they call i2c_mux_alloc.

Because you thought about removing i2c_mux_reserve_adapters completely,
and not provide any means of adding more adapters than specified in
the i2c_mux_alloc call, right?

>> -	WARN(sysfs_create_link(&priv->adap.dev.kobj, &mux_dev->kobj, "mux_device"),
>> -			       "can't create symlink to mux device\n");
>> +	WARN(sysfs_create_link(&priv->adap.dev.kobj, &muxc->dev->kobj,
>> +			       "mux_device"),
> 
> Ignoring the 80 char limit here makes the code more readable.

That is only true if you actually have more than 80 characters, so I don't
agree. Are you adamant about it? (I'm not)

>> +	     "can't create symlink to mux device\n");
>>  
>>  	snprintf(symlink_name, sizeof(symlink_name), "channel-%u", chan_id);
>> -	WARN(sysfs_create_link(&mux_dev->kobj, &priv->adap.dev.kobj, symlink_name),
>> -			       "can't create symlink for channel %u\n", chan_id);
>> +	WARN(sysfs_create_link(&muxc->dev->kobj, &priv->adap.dev.kobj,
>> +			       symlink_name),
> 
> ditto.
> 
>> +	     "can't create symlink for channel %u\n", chan_id);
>>  	dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
>>  		 i2c_adapter_id(&priv->adap));
>>  
>> -	return &priv->adap;
>> +	muxc->adapter[muxc->adapters++] = &priv->adap;
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(i2c_mux_add_adapter);
>> +
>> +struct i2c_mux_core *i2c_mux_one_adapter(struct i2c_adapter *parent,
>> +					 struct device *dev, int sizeof_priv,
>> +					 u32 flags, u32 force_nr,
>> +					 u32 chan_id, unsigned int class,
>> +					 int (*select)(struct i2c_mux_core *,
>> +						       u32),
> 
> ditto
> 
>> +					 int (*deselect)(struct i2c_mux_core *,
>> +							 u32))
> 
> ditto
> 
>> +{
>> +	struct i2c_mux_core *muxc;
>> +	int ret;
>> +
>> +	muxc = i2c_mux_alloc(parent, dev, sizeof_priv, flags, select, deselect);
>> +	if (!muxc)
>> +		return ERR_PTR(-ENOMEM);
>> +
>> +	ret = i2c_mux_add_adapter(muxc, force_nr, chan_id, class);
>> +	if (ret) {
>> +		devm_kfree(dev, muxc);
>> +		return ERR_PTR(ret);
>> +	}
>> +
>> +	return muxc;
>> +}
>> +EXPORT_SYMBOL_GPL(i2c_mux_one_adapter);
> 
> Are you sure the above function pays off? Its argument list is very
> complex and it doesn't save a lot of code. Having seperate calls is
> probably more understandable in drivers? Then again, I assume it makes
> the conversion of existing drivers easier.

I added it in v4, you can check earlier versions if you like. Without
it most gate-muxes (i.e. typically the muxes in drivers/media) grew
since the i2c_add_mux_adapter call got replaced by two calls, i.e.
i2c_mux_alloc followed by i2c_max_add_adapter, and coupled with
error checks made it look more complex than before. So, this wasn't
much of a cleanup from the point of those drivers.

> So much for now. Thanks!

Yeah, thanks!

Cheers,
Peter

  reply	other threads:[~2016-04-13 13:38 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-03  8:52 [PATCH v6 00/24] i2c mux cleanup and locking update Peter Rosin
2016-04-03  8:52 ` [PATCH v6 01/24] i2c-mux: add common data for every i2c-mux instance Peter Rosin
2016-04-11 20:46   ` Wolfram Sang
2016-04-13 13:37     ` Peter Rosin [this message]
2016-04-15 11:23       ` Wolfram Sang
2016-04-03  8:52 ` [PATCH v6 02/24] i2c: i2c-mux-gpio: convert to use an explicit i2c mux core Peter Rosin
2016-04-03  8:52 ` [PATCH v6 03/24] i2c: i2c-mux-pinctrl: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 04/24] i2c: i2c-arb-gpio-challenge: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 05/24] i2c: i2c-mux-pca9541: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 06/24] i2c: i2c-mux-pca954x: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 07/24] i2c: i2c-mux-reg: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 08/24] iio: imu: inv_mpu6050: " Peter Rosin
2016-04-03 10:51   ` Jonathan Cameron
2016-04-03 11:51     ` Peter Rosin
2016-04-10 14:12       ` Jonathan Cameron
2016-04-19 15:58   ` Crestez Dan Leonard
2016-04-19 16:37     ` Peter Rosin
2016-04-03  8:52 ` [PATCH v6 09/24] [media] m88ds3103: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 10/24] [media] rtl2830: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 11/24] [media] rtl2832: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 12/24] [media] si2168: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 13/24] [media] cx231xx: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 14/24] of/unittest: " Peter Rosin
2016-04-04  5:16   ` Rob Herring
2016-04-05  7:42     ` Peter Rosin
2016-04-03  8:52 ` [PATCH v6 15/24] i2c-mux: drop old unused i2c-mux api Peter Rosin
2016-04-03  8:52 ` [PATCH v6 16/24] i2c: allow adapter drivers to override the adapter locking Peter Rosin
2016-04-03  8:52 ` [PATCH v6 17/24] i2c: muxes always lock the parent adapter Peter Rosin
2016-04-03  8:52 ` [PATCH v6 18/24] i2c-mux: relax locking of the top i2c adapter during mux-locked muxing Peter Rosin
2016-04-03  8:52 ` [PATCH v6 19/24] i2c-mux: document i2c muxes and elaborate on parent-/mux-locked muxes Peter Rosin
2016-04-03 11:09   ` Jonathan Cameron
2016-04-05  7:50     ` Peter Rosin
2016-04-03  8:52 ` [PATCH v6 20/24] iio: imu: inv_mpu6050: change the i2c gate to be mux-locked Peter Rosin
2016-04-03 10:54   ` Jonathan Cameron
2016-04-18  7:37     ` Daniel Baluta
2016-04-03  8:52 ` [PATCH v6 21/24] [media] si2168: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 22/24] [media] rtl2832: " Peter Rosin
2016-04-03  8:52 ` [PATCH v6 23/24] [media] rtl2832_sdr: get rid of empty regmap wrappers Peter Rosin
2016-04-03  8:52 ` [PATCH v6 24/24] [media] rtl2832: regmap is aware of lockdep, drop local locking hack Peter Rosin
2016-04-11 12:39 ` [PATCH v6 00/24] i2c mux cleanup and locking update Wolfram Sang
2016-04-11 13:36   ` Peter Rosin
2016-04-11 15:59     ` Wolfram Sang
2016-04-15 15:52 [PATCH v6 01/24] i2c-mux: add common data for every i2c-mux instance Peter Rosin

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=570E4BAE.7060108@lysator.liu.se \
    --to=peda@lysator.liu.se \
    --cc=adriana.reus@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=corbet@lwn.net \
    --cc=crope@iki.fi \
    --cc=daniel.baluta@intel.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hans.verkuil@cisco.com \
    --cc=jic23@kernel.org \
    --cc=joe@perches.com \
    --cc=jslaby@suse.com \
    --cc=k.kozlowski@samsung.com \
    --cc=knaack.h@gmx.de \
    --cc=kvalo@codeaurora.org \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lucas.demarchi@intel.com \
    --cc=matt.ranostay@intel.com \
    --cc=mchehab@osg.samsung.com \
    --cc=peda@axentia.se \
    --cc=peter.korsgaard@barco.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=terryheo@google.com \
    --cc=tt.rantala@gmail.com \
    --cc=wsa@the-dreams.de \
    /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;
as well as URLs for NNTP newsgroup(s).