Re: [iio:togreg 24/24] drivers/iio/adc/ad7298.c:125:23: sparse: incorrect type in assignment (different base types)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux