diff mbox series

[2/2] gpio: Explicitly cast from __be16 to unsigned short

Message ID 20190721125259.13990-2-hm@bitlabs.co.za
State New
Headers show
Series [1/2] gpio: Replace usage of bare 'unsigned' with 'unsigned int' | expand

Commit Message

Hennie Muller July 21, 2019, 12:52 p.m. UTC
cpu_to_be16 returns a __be16 value. This does not break anything
but does cause sparse to generate unnecessary warnings.

Signed-off-by: Hennie Muller <hm@bitlabs.co.za>
---
 drivers/gpio/gpio-viperboard.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Linus Walleij Aug. 5, 2019, 9:10 a.m. UTC | #1
On Sun, Jul 21, 2019 at 2:53 PM Hennie Muller <hm@bitlabs.co.za> wrote:

> cpu_to_be16 returns a __be16 value. This does not break anything
> but does cause sparse to generate unnecessary warnings.
>
> Signed-off-by: Hennie Muller <hm@bitlabs.co.za>
(...)

> -       gbmsg->val = cpu_to_be16(dir << offset);
> -       gbmsg->mask = cpu_to_be16(0x0001 << offset);
> +       gbmsg->val = (__force u16)cpu_to_be16(dir << offset);
> +       gbmsg->mask = (__force u16)cpu_to_be16(0x0001 << offset);

Ugh I don't understand this.

Arnd: you know this better than me: is this the right thing to do
to get rid of sparse warnings from the code?

Yours,
Linus Walleij
Arnd Bergmann Aug. 5, 2019, 11:52 a.m. UTC | #2
On Mon, Aug 5, 2019 at 11:11 AM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Sun, Jul 21, 2019 at 2:53 PM Hennie Muller <hm@bitlabs.co.za> wrote:
>
> > cpu_to_be16 returns a __be16 value. This does not break anything
> > but does cause sparse to generate unnecessary warnings.
> >
> > Signed-off-by: Hennie Muller <hm@bitlabs.co.za>
> (...)
>
> > -       gbmsg->val = cpu_to_be16(dir << offset);
> > -       gbmsg->mask = cpu_to_be16(0x0001 << offset);
> > +       gbmsg->val = (__force u16)cpu_to_be16(dir << offset);
> > +       gbmsg->mask = (__force u16)cpu_to_be16(0x0001 << offset);
>
> Ugh I don't understand this.
>
> Arnd: you know this better than me: is this the right thing to do
> to get rid of sparse warnings from the code?

No, the structure should be modified to use __be16 fields instead of u16.

        Arnd
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c
index c301c1d56dd2..7ff80d18bb70 100644
--- a/drivers/gpio/gpio-viperboard.c
+++ b/drivers/gpio/gpio-viperboard.c
@@ -258,8 +258,8 @@  static int vprbrd_gpiob_setdir(struct vprbrd *vb, unsigned int offset,
 	int ret;
 
 	gbmsg->cmd = VPRBRD_GPIOB_CMD_SETDIR;
-	gbmsg->val = cpu_to_be16(dir << offset);
-	gbmsg->mask = cpu_to_be16(0x0001 << offset);
+	gbmsg->val = (__force u16)cpu_to_be16(dir << offset);
+	gbmsg->mask = (__force u16)cpu_to_be16(0x0001 << offset);
 
 	ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0),
 		VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_OUT, 0x0000,
@@ -321,8 +321,8 @@  static void vprbrd_gpiob_set(struct gpio_chip *chip,
 		mutex_lock(&vb->lock);
 
 		gbmsg->cmd = VPRBRD_GPIOB_CMD_SETVAL;
-		gbmsg->val = cpu_to_be16(value << offset);
-		gbmsg->mask = cpu_to_be16(0x0001 << offset);
+		gbmsg->val = (__force u16)cpu_to_be16(value << offset);
+		gbmsg->mask = (__force u16)cpu_to_be16(0x0001 << offset);
 
 		ret = usb_control_msg(vb->usb_dev,
 			usb_sndctrlpipe(vb->usb_dev, 0),