diff mbox series

[v1,2/3] usb: early: xhci-dbc: Move cpu_to_le16_array() to core

Message ID 20200817164226.49119-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/3] usb: early: xhci-dbc: use readl_poll_timeout() to simplify code | expand

Commit Message

Andy Shevchenko Aug. 17, 2020, 4:42 p.m. UTC
It's used in USB but it might be useful for other drivers as well.
While at it, introduce a counterpart helper, i.e. le16_to_cpu_array().

Make them available through byteorder/generic.h.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/early/xhci-dbc.c      | 15 ++++-----------
 include/linux/byteorder/generic.h | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 11 deletions(-)

Comments

Greg KH Aug. 17, 2020, 4:51 p.m. UTC | #1
On Mon, Aug 17, 2020 at 07:42:25PM +0300, Andy Shevchenko wrote:
> It's used in USB but it might be useful for other drivers as well.

Don't move it unless someone actually needs it.

> While at it, introduce a counterpart helper, i.e. le16_to_cpu_array().

Don't add something that no one uses, otherwise it will just be removed.

thanks,

greg k-h
Andy Shevchenko Aug. 17, 2020, 6:27 p.m. UTC | #2
On Mon, Aug 17, 2020 at 06:51:03PM +0200, Greg Kroah-Hartman wrote:
> On Mon, Aug 17, 2020 at 07:42:25PM +0300, Andy Shevchenko wrote:
> > It's used in USB but it might be useful for other drivers as well.
> 
> Don't move it unless someone actually needs it.
> 
> > While at it, introduce a counterpart helper, i.e. le16_to_cpu_array().
> 
> Don't add something that no one uses, otherwise it will just be removed.

I will address both by converting real users of them besides this driver.
kernel test robot Aug. 17, 2020, 9:51 p.m. UTC | #3
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on peter.chen-usb/ci-for-usb-next balbi-usb/testing/next linus/master v5.9-rc1 next-20200817]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/usb-early-xhci-dbc-use-readl_poll_timeout-to-simplify-code/20200818-004710
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: x86_64-randconfig-r014-20200817 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project de71b46a519db014ce906a39f8a0e1b235ef1568)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from drivers/usb/early/xhci-dbc.c:12:
   include/linux/byteorder/generic.h:144:33: error: unknown type name '__le16'
   static inline void le16_add_cpu(__le16 *var, u16 val)
                                   ^
   include/linux/byteorder/generic.h:144:46: error: unknown type name 'u16'
   static inline void le16_add_cpu(__le16 *var, u16 val)
                                                ^
>> include/linux/byteorder/generic.h:146:9: error: implicit declaration of function '__cpu_to_le16' [-Werror,-Wimplicit-function-declaration]
           *var = cpu_to_le16(le16_to_cpu(*var) + val);
                  ^
   include/linux/byteorder/generic.h:90:21: note: expanded from macro 'cpu_to_le16'
   #define cpu_to_le16 __cpu_to_le16
                       ^
>> include/linux/byteorder/generic.h:146:21: error: implicit declaration of function '__le16_to_cpu' [-Werror,-Wimplicit-function-declaration]
           *var = cpu_to_le16(le16_to_cpu(*var) + val);
                              ^
   include/linux/byteorder/generic.h:91:21: note: expanded from macro 'le16_to_cpu'
   #define le16_to_cpu __le16_to_cpu
                       ^
   include/linux/byteorder/generic.h:149:33: error: unknown type name '__le32'
   static inline void le32_add_cpu(__le32 *var, u32 val)
                                   ^
   include/linux/byteorder/generic.h:149:46: error: unknown type name 'u32'
   static inline void le32_add_cpu(__le32 *var, u32 val)
                                                ^
>> include/linux/byteorder/generic.h:151:9: error: implicit declaration of function '__cpu_to_le32' [-Werror,-Wimplicit-function-declaration]
           *var = cpu_to_le32(le32_to_cpu(*var) + val);
                  ^
   include/linux/byteorder/generic.h:88:21: note: expanded from macro 'cpu_to_le32'
   #define cpu_to_le32 __cpu_to_le32
                       ^
>> include/linux/byteorder/generic.h:151:21: error: implicit declaration of function '__le32_to_cpu' [-Werror,-Wimplicit-function-declaration]
           *var = cpu_to_le32(le32_to_cpu(*var) + val);
                              ^
   include/linux/byteorder/generic.h:89:21: note: expanded from macro 'le32_to_cpu'
   #define le32_to_cpu __le32_to_cpu
                       ^
   include/linux/byteorder/generic.h:154:33: error: unknown type name '__le64'
   static inline void le64_add_cpu(__le64 *var, u64 val)
                                   ^
   include/linux/byteorder/generic.h:154:46: error: unknown type name 'u64'
   static inline void le64_add_cpu(__le64 *var, u64 val)
                                                ^
>> include/linux/byteorder/generic.h:156:9: error: implicit declaration of function '__cpu_to_le64' [-Werror,-Wimplicit-function-declaration]
           *var = cpu_to_le64(le64_to_cpu(*var) + val);
                  ^
   include/linux/byteorder/generic.h:86:21: note: expanded from macro 'cpu_to_le64'
   #define cpu_to_le64 __cpu_to_le64
                       ^
>> include/linux/byteorder/generic.h:156:21: error: implicit declaration of function '__le64_to_cpu' [-Werror,-Wimplicit-function-declaration]
           *var = cpu_to_le64(le64_to_cpu(*var) + val);
                              ^
   include/linux/byteorder/generic.h:87:21: note: expanded from macro 'le64_to_cpu'
   #define le64_to_cpu __le64_to_cpu
                       ^
   include/linux/byteorder/generic.h:159:38: error: unknown type name '__le16'
   static inline void cpu_to_le16_array(__le16 *dst, const u16 *src, size_t len)
                                        ^
   include/linux/byteorder/generic.h:159:57: error: unknown type name 'u16'
   static inline void cpu_to_le16_array(__le16 *dst, const u16 *src, size_t len)
                                                           ^
   include/linux/byteorder/generic.h:159:67: error: unknown type name 'size_t'
   static inline void cpu_to_le16_array(__le16 *dst, const u16 *src, size_t len)
                                                                     ^
   include/linux/byteorder/generic.h:164:12: error: implicit declaration of function '__cpu_to_le16' [-Werror,-Wimplicit-function-declaration]
                   dst[i] = cpu_to_le16(src[i]);
                            ^
   include/linux/byteorder/generic.h:90:21: note: expanded from macro 'cpu_to_le16'
   #define cpu_to_le16 __cpu_to_le16
                       ^
   include/linux/byteorder/generic.h:167:38: error: unknown type name 'u16'
   static inline void le16_to_cpu_array(u16 *dst, const __le16 *src, size_t len)
                                        ^
   include/linux/byteorder/generic.h:167:54: error: unknown type name '__le16'
   static inline void le16_to_cpu_array(u16 *dst, const __le16 *src, size_t len)
                                                        ^
   include/linux/byteorder/generic.h:167:67: error: unknown type name 'size_t'
   static inline void le16_to_cpu_array(u16 *dst, const __le16 *src, size_t len)
                                                                     ^
   fatal error: too many errors emitted, stopping now [-ferror-limit=]
   20 errors generated.

# https://github.com/0day-ci/linux/commit/379f669600c31fef2fa3b729ebb9ecf706d69621
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andy-Shevchenko/usb-early-xhci-dbc-use-readl_poll_timeout-to-simplify-code/20200818-004710
git checkout 379f669600c31fef2fa3b729ebb9ecf706d69621
vim +/__cpu_to_le16 +146 include/linux/byteorder/generic.h

^1da177e4c3f415 Linus Torvalds 2005-04-16  143  
8b5f6883683c91a Marcin Slusarz 2008-02-08  144  static inline void le16_add_cpu(__le16 *var, u16 val)
8b5f6883683c91a Marcin Slusarz 2008-02-08  145  {
8b5f6883683c91a Marcin Slusarz 2008-02-08 @146  	*var = cpu_to_le16(le16_to_cpu(*var) + val);
8b5f6883683c91a Marcin Slusarz 2008-02-08  147  }
8b5f6883683c91a Marcin Slusarz 2008-02-08  148  
8b5f6883683c91a Marcin Slusarz 2008-02-08  149  static inline void le32_add_cpu(__le32 *var, u32 val)
8b5f6883683c91a Marcin Slusarz 2008-02-08  150  {
8b5f6883683c91a Marcin Slusarz 2008-02-08 @151  	*var = cpu_to_le32(le32_to_cpu(*var) + val);
8b5f6883683c91a Marcin Slusarz 2008-02-08  152  }
8b5f6883683c91a Marcin Slusarz 2008-02-08  153  
8b5f6883683c91a Marcin Slusarz 2008-02-08  154  static inline void le64_add_cpu(__le64 *var, u64 val)
8b5f6883683c91a Marcin Slusarz 2008-02-08  155  {
8b5f6883683c91a Marcin Slusarz 2008-02-08 @156  	*var = cpu_to_le64(le64_to_cpu(*var) + val);
8b5f6883683c91a Marcin Slusarz 2008-02-08  157  }
8b5f6883683c91a Marcin Slusarz 2008-02-08  158  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
index 77c2e8301971..c5761ea9394d 100644
--- a/drivers/usb/early/xhci-dbc.c
+++ b/drivers/usb/early/xhci-dbc.c
@@ -9,6 +9,7 @@ 
 
 #define pr_fmt(fmt)	KBUILD_MODNAME ":%s: " fmt, __func__
 
+#include <linux/byteorder/generic.h>
 #include <linux/console.h>
 #include <linux/pci_regs.h>
 #include <linux/pci_ids.h>
@@ -200,14 +201,6 @@  static void xdbc_reset_ring(struct xdbc_ring *ring)
 	}
 }
 
-static inline void xdbc_put_utf16(u16 *s, const char *c, size_t size)
-{
-	int i;
-
-	for (i = 0; i < size; i++)
-		s[i] = cpu_to_le16(c[i]);
-}
-
 static void xdbc_mem_init(void)
 {
 	struct xdbc_ep_context *ep_in, *ep_out;
@@ -263,7 +256,7 @@  static void xdbc_mem_init(void)
 	s_desc->bLength		= (strlen(XDBC_STRING_SERIAL) + 1) * 2;
 	s_desc->bDescriptorType	= USB_DT_STRING;
 
-	xdbc_put_utf16(s_desc->wData, XDBC_STRING_SERIAL, strlen(XDBC_STRING_SERIAL));
+	cpu_to_le16_array(s_desc->wData, XDBC_STRING_SERIAL, strlen(XDBC_STRING_SERIAL));
 	string_length = s_desc->bLength;
 	string_length <<= 8;
 
@@ -272,7 +265,7 @@  static void xdbc_mem_init(void)
 	s_desc->bLength		= (strlen(XDBC_STRING_PRODUCT) + 1) * 2;
 	s_desc->bDescriptorType	= USB_DT_STRING;
 
-	xdbc_put_utf16(s_desc->wData, XDBC_STRING_PRODUCT, strlen(XDBC_STRING_PRODUCT));
+	cpu_to_le16_array(s_desc->wData, XDBC_STRING_PRODUCT, strlen(XDBC_STRING_PRODUCT));
 	string_length += s_desc->bLength;
 	string_length <<= 8;
 
@@ -281,7 +274,7 @@  static void xdbc_mem_init(void)
 	s_desc->bLength		= (strlen(XDBC_STRING_MANUFACTURER) + 1) * 2;
 	s_desc->bDescriptorType	= USB_DT_STRING;
 
-	xdbc_put_utf16(s_desc->wData, XDBC_STRING_MANUFACTURER, strlen(XDBC_STRING_MANUFACTURER));
+	cpu_to_le16_array(s_desc->wData, XDBC_STRING_MANUFACTURER, strlen(XDBC_STRING_MANUFACTURER));
 	string_length += s_desc->bLength;
 	string_length <<= 8;
 
diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h
index 4b13e0a3e15b..24904ad79df0 100644
--- a/include/linux/byteorder/generic.h
+++ b/include/linux/byteorder/generic.h
@@ -156,6 +156,22 @@  static inline void le64_add_cpu(__le64 *var, u64 val)
 	*var = cpu_to_le64(le64_to_cpu(*var) + val);
 }
 
+static inline void cpu_to_le16_array(__le16 *dst, const u16 *src, size_t len)
+{
+	int i;
+
+	for (i = 0; i < len; i++)
+		dst[i] = cpu_to_le16(src[i]);
+}
+
+static inline void le16_to_cpu_array(u16 *dst, const __le16 *src, size_t len)
+{
+	int i;
+
+	for (i = 0; i < len; i++)
+		dst[i] = le16_to_cpu(src[i]);
+}
+
 /* XXX: this stuff can be optimized */
 static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
 {