public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Brian Norris <computersforpeace@gmail.com>
Cc: devicetree@vger.kernel.org,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Scott Branden" <sbranden@broadcom.com>,
	"Kevin Cernekee" <cernekee@gmail.com>,
	"Corneliu Doban" <cdoban@broadcom.com>,
	"Ray Jui" <rjui@broadcom.com>, "Rafał Miłecki" <zajec5@gmail.com>,
	linux-kernel@vger.kernel.org,
	"Dan Ehrenberg" <dehrenberg@chromium.org>,
	"Jonathan Richardson" <jonathar@broadcom.com>,
	"Anatol Pomazao" <anatol@google.com>,
	"Gregory Fong" <gregory.0xf0@gmail.com>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-mtd@lists.infradead.org,
	"Dmitry Torokhov" <dtor@google.com>
Subject: Re: [PATCH v4 08/11] mtd: brcmnand: add BCM63138 support
Date: Wed, 13 May 2015 22:02:49 +0200	[thread overview]
Message-ID: <5685584.0QXUdSHDpG@wuerfel> (raw)
In-Reply-To: <20150513194521.GF11598@ld-irv-0074>

On Wednesday 13 May 2015 12:45:21 Brian Norris wrote:
> On Wed, May 13, 2015 at 12:49:01PM +0200, Arnd Bergmann wrote:
> > On Tuesday 12 May 2015 17:53:41 Brian Norris wrote:
> > 
> > This is a slightly unconventional method of doing the abstraction.
> > For consistency with a lot of other drivers, I'd do it like this:
> > 
> > struct bcm63138_controller {
> > 	void __iomem *base;
> > 	brcmnand_controller parent;
> > };
> 
> Does it really make sense to publicize all of the brcmnand_controller
> details to each of the constituent drivers? I was intentionally keeping
> them private, with a very small and well-defined interface provided for
> shim SoC drivers.
> 
> This is kind of a problem that has plagued the wider MTD (and esp. NAND)
> subsystem in general; we expose a ton of details to low-level drivers,
> and they're free to muck with things however they want, as long as it
> ends up working. I'd rather be more intentional in what I expose.

In most cases like this, the soc-specific glue drivers eventually need
access to some of the struct members anyway, but of course it's possible
that you don't need that here.

> > static bool bcm63138_nand_intc_ack(struct brcmnand_controller *parent)
> > {
> > 	struct bcm63138_controller *controller;
> > 	controller = container_of(parent, struct brcmnand_controller, parent);
> > 
> > 	...
> > }
> > 
> > static int bcm63138_nand_probe(...)
> > {
> > 	struct bcm63138_controller *controller;
> > 
> > 	controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
> > 	...
> > 	return brcmnand_probe(pdev, &controller->parent);
> > }
> > 
> > This also simplifies the probe() functions and means less pointer chasing.
> 
> I could still avoid one pointer chase and one extra memory allocation by
> embedding 'struct brcmnand_soc' in a 'struct bcm63138_nand_soc'. e.g.:
> 
> struct bcm63138_nand_soc {
> 	void __iomem *base;
> 	struct brcmnand_soc soc;
> };
> 
> static bool bcm63138_nand_intc_ack(struct brcmnand_soc *soc)
> {
> 	struct bcm63138_nand_soc *priv;
> 	priv = container_of(soc, struct bcm63138_nand_soc, soc);
> 
> 	...
> }
> 
> static int bcm63138_nand_probe(...)
> {
> 	struct bcm63138_nand_soc *priv;
> 
> 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> 	...
> 	return brcmnand_probe(pdev, &priv->soc);
> }

That would make struct brcmnand_soc an empty structure, right?
I think that's fine though, at least it avoids passing void pointers
and it avoids one of the two allocations you do.

There is another variation of this model, which some drivers use:

static int bcm63138_nand_probe(...)
{
	struct bcm63138_nand_soc *priv;
	struct brcmnand_controller *controller;

	controller = brcmnand_controller_alloc(dev, sizeof (*priv));

	priv = brcmnand_controller_priv(controller);

	...

	return brcmnand_register(controller);
}

struct brcmnand_controller *brcmnand_controller_alloc(struct device *pdev, size_t extra)
{
	struct brcmnand_controller *p = dev_kzalloc(dev, sizeof(*p) + extra);

	...

	return p;
}

void *brcmnand_controller_priv(brcmnand_controller *p)
{
	/* extra data follows at the next byte after the controller structure */
	return p + 1;
}

Some subsystem maintainers prefer this model over the other one, up to you.

	Arnd

  reply	other threads:[~2015-05-13 20:03 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13  0:53 [PATCH v4 00/11] mtd: nand: add Broadcom NAND controller support Brian Norris
2015-05-13  0:53 ` [PATCH v4 01/11] Documentation: devicetree: add binding doc for Broadcom NAND controller Brian Norris
2015-05-13  0:53 ` [PATCH v4 02/11] mtd: nand: add NAND driver "library" for Broadcom STB " Brian Norris
2015-05-13  0:53 ` [PATCH v4 03/11] mtd: brcmnand: add support for STB chips Brian Norris
2015-05-13  0:53 ` [PATCH v4 04/11] ARM: bcm7445: add NAND to DTS Brian Norris
2015-05-13  0:53 ` [PATCH v4 05/11] Documentation: devicetree: brcmstb_nand: add BCM63138 and Cygnus/iProc Brian Norris
2015-05-13  0:53 ` [PATCH v4 06/11] mtd: brcmnand: add extra SoC support to library Brian Norris
2015-05-13  0:53 ` [PATCH v4 07/11] mtd: brcmnand: add support for Broadcom's IPROC family Brian Norris
2015-05-13  0:53 ` [PATCH v4 08/11] mtd: brcmnand: add BCM63138 support Brian Norris
2015-05-13 10:49   ` Arnd Bergmann
2015-05-13 19:45     ` Brian Norris
2015-05-13 20:02       ` Arnd Bergmann [this message]
2015-05-13 20:24         ` Brian Norris
2015-05-13 20:48           ` Arnd Bergmann
2015-05-13  0:53 ` [PATCH v4 09/11] ARM: bcm63138: add NAND DT support Brian Norris
2015-05-13  0:53 ` [PATCH v4 10/11] ARM: dts: cygnus: Enable NAND support for Cygnus Brian Norris
2015-05-13  0:53 ` [PATCH v4 11/11] MAINTAINERS: add entry for new brcmnand/ directory Brian Norris
2015-05-13 10:39 ` [PATCH v4 00/11] mtd: nand: add Broadcom NAND controller support Arnd Bergmann
2015-05-13 17:56 ` Florian Fainelli
2015-05-13 18:14   ` Brian Norris
2015-05-13 19:08     ` Arnd Bergmann
2015-05-15 20:23 ` Brian Norris

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=5685584.0QXUdSHDpG@wuerfel \
    --to=arnd@arndb.de \
    --cc=anatol@google.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=cdoban@broadcom.com \
    --cc=cernekee@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=dehrenberg@chromium.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dtor@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregory.0xf0@gmail.com \
    --cc=jonathar@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=zajec5@gmail.com \
    /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