[PATCH 05/12] staging: comedi: s626: remove the uint16_t casts of the bit values

Ian Abbott abbotti at mev.co.uk
Tue Mar 26 20:28:34 UTC 2013


On 26/03/2013 18:23, H Hartley Sweeten wrote:
> There are a number of uint16_t casts used in the #define's of the
> constant bit field values as well as the calls to DEBIreplace().
> These cause a number of sparse warnings of the type:
>
> warning: cast truncates bits from constant value (ffff1cff becomes 1cff)
>
> Remove all of the casts and change the types of the parameters to
> DEBIreplace from uin16_t to unsigned int. This fixes all the warnings.
>
> Mask the values written to the P_DEBICMD register and read from the
> P_DEBIAD register with 0xffff. These registers are only 16-bits but
> are accessed with 32-bit instructions.

No, the values written to P_DEBICMD should be 32-bits, consisting of a 
16-bit address in the lower 16 bits and some control bits in the upper 
16 bits.

>
> Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
> Cc: Ian Abbott <abbotti at mev.co.uk>
> Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
> ---
>   drivers/staging/comedi/drivers/s626.c | 47 ++++++++++++---------------
>   drivers/staging/comedi/drivers/s626.h | 60 +++++++++++++++++------------------
>   2 files changed, 51 insertions(+), 56 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
> index 22ced23..33682a3 100644
> --- a/drivers/staging/comedi/drivers/s626.c
> +++ b/drivers/staging/comedi/drivers/s626.c
> @@ -239,20 +239,20 @@ static void DEBIwrite(struct comedi_device *dev, uint16_t addr, uint16_t wdata)
>    * specifies bits that are to be preserved, wdata is new value to be
>    * or'd with the masked original.
>    */
> -static void DEBIreplace(struct comedi_device *dev, uint16_t addr, uint16_t mask,
> -			uint16_t wdata)
> +static void DEBIreplace(struct comedi_device *dev, unsigned int addr,
> +			unsigned int mask, unsigned int wdata)
>   {
>   	struct s626_private *devpriv = dev->private;
>   	unsigned int val;
>
> -	writel(DEBI_CMD_RDWORD | addr, devpriv->mmio + P_DEBICMD);
> +	writel((DEBI_CMD_RDWORD | addr) & 0xffff, devpriv->mmio + P_DEBICMD);

That's wrong.  Should be:

	addr &= 0xffff;
	writel(DEBI_CMD_RDWORD | addr, devpriv->mmio + P_DEBICMD);

(two statements, so the truncated addr can be used below...)

>   	DEBItransfer(dev);
>
> -	writel(DEBI_CMD_WRWORD | addr, devpriv->mmio + P_DEBICMD);
> +	writel((DEBI_CMD_WRWORD | addr) & 0xffff, devpriv->mmio + P_DEBICMD);

	writel(DEBI_CMD_WRWORD | addr, devpriv->mmio + P_DEBICMD);

>   	val = readl(devpriv->mmio + P_DEBIAD);
>   	val &= mask;
>   	val |= wdata;
> -	writel(val, devpriv->mmio + P_DEBIAD);
> +	writel(val & 0xffff, devpriv->mmio + P_DEBIAD);
>   	DEBItransfer(dev);
>   }

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti at mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-



More information about the devel mailing list