linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Grant Likely <grant.likely@secretlab.ca>
To: linuxppc-dev@ozlabs.org, spi-devel-general@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: david-b@pacbell.net, fabrizio.garetto@gmail.com
Subject: [PATCH v2 1/5] spi: Change modalias from a pointer to a character array
Date: Wed, 02 Jul 2008 19:02:58 -0600	[thread overview]
Message-ID: <20080703010257.26187.29589.stgit@trillian.secretlab.ca> (raw)
In-Reply-To: <20080703005749.26187.71719.stgit@trillian.secretlab.ca>

From: Grant Likely <grant.likely@secretlab.ca>

Currently, 'modalias' in the spi_device structure is a 'const char *'.
The spi_new_device() function fills in the modalias value from a passed
in spi_board_info data block.  Since it is a pointer copy, the new
spi_device remains dependent on the spi_board_info structure after the
new spi_device is registered (no other fields in spi_device directly
depend on the spi_board_info structure; all of the other data is copied).

This causes a problem when dynamically propulating the list of attached
SPI devices.  For example, in arch/powerpc, the list of SPI devices can
be populated from data in the device tree.  With the current code, the
device tree adapter must kmalloc() a new spi_board_info structure for
each new SPI device it finds in the device tree, and there is no simple
mechanism in place for keeping track of these allocations.

This patch changes modalias from a 'const char *' to a fixed char array.
By copying the modalias string instead of referencing it, the dependency
on the spi_board_info structure is eliminated and an outside caller does
not need to maintain a separate spi_board_info allocation for each device.

If searched through the code to the best of my ability for any references
to modalias which may be affected by this change and haven't found anything.
It has been tested with the lite5200b platform in arch/powerpc.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 drivers/spi/spi.c       |    4 +++-
 include/linux/spi/spi.h |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1ad12af..32b7a42 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -218,6 +218,8 @@ struct spi_device *spi_new_device(struct spi_master *master,
 	if (!spi_master_get(master))
 		return NULL;
 
+	WARN_ON(strlen(chip->modalias) >= sizeof(proxy->modalias));
+
 	proxy = kzalloc(sizeof *proxy, GFP_KERNEL);
 	if (!proxy) {
 		dev_err(dev, "can't alloc dev for cs%d\n",
@@ -229,7 +231,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
 	proxy->max_speed_hz = chip->max_speed_hz;
 	proxy->mode = chip->mode;
 	proxy->irq = chip->irq;
-	proxy->modalias = chip->modalias;
+	strlcpy(proxy->modalias, chip->modalias, sizeof(proxy->modalias));
 
 	snprintf(proxy->dev.bus_id, sizeof proxy->dev.bus_id,
 			"%s.%u", master->dev.bus_id,
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 387e428..b55910b 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -82,7 +82,7 @@ struct spi_device {
 	int			irq;
 	void			*controller_state;
 	void			*controller_data;
-	const char		*modalias;
+	char			modalias[32];
 
 	/*
 	 * likely need more hooks for more protocol options affecting how

  reply	other threads:[~2008-07-03  1:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-03  1:02 [PATCH v2 0/5] SPI OF bindings and mpc5200-spi driver Grant Likely
2008-07-03  1:02 ` Grant Likely [this message]
2008-07-03  1:03 ` [PATCH v2 2/5] spi: split up spi_new_device() to allow two stage registration Grant Likely
2008-07-03  1:03 ` [PATCH v2 3/5] of-bindings: Add binding documentation for SPI busses and devices Grant Likely
2008-07-04  3:59   ` [PATCH v2 3/5] of-bindings: Add binding documentation for SPI bussesand devices Chen Gong
2008-07-04  4:05     ` Grant Likely
2008-07-04 23:36   ` [PATCH v2 3/5] of-bindings: Add binding documentation for SPI busses and devices Segher Boessenkool
2008-07-04 23:42     ` Grant Likely
2008-07-03  1:03 ` [PATCH v2 4/5] spi: Add OF binding support for SPI busses Grant Likely
2008-07-03  3:02   ` Jon Smirl
2008-07-12  5:21     ` Grant Likely
2008-07-04  3:54   ` Chen Gong
2008-07-04  4:17     ` Grant Likely
2008-07-03  1:03 ` [PATCH v2 5/5] powerpc/mpc5200: Add mpc5200-spi (non-PSC) device driver Grant Likely

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=20080703010257.26187.29589.stgit@trillian.secretlab.ca \
    --to=grant.likely@secretlab.ca \
    --cc=david-b@pacbell.net \
    --cc=fabrizio.garetto@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=spi-devel-general@lists.sourceforge.net \
    /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).