[v2] usb: typec: tcpm: Export partner Source Capabilities
diff mbox series

Message ID 20210214033052.1284385-1-kyletso@google.com
State New, archived
Headers show
Series
  • [v2] usb: typec: tcpm: Export partner Source Capabilities
Related show

Commit Message

Kyle Tso Feb. 14, 2021, 3:30 a.m. UTC
Export a function for other drivers to get the partner Source
Capabilities.

Signed-off-by: Kyle Tso <kyletso@google.com>
---
Changes since v1:
- add a put function to free the memory

 drivers/usb/typec/tcpm/tcpm.c | 34 ++++++++++++++++++++++++++++++++++
 include/linux/usb/tcpm.h      |  2 ++
 2 files changed, 36 insertions(+)

Comments

kernel test robot Feb. 14, 2021, 4:39 a.m. UTC | #1
Hi Kyle,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on v5.11-rc7 next-20210212]
[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/Kyle-Tso/usb-typec-tcpm-Export-partner-Source-Capabilities/20210214-113553
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: i386-randconfig-m021-20210214 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/a80af7a2f4fa112b43e7b2b262729a8e1b28c132
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kyle-Tso/usb-typec-tcpm-Export-partner-Source-Capabilities/20210214-113553
        git checkout a80af7a2f4fa112b43e7b2b262729a8e1b28c132
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

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 >>):

   drivers/usb/typec/tcpm/tcpm.c: In function 'tcpm_get_partner_src_caps':
>> drivers/usb/typec/tcpm/tcpm.c:5762:11: error: implicit declaration of function 'tcpm_copy_pdos' [-Werror=implicit-function-declaration]
    5762 |  nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps,
         |           ^~~~~~~~~~~~~~
   At top level:
   drivers/usb/typec/tcpm/tcpm.c:2106:39: warning: 'tcpm_altmode_ops' defined but not used [-Wunused-const-variable=]
    2106 | static const struct typec_altmode_ops tcpm_altmode_ops = {
         |                                       ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +/tcpm_copy_pdos +5762 drivers/usb/typec/tcpm/tcpm.c

  5741	
  5742	/*
  5743	 * Don't call this function in interrupt context. Caller needs to free the
  5744	 * memory by calling tcpm_put_partner_src_caps.
  5745	 */
  5746	int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **src_pdo)
  5747	{
  5748		unsigned int nr_pdo;
  5749	
  5750		mutex_lock(&port->lock);
  5751		if (port->nr_source_caps == 0) {
  5752			mutex_unlock(&port->lock);
  5753			return -ENODATA;
  5754		}
  5755	
  5756		*src_pdo = kcalloc(port->nr_source_caps, sizeof(u32), GFP_KERNEL);
  5757		if (!src_pdo) {
  5758			mutex_unlock(&port->lock);
  5759			return -ENOMEM;
  5760		}
  5761	
> 5762		nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps,
  5763					port->nr_source_caps);
  5764		mutex_unlock(&port->lock);
  5765		return nr_pdo;
  5766	}
  5767	EXPORT_SYMBOL_GPL(tcpm_get_partner_src_caps);
  5768	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Feb. 14, 2021, 6:24 a.m. UTC | #2
Hi Kyle,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on v5.11-rc7 next-20210212]
[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/Kyle-Tso/usb-typec-tcpm-Export-partner-Source-Capabilities/20210214-113553
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: x86_64-randconfig-a013-20210214 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)
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
        # https://github.com/0day-ci/linux/commit/a80af7a2f4fa112b43e7b2b262729a8e1b28c132
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kyle-Tso/usb-typec-tcpm-Export-partner-Source-Capabilities/20210214-113553
        git checkout a80af7a2f4fa112b43e7b2b262729a8e1b28c132
        # 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 >>):

>> drivers/usb/typec/tcpm/tcpm.c:5762:11: error: implicit declaration of function 'tcpm_copy_pdos' [-Werror,-Wimplicit-function-declaration]
           nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps,
                    ^
   1 error generated.


vim +/tcpm_copy_pdos +5762 drivers/usb/typec/tcpm/tcpm.c

  5741	
  5742	/*
  5743	 * Don't call this function in interrupt context. Caller needs to free the
  5744	 * memory by calling tcpm_put_partner_src_caps.
  5745	 */
  5746	int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **src_pdo)
  5747	{
  5748		unsigned int nr_pdo;
  5749	
  5750		mutex_lock(&port->lock);
  5751		if (port->nr_source_caps == 0) {
  5752			mutex_unlock(&port->lock);
  5753			return -ENODATA;
  5754		}
  5755	
  5756		*src_pdo = kcalloc(port->nr_source_caps, sizeof(u32), GFP_KERNEL);
  5757		if (!src_pdo) {
  5758			mutex_unlock(&port->lock);
  5759			return -ENOMEM;
  5760		}
  5761	
> 5762		nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps,
  5763					port->nr_source_caps);
  5764		mutex_unlock(&port->lock);
  5765		return nr_pdo;
  5766	}
  5767	EXPORT_SYMBOL_GPL(tcpm_get_partner_src_caps);
  5768	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Christoph Hellwig Feb. 16, 2021, 9:14 a.m. UTC | #3
On Sun, Feb 14, 2021 at 11:30:52AM +0800, Kyle Tso wrote:
> Export a function for other drivers to get the partner Source
> Capabilities.
> 
> Signed-off-by: Kyle Tso <kyletso@google.com>

Who is going to use this?  Please submit any new export together with
the actual user.

Patch
diff mbox series

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index be0b6469dd3d..6c6d199f63b7 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -5739,6 +5739,40 @@  static int tcpm_fw_get_caps(struct tcpm_port *port,
 	return 0;
 }
 
+/*
+ * Don't call this function in interrupt context. Caller needs to free the
+ * memory by calling tcpm_put_partner_src_caps.
+ */
+int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **src_pdo)
+{
+	unsigned int nr_pdo;
+
+	mutex_lock(&port->lock);
+	if (port->nr_source_caps == 0) {
+		mutex_unlock(&port->lock);
+		return -ENODATA;
+	}
+
+	*src_pdo = kcalloc(port->nr_source_caps, sizeof(u32), GFP_KERNEL);
+	if (!src_pdo) {
+		mutex_unlock(&port->lock);
+		return -ENOMEM;
+	}
+
+	nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps,
+				port->nr_source_caps);
+	mutex_unlock(&port->lock);
+	return nr_pdo;
+}
+EXPORT_SYMBOL_GPL(tcpm_get_partner_src_caps);
+
+void tcpm_put_partner_src_caps(u32 **src_pdo)
+{
+	kfree(*src_pdo);
+	*src_pdo = NULL;
+}
+EXPORT_SYMBOL_GPL(tcpm_put_partner_src_caps);
+
 /* Power Supply access to expose source power information */
 enum tcpm_psy_online_states {
 	TCPM_PSY_OFFLINE = 0,
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index 42fcfbe10590..f83d9ff89a13 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -161,5 +161,7 @@  void tcpm_pd_transmit_complete(struct tcpm_port *port,
 			       enum tcpm_transmit_status status);
 void tcpm_pd_hard_reset(struct tcpm_port *port);
 void tcpm_tcpc_reset(struct tcpm_port *port);
+int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **pdo);
+void tcpm_put_partner_src_caps(u32 **pdo);
 
 #endif /* __LINUX_USB_TCPM_H */