Staging: comedi: Fix sparse warnings
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
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
@@ -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
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.Signed-off-by Ksenija Stanojevic <[email protected]>---
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
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.Signed-off-by Ksenija Stanojevic <[email protected]>---
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
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.Signed-off-by Ksenija Stanojevic <[email protected]>---
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
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.Signed-off-by Ksenija Stanojevic <[email protected]>---
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
PATCH 2/2 Staging: comedi: adl_pci9118: Fix endian sparse warning
In reply to Ksenija StanojevicFix 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
@@ -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