From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: Chen Gong <G.Chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Cc: david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org,
linuxppc-dev-mnsaURCQ41sdnm+yROfE0A@public.gmane.org,
fabrizio.garetto-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH v2 4/5] spi: Add OF binding support for SPI busses
Date: Thu, 3 Jul 2008 22:17:58 -0600 [thread overview]
Message-ID: <20080704041758.GH12945@secretlab.ca> (raw)
In-Reply-To: <58A20A281BAF1047B4EAE68DE5C0BDC2010121B7-bKEhWGtIRULiD3AT8lUqWFjVikpgYyvb5NbjCUgZEJk@public.gmane.org>
On Fri, Jul 04, 2008 at 11:54:57AM +0800, Chen Gong wrote:
> Grant Likely wrote:
> > + /* Mode (clock phase/polarity/etc.) */
> > + if (of_find_property(nc, "spi,cpha", NULL))
> > + spi->mode |= SPI_CPHA;
> > + if (of_find_property(nc, "spi,cpol", NULL))
> > + spi->mode |= SPI_CPOL;
>
> so becuase in function spi_alloc_deive, spi is allocated by kzalloc,
> how about writing as follows:
> /* Mode (clock phase/polarity/etc.) */
> prop = of_get_property(nc, "spi,cpha", NULL))
> if (prop)
> spi->mode |= *prop;
> prop = of_get_property(nc, "spi,cpol", NULL))
> if (prop)
> spi->mode |= *prop;
spi,cpha and spi,cpol are defined as empty properties. The presence of
the property in the node means I need to set the flag in the spi_device.
> > + /* Select device driver */
> > + sprop = of_get_property(nc, "linux,modalias", &len);
> > + if (sprop && len > 0)
> > + strncpy(spi->modalias, sprop, KOBJ_NAME_LEN);
> > + else
> > + strncpy(spi->modalias, "spidev", KOBJ_NAME_LEN);
> > +
> how about writing as follows:
>
> if (sprop && len > 0)
> strncpy(spi->modalias, sprop, KOBJ_NAME_LEN -
> 1);
> else
> strncpy(spi->modalias, "spidev", KOBJ_NAME_LEN -
> 1);
Actually, neither are very good. What it should really be is:
if (sprop && len > 0)
strlcpy(spi->modalias, sprop, sizeof (spi->modalias));
else
strlcpy(spi->modalias, "spidev", sizeof (spi->modalias));
This ensures that the string is always null terminated and always the
right size.
... But the whole argument is a bit moot. The fact that I even defined
a "linux,modalias" property is a great big hairy hack that I would
never want my mother to see. Instead, I need a method to bind to an SPI
driver based on the compatible list. Jon Smirl has done some work
in this regard for i2c, but I haven't looked at it very deeply, and so
do not at all understand it (yet).
Thanks for the comments.
g.
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
WARNING: multiple messages have this Message-ID (diff)
From: Grant Likely <grant.likely@secretlab.ca>
To: Chen Gong <G.Chen@freescale.com>
Cc: david-b@pacbell.net, linuxppc-dev@ozlabs.org,
fabrizio.garetto@gmail.com, linux-kernel@vger.kernel.org,
spi-devel-general@lists.sourceforge.net
Subject: Re: [PATCH v2 4/5] spi: Add OF binding support for SPI busses
Date: Thu, 3 Jul 2008 22:17:58 -0600 [thread overview]
Message-ID: <20080704041758.GH12945@secretlab.ca> (raw)
In-Reply-To: <58A20A281BAF1047B4EAE68DE5C0BDC2010121B7@zch01exm21.fsl.freescale.net>
On Fri, Jul 04, 2008 at 11:54:57AM +0800, Chen Gong wrote:
> Grant Likely wrote:
> > + /* Mode (clock phase/polarity/etc.) */
> > + if (of_find_property(nc, "spi,cpha", NULL))
> > + spi->mode |= SPI_CPHA;
> > + if (of_find_property(nc, "spi,cpol", NULL))
> > + spi->mode |= SPI_CPOL;
>
> so becuase in function spi_alloc_deive, spi is allocated by kzalloc,
> how about writing as follows:
> /* Mode (clock phase/polarity/etc.) */
> prop = of_get_property(nc, "spi,cpha", NULL))
> if (prop)
> spi->mode |= *prop;
> prop = of_get_property(nc, "spi,cpol", NULL))
> if (prop)
> spi->mode |= *prop;
spi,cpha and spi,cpol are defined as empty properties. The presence of
the property in the node means I need to set the flag in the spi_device.
> > + /* Select device driver */
> > + sprop = of_get_property(nc, "linux,modalias", &len);
> > + if (sprop && len > 0)
> > + strncpy(spi->modalias, sprop, KOBJ_NAME_LEN);
> > + else
> > + strncpy(spi->modalias, "spidev", KOBJ_NAME_LEN);
> > +
> how about writing as follows:
>
> if (sprop && len > 0)
> strncpy(spi->modalias, sprop, KOBJ_NAME_LEN -
> 1);
> else
> strncpy(spi->modalias, "spidev", KOBJ_NAME_LEN -
> 1);
Actually, neither are very good. What it should really be is:
if (sprop && len > 0)
strlcpy(spi->modalias, sprop, sizeof (spi->modalias));
else
strlcpy(spi->modalias, "spidev", sizeof (spi->modalias));
This ensures that the string is always null terminated and always the
right size.
... But the whole argument is a bit moot. The fact that I even defined
a "linux,modalias" property is a great big hairy hack that I would
never want my mother to see. Instead, I need a method to bind to an SPI
driver based on the compatible list. Jon Smirl has done some work
in this regard for i2c, but I haven't looked at it very deeply, and so
do not at all understand it (yet).
Thanks for the comments.
g.
WARNING: multiple messages have this Message-ID (diff)
From: Grant Likely <grant.likely@secretlab.ca>
To: Chen Gong <G.Chen@freescale.com>
Cc: david-b@pacbell.net, fabrizio.garetto@gmail.com,
linuxppc-dev@ozlabs.org, spi-devel-general@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/5] spi: Add OF binding support for SPI busses
Date: Thu, 3 Jul 2008 22:17:58 -0600 [thread overview]
Message-ID: <20080704041758.GH12945@secretlab.ca> (raw)
In-Reply-To: <58A20A281BAF1047B4EAE68DE5C0BDC2010121B7@zch01exm21.fsl.freescale.net>
On Fri, Jul 04, 2008 at 11:54:57AM +0800, Chen Gong wrote:
> Grant Likely wrote:
> > + /* Mode (clock phase/polarity/etc.) */
> > + if (of_find_property(nc, "spi,cpha", NULL))
> > + spi->mode |= SPI_CPHA;
> > + if (of_find_property(nc, "spi,cpol", NULL))
> > + spi->mode |= SPI_CPOL;
>
> so becuase in function spi_alloc_deive, spi is allocated by kzalloc,
> how about writing as follows:
> /* Mode (clock phase/polarity/etc.) */
> prop = of_get_property(nc, "spi,cpha", NULL))
> if (prop)
> spi->mode |= *prop;
> prop = of_get_property(nc, "spi,cpol", NULL))
> if (prop)
> spi->mode |= *prop;
spi,cpha and spi,cpol are defined as empty properties. The presence of
the property in the node means I need to set the flag in the spi_device.
> > + /* Select device driver */
> > + sprop = of_get_property(nc, "linux,modalias", &len);
> > + if (sprop && len > 0)
> > + strncpy(spi->modalias, sprop, KOBJ_NAME_LEN);
> > + else
> > + strncpy(spi->modalias, "spidev", KOBJ_NAME_LEN);
> > +
> how about writing as follows:
>
> if (sprop && len > 0)
> strncpy(spi->modalias, sprop, KOBJ_NAME_LEN -
> 1);
> else
> strncpy(spi->modalias, "spidev", KOBJ_NAME_LEN -
> 1);
Actually, neither are very good. What it should really be is:
if (sprop && len > 0)
strlcpy(spi->modalias, sprop, sizeof (spi->modalias));
else
strlcpy(spi->modalias, "spidev", sizeof (spi->modalias));
This ensures that the string is always null terminated and always the
right size.
... But the whole argument is a bit moot. The fact that I even defined
a "linux,modalias" property is a great big hairy hack that I would
never want my mother to see. Instead, I need a method to bind to an SPI
driver based on the compatible list. Jon Smirl has done some work
in this regard for i2c, but I haven't looked at it very deeply, and so
do not at all understand it (yet).
Thanks for the comments.
g.
next prev parent reply other threads:[~2008-07-04 4:17 UTC|newest]
Thread overview: 42+ 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
2008-07-03 1:02 ` Grant Likely
[not found] ` <20080703005749.26187.71719.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org>
2008-07-03 1:02 ` [PATCH v2 1/5] spi: Change modalias from a pointer to a character array Grant Likely
2008-07-03 1:02 ` Grant Likely
2008-07-03 1:02 ` Grant Likely
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 ` Grant Likely
2008-07-03 1:03 ` 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-03 1:03 ` Grant Likely
2008-07-03 1:03 ` Grant Likely
[not found] ` <20080703010308.26187.23037.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org>
2008-07-04 3:59 ` [PATCH v2 3/5] of-bindings: Add binding documentation for SPI bussesand devices Chen Gong
2008-07-04 3:59 ` Chen Gong
2008-07-04 3:59 ` Chen Gong
[not found] ` <58A20A281BAF1047B4EAE68DE5C0BDC2010121B9-bKEhWGtIRULiD3AT8lUqWFjVikpgYyvb5NbjCUgZEJk@public.gmane.org>
2008-07-04 4:05 ` Grant Likely
2008-07-04 4:05 ` Grant Likely
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:36 ` Segher Boessenkool
2008-07-04 23:36 ` Segher Boessenkool
[not found] ` <1694b01b1b41f244e565298b430f021c-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
2008-07-04 23:42 ` Grant Likely
2008-07-04 23:42 ` Grant Likely
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 1:03 ` Grant Likely
2008-07-03 1:03 ` Grant Likely
[not found] ` <20080703010313.26187.99119.stgit-8FIgwK2HfyId2tlXD8uQ6/kpB+XfMlBf@public.gmane.org>
2008-07-03 3:02 ` Jon Smirl
2008-07-03 3:02 ` Jon Smirl
2008-07-03 3:02 ` Jon Smirl
[not found] ` <9e4733910807022002n3c739c7cs8ed642e4a6027bb6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-12 5:21 ` Grant Likely
2008-07-12 5:21 ` Grant Likely
2008-07-12 5:21 ` Grant Likely
2008-07-04 3:54 ` Chen Gong
2008-07-04 3:54 ` Chen Gong
2008-07-04 3:54 ` Chen Gong
[not found] ` <58A20A281BAF1047B4EAE68DE5C0BDC2010121B7-bKEhWGtIRULiD3AT8lUqWFjVikpgYyvb5NbjCUgZEJk@public.gmane.org>
2008-07-04 4:17 ` Grant Likely [this message]
2008-07-04 4:17 ` Grant Likely
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
2008-07-03 1:03 ` Grant Likely
2008-07-03 1:03 ` 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=20080704041758.GH12945@secretlab.ca \
--to=grant.likely-s3s/wqlpoipyb63q8fvjnq@public.gmane.org \
--cc=G.Chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
--cc=david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org \
--cc=fabrizio.garetto-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linuxppc-dev-mnsaURCQ41sdnm+yROfE0A@public.gmane.org \
--cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.