linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
@ 2008-05-22  0:04 David Brownell
       [not found] ` <200805211704.56761.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: David Brownell @ 2008-05-22  0:04 UTC (permalink / raw)
  To: Andrew Morton; +Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

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-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Signed-off-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
---
 drivers/spi/spi.c       |    2 +-
 include/linux/spi/spi.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -229,7 +229,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;
+	strncpy(proxy->modalias, chip->modalias, KOBJ_NAME_LEN);
 
 	snprintf(proxy->dev.bus_id, sizeof proxy->dev.bus_id,
 			"%s.%u", master->dev.bus_id,
--- 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[KOBJ_NAME_LEN];
 
 	/*
 	 * likely need more hooks for more protocol options affecting how


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
       [not found] ` <200805211704.56761.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
@ 2008-05-22  3:46   ` Andrew Morton
       [not found]     ` <20080521204633.8234c7d7.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2008-05-22  3:46 UTC (permalink / raw)
  To: David Brownell; +Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Wed, 21 May 2008 17:04:56 -0700 David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:

> From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> 
> 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.
> 

Not for 2.6.26, I assume?

> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -229,7 +229,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;
> +	strncpy(proxy->modalias, chip->modalias, KOBJ_NAME_LEN);
>  
>  	snprintf(proxy->dev.bus_id, sizeof proxy->dev.bus_id,
>  			"%s.%u", master->dev.bus_id,
> --- 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[KOBJ_NAME_LEN];
>  
>  	/*
>  	 * likely need more hooks for more protocol options affecting how

a) strncpy() doesn't null-terminate the dest if it overran.  strlcpy() does.

b) Given the uncertainly over the state of existing code, perhaps we
   should have an explicit check for overflows here, with a WARN_ON()?

c) I think it's better to use sizeof() in the strlcpy() rather than
   duplicating the array size - it's a little more robust in the face
   of future changes and it is more obviously-correct (don't need to go
   elsewhere to check the size of the destination).

d) KOBJ_NAME_LEN no longer exists in linux-next.  I'm not sure where
   it went - Greg and Kay have been up to their usual tricks.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
       [not found]     ` <20080521204633.8234c7d7.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
@ 2008-05-23 17:31       ` David Brownell
       [not found]         ` <200805231031.25919.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: David Brownell @ 2008-05-23 17:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Wednesday 21 May 2008, Andrew Morton wrote:
> On Wed, 21 May 2008 17:04:56 -0700 David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:
> 
> > From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> >		...
> > -	proxy->modalias = chip->modalias;
> > +	strncpy(proxy->modalias, chip->modalias, KOBJ_NAME_LEN);
> >		...
> 
> a) strncpy() doesn't null-terminate the dest if it overran.  strlcpy() does.
> 
> b) Given the uncertainly over the state of existing code, perhaps we
>    should have an explicit check for overflows here, with a WARN_ON()?
> 
> c) I think it's better to use sizeof() in the strlcpy() rather than
>    duplicating the array size - it's a little more robust in the face
>    of future changes and it is more obviously-correct (don't need to go
>    elsewhere to check the size of the destination).

Good points.  I usually try to use sizeof() myself, for exactly
that reason.  Updated version (below) uses strlcpy, sizeof, WARN_ON.


> d) KOBJ_NAME_LEN no longer exists in linux-next.  I'm not sure where
>    it went - Greg and Kay have been up to their usual tricks.
 
Yeech.  Replacing symbols with inline constants isn't good when
the constant is what ensures various fields are the same size.

BTW -- four comments on one line is pretty good even for you.  ;)

- Dave


========= CUT HERE
From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

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-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
[ cope with linux-next changes: KOBJ_NAME_LEN obliterated, etc ]
Signed-off-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
---
 drivers/spi/spi.c       |    4 +++-
 include/linux/spi/spi.h |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

--- a/drivers/spi/spi.c	2008-05-22 10:57:21.000000000 -0700
+++ b/drivers/spi/spi.c	2008-05-22 18:56:16.000000000 -0700
@@ -218,6 +218,8 @@ struct spi_device *spi_new_device(struct
 	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
 	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,
--- a/include/linux/spi/spi.h	2008-05-22 10:57:21.000000000 -0700
+++ b/include/linux/spi/spi.h	2008-05-23 10:21:41.000000000 -0700
@@ -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



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
       [not found]         ` <200805231031.25919.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
@ 2008-05-23 17:38           ` Grant Likely
  2008-05-23 18:33           ` Andrew Morton
  2008-07-17 22:33           ` Grant Likely
  2 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2008-05-23 17:38 UTC (permalink / raw)
  To: David Brownell
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Andrew Morton

On Fri, May 23, 2008 at 11:31 AM, David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:
> On Wednesday 21 May 2008, Andrew Morton wrote:
>> On Wed, 21 May 2008 17:04:56 -0700 David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:
>>
>> > From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>> >             ...
>> > -   proxy->modalias = chip->modalias;
>> > +   strncpy(proxy->modalias, chip->modalias, KOBJ_NAME_LEN);
>> >             ...
>>
>> a) strncpy() doesn't null-terminate the dest if it overran.  strlcpy() does.
>>
>> b) Given the uncertainly over the state of existing code, perhaps we
>>    should have an explicit check for overflows here, with a WARN_ON()?
>>
>> c) I think it's better to use sizeof() in the strlcpy() rather than
>>    duplicating the array size - it's a little more robust in the face
>>    of future changes and it is more obviously-correct (don't need to go
>>    elsewhere to check the size of the destination).
>
> Good points.  I usually try to use sizeof() myself, for exactly
> that reason.  Updated version (below) uses strlcpy, sizeof, WARN_ON.

Woo!  I get wrapped up in other code for a few days and someone else
does my work for me.  :-)  Dave, thanks for updating the patch.  I
truly appreciate it.  New version looks good to me.

Cheers,
g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
       [not found]         ` <200805231031.25919.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
  2008-05-23 17:38           ` Grant Likely
@ 2008-05-23 18:33           ` Andrew Morton
       [not found]             ` <20080523113351.8c16bd02.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
  2008-07-17 22:33           ` Grant Likely
  2 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2008-05-23 18:33 UTC (permalink / raw)
  To: David Brownell; +Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Fri, 23 May 2008 10:31:25 -0700
David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:

> On Wednesday 21 May 2008, Andrew Morton wrote:
> > On Wed, 21 May 2008 17:04:56 -0700 David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:
> > 
> > > From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> > >		...
> > > -	proxy->modalias = chip->modalias;
> > > +	strncpy(proxy->modalias, chip->modalias, KOBJ_NAME_LEN);
> > >		...
> > 
> > a) strncpy() doesn't null-terminate the dest if it overran.  strlcpy() does.
> > 
> > b) Given the uncertainly over the state of existing code, perhaps we
> >    should have an explicit check for overflows here, with a WARN_ON()?
> > 
> > c) I think it's better to use sizeof() in the strlcpy() rather than
> >    duplicating the array size - it's a little more robust in the face
> >    of future changes and it is more obviously-correct (don't need to go
> >    elsewhere to check the size of the destination).
> 
> Good points.  I usually try to use sizeof() myself, for exactly
> that reason.  Updated version (below) uses strlcpy, sizeof, WARN_ON.

For 2.6.26?

> 
> > d) KOBJ_NAME_LEN no longer exists in linux-next.  I'm not sure where
> >    it went - Greg and Kay have been up to their usual tricks.
>  
> Yeech.  Replacing symbols with inline constants isn't good when
> the constant is what ensures various fields are the same size.
> 
> BTW -- four comments on one line is pretty good even for you.  ;)

I was quite proud of it ;)

> Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> [ cope with linux-next changes: KOBJ_NAME_LEN obliterated, etc ]
> Signed-off-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>

I have a specific format for this which I never told anyone else about:

[email@address: text goes here]

Immediately before the signoffs.

If you do

	git-log | grep '^[ ]*\[akpm@' | wc -l

you'll see how many commits I have deprived myself of ;)

If we stick to that form then perhaps one day those folks who troll the
changelogs to generate who-did-what statistics can incorporate these
things.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
       [not found]             ` <20080523113351.8c16bd02.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
@ 2008-05-23 18:45               ` David Brownell
       [not found]                 ` <200805231145.09786.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: David Brownell @ 2008-05-23 18:45 UTC (permalink / raw)
  To: Andrew Morton; +Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Friday 23 May 2008, Andrew Morton wrote:
> For 2.6.26?

I'm thinking not; shouldn't hurt, but the reason for this is
OpenFirmware integration ... which seems like '27 material.


> > Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> > [ cope with linux-next changes: KOBJ_NAME_LEN obliterated, etc ]
> > Signed-off-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
> 
> I have a specific format for this which I never told anyone else about:
> 
> [email@address: text goes here]
> 
> Immediately before the signoffs.

I'm not entirely consistent about using that, but I suggested
yesterday to Jean Delvare that he use that for some of his I2C
issues (rather than multiple resubmits).

Maybe I'll just make myself a template for that, like I use
for S-o-b and acks.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
       [not found]                 ` <200805231145.09786.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
@ 2008-05-23 18:45                   ` Grant Likely
  0 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2008-05-23 18:45 UTC (permalink / raw)
  To: David Brownell
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Andrew Morton

On Fri, May 23, 2008 at 12:45 PM, David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:
> On Friday 23 May 2008, Andrew Morton wrote:
>> For 2.6.26?
>
> I'm thinking not; shouldn't hurt, but the reason for this is
> OpenFirmware integration ... which seems like '27 material.

Yes, I have nothing targeted for .26 that needs this.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array
       [not found]         ` <200805231031.25919.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
  2008-05-23 17:38           ` Grant Likely
  2008-05-23 18:33           ` Andrew Morton
@ 2008-07-17 22:33           ` Grant Likely
  2 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2008-07-17 22:33 UTC (permalink / raw)
  To: David Brownell
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, linuxppc-dev

David, are you going to pick up this and the other SPI of support
patches (linked below)?  Or should I push them through my tree?  (I'm
assuming that all the comments are addressed and they are ready to be
merged).

http://patchwork.ozlabs.org/linuxppc/patch?id=19597
http://patchwork.ozlabs.org/linuxppc/patch?id=19601
http://patchwork.ozlabs.org/linuxppc/patch?id=19602

Thanks,
g.

On Fri, May 23, 2008 at 11:31 AM, David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:
> On Wednesday 21 May 2008, Andrew Morton wrote:
>> On Wed, 21 May 2008 17:04:56 -0700 David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org> wrote:
>>
>> > From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>> >             ...
>> > -   proxy->modalias = chip->modalias;
>> > +   strncpy(proxy->modalias, chip->modalias, KOBJ_NAME_LEN);
>> >             ...
>>
>> a) strncpy() doesn't null-terminate the dest if it overran.  strlcpy() does.
>>
>> b) Given the uncertainly over the state of existing code, perhaps we
>>    should have an explicit check for overflows here, with a WARN_ON()?
>>
>> c) I think it's better to use sizeof() in the strlcpy() rather than
>>    duplicating the array size - it's a little more robust in the face
>>    of future changes and it is more obviously-correct (don't need to go
>>    elsewhere to check the size of the destination).
>
> Good points.  I usually try to use sizeof() myself, for exactly
> that reason.  Updated version (below) uses strlcpy, sizeof, WARN_ON.
>
>
>> d) KOBJ_NAME_LEN no longer exists in linux-next.  I'm not sure where
>>    it went - Greg and Kay have been up to their usual tricks.
>
> Yeech.  Replacing symbols with inline constants isn't good when
> the constant is what ensures various fields are the same size.
>
> BTW -- four comments on one line is pretty good even for you.  ;)
>
> - Dave
>
>
> ========= CUT HERE
> From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>
> 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-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> [ cope with linux-next changes: KOBJ_NAME_LEN obliterated, etc ]
> Signed-off-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
> ---
>  drivers/spi/spi.c       |    4 +++-
>  include/linux/spi/spi.h |    2 +-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> --- a/drivers/spi/spi.c 2008-05-22 10:57:21.000000000 -0700
> +++ b/drivers/spi/spi.c 2008-05-22 18:56:16.000000000 -0700
> @@ -218,6 +218,8 @@ struct spi_device *spi_new_device(struct
>        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
>        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,
> --- a/include/linux/spi/spi.h   2008-05-22 10:57:21.000000000 -0700
> +++ b/include/linux/spi/spi.h   2008-05-23 10:21:41.000000000 -0700
> @@ -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
>
>
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-07-17 22:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-22  0:04 [patch 2.6.26-rc3] spi: make spi_board_info.modalias a char array David Brownell
     [not found] ` <200805211704.56761.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-22  3:46   ` Andrew Morton
     [not found]     ` <20080521204633.8234c7d7.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2008-05-23 17:31       ` David Brownell
     [not found]         ` <200805231031.25919.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-23 17:38           ` Grant Likely
2008-05-23 18:33           ` Andrew Morton
     [not found]             ` <20080523113351.8c16bd02.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2008-05-23 18:45               ` David Brownell
     [not found]                 ` <200805231145.09786.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-23 18:45                   ` Grant Likely
2008-07-17 22:33           ` Grant Likely

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).