linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: kbuild test robot <fengguang.wu@intel.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: [iio:togreg 24/24] drivers/iio/adc/ad7298.c:125:23: sparse: incorrect type in assignment (different base types)
Date: Sun, 18 Nov 2012 18:48:02 +0000	[thread overview]
Message-ID: <50A92D62.3060009@kernel.org> (raw)
In-Reply-To: <50A92AB4.3050707@kernel.org>

On 11/18/2012 06:36 PM, Jonathan Cameron wrote:
> On 11/18/2012 02:19 PM, Lars-Peter Clausen wrote:
>> On 11/18/2012 02:42 PM, Jonathan Cameron wrote:
>>> Hi Lars-Peter
>>>
>>> Hmm. currious. I'd not normally have that check on - for reference
>>> this only happens for me with CF="-D__CHECK_ENDIAN__" appeneded to my
>>> normal make for the kernel.
>>>
>>> Anyhow, initial thought was to change rx_buf and tx_buf to __be16.
>>> Can you see any issues with that?
>>>
>>
>> I actually had such a patch initially in my series, but removed it again, since
>> we are using the buffer as non __be16 in some places.
>>
>>> It clears the warnings out.
>>
>> But if sparse doesn't complain about those we are better of with the change I
>> guess.
> Hmm. I wonder if there is any marking for no endianness specified?
> Either that or we'll need to play games with a union to pull this off
> cleanly.
>
> For anyone reading this without the background.  This bit of code is filling
> a buffer with a mixture of big and cpu endian elements.  This buffer is described
> to userspace which can then do the conversions as necessary.
>
> For now I'm going to hold the patch I sent out as it's not a real fix, but
> rather a nasty work around of the problem.

As a quick stab at it, how about something like...

diff --git a/drivers/iio/adc/ad7298.c b/drivers/iio/adc/ad7298.c
index 441a9a2..258ba97 100644
--- a/drivers/iio/adc/ad7298.c
+++ b/drivers/iio/adc/ad7298.c
@@ -54,8 +54,11 @@ struct ad7298_state {
 	 * DMA (thus cache coherency maintenance) requires the
 	 * transfer buffers to live in their own cache lines.
 	 */
-	unsigned short			rx_buf[12] ____cacheline_aligned;
-	unsigned short			tx_buf[2];
+	union {
+		__be16                  rx_buf[12];
+		s64                     rx_ts[3];
+	} ____cacheline_aligned;
+	__be16			tx_buf[2];
 };

 #define AD7298_V_CHAN(index)						\
@@ -159,18 +162,15 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7298_state *st = iio_priv(indio_dev);
-	s64 time_ns = 0;
 	int b_sent;

 	b_sent = spi_sync(st->spi, &st->ring_msg);
 	if (b_sent)
 		goto done;

-	if (indio_dev->scan_timestamp) {
-		time_ns = iio_get_time_ns();
-		memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
-			&time_ns, sizeof(time_ns));
-	}
+	if (indio_dev->scan_timestamp)
+		st->rx_ts[(indio_dev->scan_bytes + sizeof(s64) - 1) / sizeof(s64)]
+			= iio_get_time_ns();

 	iio_push_to_buffers(indio_dev, (u8 *)st->rx_buf);


      reply	other threads:[~2012-11-18 18:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <50a787d6.NK04zL7PgCPbLOrx%fengguang.wu@intel.com>
2012-11-18 13:42 ` [iio:togreg 24/24] drivers/iio/adc/ad7298.c:125:23: sparse: incorrect type in assignment (different base types) Jonathan Cameron
2012-11-18 13:47   ` [PATCH] iio:adc:ad7298 Mark the rx and tx buffers as big endian Jonathan Cameron
2012-11-18 14:19   ` [iio:togreg 24/24] drivers/iio/adc/ad7298.c:125:23: sparse: incorrect type in assignment (different base types) Lars-Peter Clausen
2012-11-18 18:36     ` Jonathan Cameron
2012-11-18 18:48       ` Jonathan Cameron [this message]

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=50A92D62.3060009@kernel.org \
    --to=jic23@kernel.org \
    --cc=fengguang.wu@intel.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.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 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).