* [PATCH/RFC] spi: Change modalias from a pointer to a character array @ 2008-05-09 17:32 Grant Likely [not found] ` <20080509173146.2932.16141.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Grant Likely @ 2008-05-09 17:32 UTC (permalink / raw) To: linux-kernel, spi-devel-general, dbrownell 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 | 2 +- include/linux/spi/spi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 1ad12af..bdf1b70 100644 --- 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, diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 387e428..38a080b 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[KOBJ_NAME_LEN]; /* * likely need more hooks for more protocol options affecting how ^ permalink raw reply related [flat|nested] 5+ messages in thread
[parent not found: <20080509173146.2932.16141.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org>]
* Re: [PATCH/RFC] spi: Change modalias from a pointer to a character array [not found] ` <20080509173146.2932.16141.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org> @ 2008-05-12 22:18 ` Andrew Morton [not found] ` <20080512151805.4c2763b9.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> 2008-05-22 0:03 ` David Brownell 1 sibling, 1 reply; 5+ messages in thread From: Andrew Morton @ 2008-05-12 22:18 UTC (permalink / raw) To: Grant Likely Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f, linux-kernel-u79uwXL29TY76Z2rM5mHXA On Fri, 09 May 2008 11:32:28 -0600 Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@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. > > Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org> > --- > > drivers/spi/spi.c | 2 +- > include/linux/spi/spi.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c > index 1ad12af..bdf1b70 100644 > --- 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, > diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h > index 387e428..38a080b 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[KOBJ_NAME_LEN]; > > /* > * likely need more hooks for more protocol options affecting how I'm not really able to work out if this is a needed-in-2.6.26 thing. I assumed "not". ------------------------------------------------------------------------- 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] 5+ messages in thread
[parent not found: <20080512151805.4c2763b9.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>]
* Re: [PATCH/RFC] spi: Change modalias from a pointer to a character array [not found] ` <20080512151805.4c2763b9.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> @ 2008-05-12 22:20 ` Grant Likely [not found] ` <fa686aa40805121520y979ee37ga83221b74b35afe1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Grant Likely @ 2008-05-12 22:20 UTC (permalink / raw) To: Andrew Morton Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f, linux-kernel-u79uwXL29TY76Z2rM5mHXA On Mon, May 12, 2008 at 4:18 PM, Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> wrote: > > On Fri, 09 May 2008 11:32:28 -0600 > Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@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). > > <snip> > > I'm not really able to work out if this is a needed-in-2.6.26 thing. I > assumed "not". That's correct. I'm also not even 100% sure that this is the best approach. I'm waiting/hoping for feedback from David. 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] 5+ messages in thread
[parent not found: <fa686aa40805121520y979ee37ga83221b74b35afe1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH/RFC] spi: Change modalias from a pointer to a character array [not found] ` <fa686aa40805121520y979ee37ga83221b74b35afe1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-05-12 22:56 ` David Brownell 0 siblings, 0 replies; 5+ messages in thread From: David Brownell @ 2008-05-12 22:56 UTC (permalink / raw) To: Grant Likely Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Andrew Morton, linux-kernel-u79uwXL29TY76Z2rM5mHXA On Monday 12 May 2008, Grant Likely wrote: > > > > I'm not really able to work out if this is a needed-in-2.6.26 thing. I > > assumed "not". > > That's correct. I'm also not even 100% sure that this is the best > approach. I'm waiting/hoping for feedback from David. You'll get some. Unlike your other patch, this one wasn't obvious and required me to burn a few grey cells ... ones which have been otherwise occupied. ;) - 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] 5+ messages in thread
* Re: [PATCH/RFC] spi: Change modalias from a pointer to a character array [not found] ` <20080509173146.2932.16141.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org> 2008-05-12 22:18 ` Andrew Morton @ 2008-05-22 0:03 ` David Brownell 1 sibling, 0 replies; 5+ messages in thread From: David Brownell @ 2008-05-22 0:03 UTC (permalink / raw) To: Grant Likely Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, linux-kernel-u79uwXL29TY76Z2rM5mHXA On Friday 09 May 2008, Grant Likely wrote: > 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. Looks fine to me. ------------------------------------------------------------------------- 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] 5+ messages in thread
end of thread, other threads:[~2008-05-22 0:03 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-05-09 17:32 [PATCH/RFC] spi: Change modalias from a pointer to a character array Grant Likely [not found] ` <20080509173146.2932.16141.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org> 2008-05-12 22:18 ` Andrew Morton [not found] ` <20080512151805.4c2763b9.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> 2008-05-12 22:20 ` Grant Likely [not found] ` <fa686aa40805121520y979ee37ga83221b74b35afe1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2008-05-12 22:56 ` David Brownell 2008-05-22 0:03 ` David Brownell
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).