Skip to contentSkip to conversation

Staging: comedi: Fix sparse warnings

PATCH Superseded Ksenija Stanojevic 2 participants 7 messages Oct 30, 2015 – Oct 31, 2015 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Staging: comedi: Fix sparse warnings

Fix sparse endian warnings in ni_mio_common and adl_pci9118.

I didn't fix warnings of ni_pcimio driver because it seems more complex and one solution that I see is to change struct ni_private with adding a new field (unsigned int), but I don't know if that's a valid solution.

Ksenija Stanojevic (2):
Staging: comedi: ni_mio_common: Fix endian sparse warning
Staging: comedi: adl_pci9118: Fix endian sparse warning

 drivers/staging/comedi/drivers/adl_pci9118.c   |  3 ++-
 drivers/staging/comedi/drivers/ni_mio_common.c | 14 +++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 Staging: comedi: ni_mio_common: Fix endian sparse warning

Data is pointer of type void and can be used to store any type of data. In function ni_ai_munge:
barray and array have the same 16 bit offset.
blarray and larray have the same 32 bit offset.

---
Note:
This function even before my changes had a lot of build warnings.
I think it's because some config options are not enabled, but I
might be wrong.
Also I think I introduced new warnings because PCIDMA is not set:
drivers/staging/comedi/drivers/ni_mio_common.c:1520:10: warning: unused variable ‘blarray’ [-Wunused-variable]

  __le32 *blarray = data;
          ^

drivers/staging/comedi/drivers/ni_mio_common.c:1519:10: warning: unused variable ‘barray’ [-Wunused-variable]
__le16 *barray = data;

 drivers/staging/comedi/drivers/ni_mio_common.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/staging/comedi/drivers/ni_mio_common.c +9 -5
index 6cc304a..0c034f2 100644
@@ -1516,13 +1516,15 @@ static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s,
 	unsigned short *array = data;
 	unsigned int *larray = data;
 	unsigned int i;
+	__le16 *barray = data;
+	__le32 *blarray = data;
 
 	for (i = 0; i < nsamples; i++) {
 #ifdef PCIDMA
 		if (s->subdev_flags & SDF_LSAMPL)
-			larray[i] = le32_to_cpu(larray[i]);
+			larray[i] = le32_to_cpu(blarray[i]);
 		else
-			array[i] = le16_to_cpu(array[i]);
+			array[i] = le16_to_cpu(barray[i]);
 #endif
 		if (s->subdev_flags & SDF_LSAMPL)
 			larray[i] += devpriv->ai_offset[chan_index];
@@ -2574,6 +2576,7 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
 	unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes);
 	unsigned short *array = data;
 	unsigned int i;
+	__le16 buf, *barray = data;
 
 	for (i = 0; i < nsamples; i++) {
 		unsigned int range = CR_RANGE(cmd->chanlist[chan_index]);
@@ -2586,10 +2589,11 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
 		if (comedi_range_is_bipolar(s, range))
 			val = comedi_offset_munge(s, val);
 #ifdef PCIDMA
-		val = cpu_to_le16(val);
-#endif
+		buf = cpu_to_le16(val);
+		barray[i] = buf;
+#else
 		array[i] = val;
-
+#endif
 		chan_index++;
 		chan_index %= cmd->chanlist_len;
 	}
Signature · 1 line
1.9.1
#2 lore raw

Re: [Outreachy kernel] [PATCH 1/2] Staging: comedi: ni_mio_common: Fix endian sparse warning

Quoted 7 lines · Ksenija Stanojevic

Data is pointer of type void and can be used to store any type of data. In function ni_ai_munge:
barray and array have the same 16 bit offset.
blarray and larray have the same 32 bit offset.

---

Yes, it introduces build warning. You will have to do the change in such a way that it does not introduce any new warnings.

regards
sudip

#3 lore raw

Re: [Outreachy kernel] [PATCH 1/2] Staging: comedi: ni_mio_common: Fix endian sparse warning

HI Sudip,

Quoted 11 lines · Sudip Mukherjee
Quoted 7 lines · Ksenija Stanojevic

Data is pointer of type void and can be used to store any type of data. In function ni_ai_munge:
barray and array have the same 16 bit offset.
blarray and larray have the same 32 bit offset.

---

Yes, it introduces build warning. You will have to do the change in such a way that it does not introduce any new warnings.

My idea was to place declaration of buf and barray within #ifdef PCIDMA but in that case I have a new warning:
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
__le16 buf, *barray = data;
^

So, I'm not sure what to do and if it's possible to avoid introducing warnings.

Ksenija

#4 lore raw

Re: [Outreachy kernel] [PATCH 1/2] Staging: comedi: ni_mio_common: Fix endian sparse warning

Quoted 16 lines · Ksenija Stanojević

HI Sudip,

Quoted 11 lines · Sudip Mukherjee
Quoted 7 lines · Ksenija Stanojevic

Data is pointer of type void and can be used to store any type of data. In function ni_ai_munge:
barray and array have the same 16 bit offset.
blarray and larray have the same 32 bit offset.

---

Yes, it introduces build warning. You will have to do the change in such a way that it does not introduce any new warnings.

Quoted 8 lines

My idea was to place declaration of buf and barray within #ifdef PCIDMA but in that case I have a new warning:
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]

   __le16 buf, *barray = data;
   ^

So, I'm not sure what to do and if it's possible to avoid introducing warnings.

Keep the declaration where you have kept it, add another #ifdef PCIDMA just before the declaration of buf and barray and #endif just after the declaration.

regards
sudip

#5 lore raw

Re: [Outreachy kernel] [PATCH 1/2] Staging: comedi: ni_mio_common: Fix endian sparse warning

Quoted 24 lines · Sudip Mukherjee
Quoted 23 lines · Ksenija Stanojević

HI Sudip,

Quoted 11 lines · Sudip Mukherjee
Quoted 7 lines · Ksenija Stanojevic

Data is pointer of type void and can be used to store any type of data. In function ni_ai_munge:
barray and array have the same 16 bit offset.
blarray and larray have the same 32 bit offset.

---

Yes, it introduces build warning. You will have to do the change in such a way that it does not introduce any new warnings.

My idea was to place declaration of buf and barray within #ifdef PCIDMA but in that case I have a new warning:
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]

   __le16 buf, *barray = data;
   ^
Quoted 5 lines
Quoted 1 line

So, I'm not sure what to do and if it's possible to avoid introducing warnings.

Keep the declaration where you have kept it, add another #ifdef PCIDMA just before the declaration of buf and barray and #endif just after the declaration.

Thanks!

Ksenija

#6 lore raw

PATCH 2/2 Staging: comedi: adl_pci9118: Fix endian sparse warning

In reply to Ksenija Stanojevic

Fix following sparse warning:
warning: cast to restricted __be16

Data is pointer of type void and can be used to store any type of data. barray and array have the same 16 bit offset.

---
 drivers/staging/comedi/drivers/adl_pci9118.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/comedi/drivers/adl_pci9118.c +2 -1
index 0dff1db..4437ea3 100644
@@ -603,10 +603,11 @@ static void pci9118_ai_munge(struct comedi_device *dev,
 	unsigned short *array = data;
 	unsigned int num_samples = comedi_bytes_to_samples(s, num_bytes);
 	unsigned int i;
+	__be16 *barray = data;
 
 	for (i = 0; i < num_samples; i++) {
 		if (devpriv->usedma)
-			array[i] = be16_to_cpu(array[i]);
+			array[i] = be16_to_cpu(barray[i]);
 		if (s->maxdata == 0xffff)
 			array[i] ^= 0x8000;
 		else
Signature · 1 line
1.9.1