diff mbox

ALSA: hda/ca0132: Limit values for chip addresses to 32-bit

Message ID 20170316205223.16926-1-mka@chromium.org (mailing list archive)
State New, archived
Headers show

Commit Message

Matthias Kaehlcke March 16, 2017, 8:52 p.m. UTC
With the previous unsigned long value clang generates warnings like
this:

sound/pci/hda/patch_ca0132.c:860:37: error: implicit conversion from
  'unsigned long' to 'u32' (aka 'unsigned int') changes value from
  18446744073709551615 to 4294967295 [-Werror,-Wconstant-conversion]
        spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
                             ~             ^~~~

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 sound/pci/hda/patch_ca0132.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Takashi Iwai March 20, 2017, 9:33 a.m. UTC | #1
On Thu, 16 Mar 2017 21:52:23 +0100,
Matthias Kaehlcke wrote:
> 
> With the previous unsigned long value clang generates warnings like
> this:
> 
> sound/pci/hda/patch_ca0132.c:860:37: error: implicit conversion from
>   'unsigned long' to 'u32' (aka 'unsigned int') changes value from
>   18446744073709551615 to 4294967295 [-Werror,-Wconstant-conversion]
>         spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
>                              ~             ^~~~
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>

Thanks for the patch.  The changes look mostly OK, but...

> ---
>  sound/pci/hda/patch_ca0132.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
> index 11b9b2f17a2e..7175e2b46fc4 100644
> --- a/sound/pci/hda/patch_ca0132.c
> +++ b/sound/pci/hda/patch_ca0132.c
> @@ -857,7 +857,7 @@ static int chipio_write_address(struct hda_codec *codec,
>  				  chip_addx >> 16);
>  	}
>  
> -	spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
> +	spec->curr_chip_addx = (res < 0) ? (u32)~0U : chip_addx;

... I guess the cast to u32 is superfluous here?  That is, just
replace UL to U should work, I suppose.  (Ditto for all other places.)


Takashi
Matthias Kaehlcke April 1, 2017, 12:52 a.m. UTC | #2
Sorry for the delayed reply,

El Mon, Mar 20, 2017 at 10:33:43AM +0100 Takashi Iwai ha dit:

> On Thu, 16 Mar 2017 21:52:23 +0100,
> Matthias Kaehlcke wrote:
> > 
> > With the previous unsigned long value clang generates warnings like
> > this:
> > 
> > sound/pci/hda/patch_ca0132.c:860:37: error: implicit conversion from
> >   'unsigned long' to 'u32' (aka 'unsigned int') changes value from
> >   18446744073709551615 to 4294967295 [-Werror,-Wconstant-conversion]
> >         spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
> >                              ~             ^~~~
> > 
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> 
> Thanks for the patch.  The changes look mostly OK, but...
> 
> > ---
> >  sound/pci/hda/patch_ca0132.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
> > index 11b9b2f17a2e..7175e2b46fc4 100644
> > --- a/sound/pci/hda/patch_ca0132.c
> > +++ b/sound/pci/hda/patch_ca0132.c
> > @@ -857,7 +857,7 @@ static int chipio_write_address(struct hda_codec *codec,
> >  				  chip_addx >> 16);
> >  	}
> >  
> > -	spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
> > +	spec->curr_chip_addx = (res < 0) ? (u32)~0U : chip_addx;
> 
> ... I guess the cast to u32 is superfluous here?  That is, just
> replace UL to U should work, I suppose.  (Ditto for all other places.)

You are right, the cast is not needed. I'll send an updated version.

Cheers

Matthias
diff mbox

Patch

diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 11b9b2f17a2e..7175e2b46fc4 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -857,7 +857,7 @@  static int chipio_write_address(struct hda_codec *codec,
 				  chip_addx >> 16);
 	}
 
-	spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
+	spec->curr_chip_addx = (res < 0) ? (u32)~0U : chip_addx;
 
 	return res;
 }
@@ -882,7 +882,7 @@  static int chipio_write_data(struct hda_codec *codec, unsigned int data)
 	/*If no error encountered, automatically increment the address
 	as per chip behaviour*/
 	spec->curr_chip_addx = (res != -EIO) ?
-					(spec->curr_chip_addx + 4) : ~0UL;
+					(spec->curr_chip_addx + 4) : (u32)~0U;
 	return res;
 }
 
@@ -933,7 +933,7 @@  static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
 	/*If no error encountered, automatically increment the address
 	as per chip behaviour*/
 	spec->curr_chip_addx = (res != -EIO) ?
-					(spec->curr_chip_addx + 4) : ~0UL;
+					(spec->curr_chip_addx + 4) : (u32)~0U;
 	return res;
 }