Re: [PATCH] staging: usbip: fixed a coding-style warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 18, 2014 at 12:17:55AM -0700, Joe Perches wrote:
> On Wed, 2014-06-18 at 00:06 -0700, Greg Kroah-Hartman wrote:
> > On Wed, Jun 18, 2014 at 09:49:39AM +0300, Alexey Tulia wrote:
> > > On Tue, Jun 17, 2014 at 03:44:58PM -0700, Greg Kroah-Hartman wrote:
> > > > On Fri, Jun 13, 2014 at 11:35:13AM +0300, Alexey Tulia wrote:
> > > > > This fixes the following warning:
> > > > > 	- WARNING: __constant_cpu_to_le32 should be cpu_to_le32
> > > > 
> > > > What produces this warning?
> > > > 
> > > 
> > > This warning was found by checkpatch.pl -f
> > > 
> > > > > 
> > > > > Signed-off-by: Alexey Tulia <alexey.tulia@xxxxxxxxx>
> > > > > ---
> > > > >  drivers/staging/usbip/vhci_hcd.c | 2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
> > > > > index 0007d30..e21c1b4 100644
> > > > > --- a/drivers/staging/usbip/vhci_hcd.c
> > > > > +++ b/drivers/staging/usbip/vhci_hcd.c
> > > > > @@ -304,7 +304,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> > > > >  		break;
> > > > >  	case GetHubStatus:
> > > > >  		usbip_dbg_vhci_rh(" GetHubStatus\n");
> > > > > -		*(__le32 *) buf = __constant_cpu_to_le32(0);
> > > > > +		*(__le32 *) buf = cpu_to_le32(0);
> > > > 
> > > > How is this correct?  Why shouldn't __constant_cpu_to_le32() be used
> > > > here?  Heck, why can't we just use 0 given that it doesn't matter the
> > > > endianness of that specific value :)
> > > 
> > > It may be so, but anyway the __constant_cpu_to_le32 produced a warning
> > > and it was obvious to clean up this part of code a bit.
> > > However, the 0 value possibly can change to other value in future and
> > > this macro acts as a safety net here. 
> > 
> > Dragging Joe in here as he wrote that checkpatch feature.
> > 
> > Joe, how is not using __constant_cpu_to_* a good thing?  If I have a
> > constant value, cpu_to_* will be a function call if the bits have to be
> > switched around (no-op if not).  I don't see the code path that detects
> > a constant value and calls the swap-bits-as-a-constant macro instead,
> > unless the __constant_cpu_to* function is called.
> > 
> > Am I just missing it somewhere in the .h include chain?
> 
> Probably.
> 
> There a __builtin_constant_p check in there via the
> include/uapi/linux/swab.h chain.
> 
> for instance:
> 
> htonl ->
> ___htonl ->
> __cpu_to_be32
> __constant_htonl ->
> __swab32 ->
> 
> include/uapi/linux/swab.h:#define __swab32(x)                           \
> include/uapi/linux/swab.h-      (__builtin_constant_p((__u32)(x)) ?     \
> include/uapi/linux/swab.h-      ___constant_swab32(x) :                 \
> include/uapi/linux/swab.h-      __fswab32(x))

Ah, ok, my fault, sorry for the noise.  I'll go queue this patch up in a
bit...

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux