From: Peter Rosin <peda@axentia.se>
To: Rob Herring <robh@kernel.org>
Cc: Jonathan Cameron <jic23@kernel.org>,
linux-kernel@vger.kernel.org, Wolfram Sang <wsa@the-dreams.de>,
Mark Rutland <mark.rutland@arm.com>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
linux-i2c@vger.kernel.org, devicetree@vger.kernel.org,
linux-iio@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v8 12/12] mux: support simplified bindings for single-user gpio mux
Date: Mon, 30 Jan 2017 09:02:52 +0100 [thread overview]
Message-ID: <67bc8a1c-7067-700f-2b69-12a76d91b2ba@axentia.se> (raw)
In-Reply-To: <20170127155202.z2ufbq5bdtclk5oo@rob-hp-laptop>
[-- Attachment #1: Type: text/plain, Size: 2895 bytes --]
On 2017-01-27 16:52, Rob Herring wrote:
> On Mon, Jan 23, 2017 at 11:24:18AM +0100, Peter Rosin wrote:
>> On 2017-01-22 14:30, Jonathan Cameron wrote:
>>> On 18/01/17 15:57, Peter Rosin wrote:
>>>> Allow bindings for a GPIO controlled mux to be specified in the
>>>> mux consumer node.
>>>>
>>>> Signed-off-by: Peter Rosin <peda@axentia.se>
>>> Code is good as far as I am concerned. Only question is whether this
>>
>> Hmmm, now that I think some more about it, the code supporting the
>> simplified binding (patch 12/12) is a bit fishy in one respect.
>>
>> A driver that calls mux_control_get and gets a mux_control that happens
>> to be backed by an implicit mux chip (i.e. using the simplified binding)
>> will not be able to reverse the resource allocation with less than a
>> complete destruction of itself. Now, this is likely not a problem in
>> most cases, but I bet it will creep up at the most inopportune time. And
>> your remark that I'm the one that has to maintain this makes me dislike
>> this concept...
>>
>> I.e. mux_control_put *should* reverse mux_control_get, but this simply
>> does not happen for the implicit mux chips, as implicit mux chips are
>> not put away until the owning device is put away.
>
> I think this is because you aren't creating a device in this case. Nodes
> in DT are not the only way to create devices. Drivers can create a child
> device when they find mux-gpios property.
Yes, but even with such a child device, a flag is needed somewhere that
triggers cleanup when the mux_control is put away. And then it is possible
to cleanup w/o the help of a child device. I wrote some code for this when
I realized the problem, and it looks simple enough, but I haven't tested
it yet, so who knows... It is attached (patch to be applied on top of 12/12)
if anyone cares.
>> Every time I have tried to come up with a way to implement the simplified
>> bindings I seem to hit one of these subtleties.
>>
>>> is worth the hassle given the normal bindings don't give that high
>>> a burden in complexity!
>
> I was going to change my mind here, but we already have "mux-gpios" as a
> binding at least for i2c-gpio-mux. So really the question is do we want
> to support that here?
I think my preference is to drop the simplified binding, but I can also
live with it. But as there appears to be no strong feelings, let's just
drop it. It is always possible to add it later. Ok?
>> I am missing an ack from Rob though.
>>
>>> I don't really care either way:)
>>
>> But Rob seems to care, this series just has to find a way to get out of
>> his too-much-churn-will-look-at-it-later list. I sadly don't know how to
>> pull that trick...
>
> By complaining that I'm putting it off... :) I guess I'm okay with this
> series in general. I will reply on the specific patches today.
Great, it appears that I'm quite the magician. :-) Thanks!
Cheers,
peda
[-- Attachment #2: 0001-mux-fix-cleanup-for-simplified-bindings.patch --]
[-- Type: text/plain, Size: 2402 bytes --]
>From 5c448b8dfd831c7bc501d9543d48b2077ee1ba7b Mon Sep 17 00:00:00 2001
From: Peter Rosin <peda@axentia.se>
Date: Tue, 24 Jan 2017 16:58:58 +0100
Subject: [PATCH] mux: fix cleanup for simplified bindings
---
drivers/mux/mux-core.c | 19 ++++++++++++++++++-
include/linux/mux.h | 2 ++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/mux/mux-core.c b/drivers/mux/mux-core.c
index 0caafd6f5a77..53954bd12709 100644
--- a/drivers/mux/mux-core.c
+++ b/drivers/mux/mux-core.c
@@ -321,9 +321,12 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
if (ret == -ENOENT && !mux_name) {
mux_chip = mux_gpio_alloc(dev);
if (!IS_ERR(mux_chip)) {
+ mux_chip->private = true;
ret = devm_mux_chip_register(dev, mux_chip);
- if (ret < 0)
+ if (ret < 0) {
+ devm_mux_chip_free(dev, mux_chip);
return ERR_PTR(ret);
+ }
get_device(&mux_chip->dev);
return mux_chip->mux;
}
@@ -344,6 +347,12 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
if (!mux_chip)
return ERR_PTR(-EPROBE_DEFER);
+ if (mux_chip->private) {
+ dev_err(dev, "%s: private mux chip specified in %s\n",
+ np->full_name, args.np->full_name);
+ return ERR_PTR(-EBUSY);
+ }
+
if (args.args_count > 1 ||
(!args.args_count && (mux_chip->controllers > 1))) {
dev_err(dev, "%s: wrong #mux-control-cells for %s\n",
@@ -368,7 +377,15 @@ EXPORT_SYMBOL_GPL(mux_control_get);
void mux_control_put(struct mux_control *mux)
{
+ bool private = mux->chip->private;
+ struct device *parent = mux->chip->dev.parent;
+
put_device(&mux->chip->dev);
+
+ if (private) {
+ devm_mux_chip_unregister(parent, mux->chip);
+ devm_mux_chip_free(parent, mux->chip);
+ }
}
EXPORT_SYMBOL_GPL(mux_control_put);
diff --git a/include/linux/mux.h b/include/linux/mux.h
index ec9e605d8acf..3ad2e475c9dd 100644
--- a/include/linux/mux.h
+++ b/include/linux/mux.h
@@ -49,6 +49,7 @@ struct mux_control {
* @mux: Array of mux controllers that is handled.
* @dev: Device structure.
* @id: Used to identify the device internally.
+ * @private: The mux chip is implicitly allocated by a single user.
* @ops: Mux controller operations.
*/
struct mux_chip {
@@ -56,6 +57,7 @@ struct mux_chip {
struct mux_control *mux;
struct device dev;
int id;
+ bool private;
const struct mux_control_ops *ops;
};
--
2.1.4
prev parent reply other threads:[~2017-01-30 8:02 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-18 15:57 [PATCH v8 00/12] mux controller abstraction and iio/i2c muxes Peter Rosin
2017-01-18 15:57 ` [PATCH v8 01/12] devres: trivial whitespace fix Peter Rosin
2017-01-18 15:57 ` [PATCH v8 02/12] dt-bindings: document devicetree bindings for mux-controllers and mux-gpio Peter Rosin
[not found] ` <1484755035-25927-3-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-27 17:49 ` Rob Herring
2017-01-27 18:57 ` Peter Rosin
2017-01-18 15:57 ` [PATCH v8 03/12] mux: minimal mux subsystem and gpio-based mux controller Peter Rosin
2017-01-18 15:57 ` [PATCH v8 04/12] iio: inkern: api for manipulating ext_info of iio channels Peter Rosin
2017-01-18 15:57 ` [PATCH v8 05/12] dt-bindings: iio: io-channel-mux: document io-channel-mux bindings Peter Rosin
2017-01-27 19:12 ` Rob Herring
2017-01-18 15:57 ` [PATCH v8 06/12] iio: multiplexer: new iio category and iio-mux driver Peter Rosin
2017-01-18 15:57 ` [PATCH v8 07/12] dt-bindings: i2c: i2c-mux-simple: document i2c-mux-simple bindings Peter Rosin
2017-01-27 19:39 ` Rob Herring
2017-01-28 22:42 ` Peter Rosin
[not found] ` <835415bf-77af-6131-d018-d0bc7d8233b0-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-30 17:20 ` Rob Herring
[not found] ` <CAL_JsqLVrzm4BEv3kpOGRoaRq+cqvSm+A6weZfU8H8i9dc=tcA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-31 7:36 ` Peter Rosin
2017-02-02 16:08 ` Rob Herring
2017-02-03 8:25 ` Peter Rosin
[not found] ` <5dc05e28-45c7-1dfe-3cd2-53e55490b48a-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-02-06 21:22 ` Rob Herring
[not found] ` <1484755035-25927-1-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-18 15:57 ` [PATCH v8 08/12] i2c: i2c-mux-simple: new driver Peter Rosin
2017-01-18 15:57 ` [PATCH v8 09/12] dt-bindings: mux-adg792a: document devicetree bindings for ADG792A/G mux Peter Rosin
2017-01-27 19:50 ` Rob Herring
2017-01-27 22:09 ` Peter Rosin
[not found] ` <383638ef-1bb2-224f-0fd0-4818395a2306-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-28 10:34 ` Peter Meerwald-Stadler
2017-01-28 11:40 ` Jonathan Cameron
2017-01-18 15:57 ` [PATCH v8 10/12] mux: adg792a: add mux controller driver for ADG792A/G Peter Rosin
2017-01-18 15:57 ` [PATCH v8 11/12] dt-bindings: simplified bindings for single-user gpio mux Peter Rosin
2017-01-18 15:57 ` [PATCH v8 12/12] mux: support " Peter Rosin
[not found] ` <1484755035-25927-13-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-22 13:30 ` Jonathan Cameron
2017-01-23 10:24 ` Peter Rosin
2017-01-27 15:52 ` Rob Herring
2017-01-30 8:02 ` Peter Rosin [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=67bc8a1c-7067-700f-2b69-12a76d91b2ba@axentia.se \
--to=peda@axentia.se \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--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=mark.rutland@arm.com \
--cc=pmeerw@pmeerw.net \
--cc=robh@kernel.org \
--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).