diff mbox series

[v2,1/2] coresight: core: Add device name support

Message ID 20240115164252.26510-2-quic_jinlmao@quicinc.com
State New
Headers show
Series coresight: core: Add device name support | expand

Commit Message

Mao Jinlong Jan. 15, 2024, 4:42 p.m. UTC
For some coresight components like CTI and TPDM, there could be
numerous of them. From the node name, we can only get the type and
register address of the component. We can't identify the HW or the
system the component belongs to. Add the device-name support for
adding the intuitive name of the device.

Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com>
---
 drivers/hwtracing/coresight/coresight-core.c  | 33 ++++++++++---------
 .../hwtracing/coresight/coresight-platform.c  | 31 +++++++++++++++++
 include/linux/coresight.h                     |  1 +
 3 files changed, 50 insertions(+), 15 deletions(-)

Comments

kernel test robot Jan. 16, 2024, 10:09 a.m. UTC | #1
Hi Mao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.7 next-20240112]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mao-Jinlong/coresight-core-Add-device-name-support/20240116-004557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240115164252.26510-2-quic_jinlmao%40quicinc.com
patch subject: [PATCH v2 1/2] coresight: core: Add device name support
config: arm-randconfig-r112-20240116 (https://download.01.org/0day-ci/archive/20240116/202401161751.IuhpKb75-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20240116/202401161751.IuhpKb75-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401161751.IuhpKb75-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/hwtracing/coresight/coresight-core.c:1775:14: sparse: sparse: incorrect type in assignment (different modifiers) @@     expected char *name @@     got char const * @@
   drivers/hwtracing/coresight/coresight-core.c:1775:14: sparse:     expected char *name
   drivers/hwtracing/coresight/coresight-core.c:1775:14: sparse:     got char const *

vim +1775 drivers/hwtracing/coresight/coresight-core.c

  1758	
  1759	/*
  1760	 * coresight_alloc_device_name - Get an index for a given device in the
  1761	 * device index list specific to a driver. An index is allocated for a
  1762	 * device and is tracked with the fwnode_handle to prevent allocating
  1763	 * duplicate indices for the same device (e.g, if we defer probing of
  1764	 * a device due to dependencies), in case the index is requested again.
  1765	 */
  1766	char *coresight_alloc_device_name(struct coresight_dev_list *dict,
  1767					  struct device *dev)
  1768	{
  1769		int idx;
  1770		char *name = NULL;
  1771		struct fwnode_handle **list;
  1772	
  1773		mutex_lock(&coresight_mutex);
  1774	
> 1775		name = coresight_get_device_name(dev);
  1776		if (!name) {
  1777			idx = coresight_search_device_idx(dict, dev_fwnode(dev));
  1778			if (idx < 0) {
  1779				/* Make space for the new entry */
  1780				idx = dict->nr_idx;
  1781				list = krealloc_array(dict->fwnode_list,
  1782						      idx + 1, sizeof(*dict->fwnode_list),
  1783						      GFP_KERNEL);
  1784				if (ZERO_OR_NULL_PTR(list)) {
  1785					idx = -ENOMEM;
  1786					goto done;
  1787				}
  1788	
  1789				list[idx] = dev_fwnode(dev);
  1790				dict->fwnode_list = list;
  1791				dict->nr_idx = idx + 1;
  1792			}
  1793	
  1794			name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", dict->pfx, idx);
  1795		}
  1796	done:
  1797		mutex_unlock(&coresight_mutex);
  1798		return name;
  1799	}
  1800	EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
  1801
kernel test robot Jan. 16, 2024, 10:41 a.m. UTC | #2
Hi Mao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.7 next-20240112]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mao-Jinlong/coresight-core-Add-device-name-support/20240116-004557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240115164252.26510-2-quic_jinlmao%40quicinc.com
patch subject: [PATCH v2 1/2] coresight: core: Add device name support
config: arm64-defconfig (https://download.01.org/0day-ci/archive/20240116/202401161834.N4E6YW3K-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240116/202401161834.N4E6YW3K-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401161834.N4E6YW3K-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/hwtracing/coresight/coresight-core.c: In function 'coresight_alloc_device_name':
>> drivers/hwtracing/coresight/coresight-core.c:1775:14: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    1775 |         name = coresight_get_device_name(dev);
         |              ^


vim +/const +1775 drivers/hwtracing/coresight/coresight-core.c

  1758	
  1759	/*
  1760	 * coresight_alloc_device_name - Get an index for a given device in the
  1761	 * device index list specific to a driver. An index is allocated for a
  1762	 * device and is tracked with the fwnode_handle to prevent allocating
  1763	 * duplicate indices for the same device (e.g, if we defer probing of
  1764	 * a device due to dependencies), in case the index is requested again.
  1765	 */
  1766	char *coresight_alloc_device_name(struct coresight_dev_list *dict,
  1767					  struct device *dev)
  1768	{
  1769		int idx;
  1770		char *name = NULL;
  1771		struct fwnode_handle **list;
  1772	
  1773		mutex_lock(&coresight_mutex);
  1774	
> 1775		name = coresight_get_device_name(dev);
  1776		if (!name) {
  1777			idx = coresight_search_device_idx(dict, dev_fwnode(dev));
  1778			if (idx < 0) {
  1779				/* Make space for the new entry */
  1780				idx = dict->nr_idx;
  1781				list = krealloc_array(dict->fwnode_list,
  1782						      idx + 1, sizeof(*dict->fwnode_list),
  1783						      GFP_KERNEL);
  1784				if (ZERO_OR_NULL_PTR(list)) {
  1785					idx = -ENOMEM;
  1786					goto done;
  1787				}
  1788	
  1789				list[idx] = dev_fwnode(dev);
  1790				dict->fwnode_list = list;
  1791				dict->nr_idx = idx + 1;
  1792			}
  1793	
  1794			name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", dict->pfx, idx);
  1795		}
  1796	done:
  1797		mutex_unlock(&coresight_mutex);
  1798		return name;
  1799	}
  1800	EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
  1801
kernel test robot Jan. 16, 2024, 11:34 a.m. UTC | #3
Hi Mao,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.7 next-20240112]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mao-Jinlong/coresight-core-Add-device-name-support/20240116-004557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240115164252.26510-2-quic_jinlmao%40quicinc.com
patch subject: [PATCH v2 1/2] coresight: core: Add device name support
config: arm-randconfig-r081-20240116 (https://download.01.org/0day-ci/archive/20240116/202401161905.KuRUhKW4-lkp@intel.com/config)
compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project 9bde5becb44ea071f5e1fa1f5d4071dc8788b18c)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240116/202401161905.KuRUhKW4-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401161905.KuRUhKW4-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/hwtracing/coresight/coresight-core.c:1775:7: error: assigning to 'char *' from 'const char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    1775 |         name = coresight_get_device_name(dev);
         |              ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   1 error generated.


vim +1775 drivers/hwtracing/coresight/coresight-core.c

  1758	
  1759	/*
  1760	 * coresight_alloc_device_name - Get an index for a given device in the
  1761	 * device index list specific to a driver. An index is allocated for a
  1762	 * device and is tracked with the fwnode_handle to prevent allocating
  1763	 * duplicate indices for the same device (e.g, if we defer probing of
  1764	 * a device due to dependencies), in case the index is requested again.
  1765	 */
  1766	char *coresight_alloc_device_name(struct coresight_dev_list *dict,
  1767					  struct device *dev)
  1768	{
  1769		int idx;
  1770		char *name = NULL;
  1771		struct fwnode_handle **list;
  1772	
  1773		mutex_lock(&coresight_mutex);
  1774	
> 1775		name = coresight_get_device_name(dev);
  1776		if (!name) {
  1777			idx = coresight_search_device_idx(dict, dev_fwnode(dev));
  1778			if (idx < 0) {
  1779				/* Make space for the new entry */
  1780				idx = dict->nr_idx;
  1781				list = krealloc_array(dict->fwnode_list,
  1782						      idx + 1, sizeof(*dict->fwnode_list),
  1783						      GFP_KERNEL);
  1784				if (ZERO_OR_NULL_PTR(list)) {
  1785					idx = -ENOMEM;
  1786					goto done;
  1787				}
  1788	
  1789				list[idx] = dev_fwnode(dev);
  1790				dict->fwnode_list = list;
  1791				dict->nr_idx = idx + 1;
  1792			}
  1793	
  1794			name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", dict->pfx, idx);
  1795		}
  1796	done:
  1797		mutex_unlock(&coresight_mutex);
  1798		return name;
  1799	}
  1800	EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
  1801
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index 9fabe00a40d6..b85fc5cc3807 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1772,24 +1772,27 @@  char *coresight_alloc_device_name(struct coresight_dev_list *dict,
 
 	mutex_lock(&coresight_mutex);
 
-	idx = coresight_search_device_idx(dict, dev_fwnode(dev));
-	if (idx < 0) {
-		/* Make space for the new entry */
-		idx = dict->nr_idx;
-		list = krealloc_array(dict->fwnode_list,
-				      idx + 1, sizeof(*dict->fwnode_list),
-				      GFP_KERNEL);
-		if (ZERO_OR_NULL_PTR(list)) {
-			idx = -ENOMEM;
-			goto done;
+	name = coresight_get_device_name(dev);
+	if (!name) {
+		idx = coresight_search_device_idx(dict, dev_fwnode(dev));
+		if (idx < 0) {
+			/* Make space for the new entry */
+			idx = dict->nr_idx;
+			list = krealloc_array(dict->fwnode_list,
+					      idx + 1, sizeof(*dict->fwnode_list),
+					      GFP_KERNEL);
+			if (ZERO_OR_NULL_PTR(list)) {
+				idx = -ENOMEM;
+				goto done;
+			}
+
+			list[idx] = dev_fwnode(dev);
+			dict->fwnode_list = list;
+			dict->nr_idx = idx + 1;
 		}
 
-		list[idx] = dev_fwnode(dev);
-		dict->fwnode_list = list;
-		dict->nr_idx = idx + 1;
+		name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", dict->pfx, idx);
 	}
-
-	name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", dict->pfx, idx);
 done:
 	mutex_unlock(&coresight_mutex);
 	return name;
diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 9d550f5697fa..c6c68fc9f787 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -183,6 +183,22 @@  static int of_coresight_get_cpu(struct device *dev)
 	return cpu;
 }
 
+static const char *of_coresight_get_device_name(struct device *dev)
+{
+	const char *name = NULL;
+
+	if (!dev->of_node)
+		return NULL;
+
+	/*
+	 * Get the device name from DT. The name describes the HW or
+	 * system the device is for.
+	 */
+	of_property_read_string(dev->of_node, "device-name", &name);
+
+	return name;
+}
+
 /*
  * of_coresight_parse_endpoint : Parse the given output endpoint @ep
  * and fill the connection information in @pdata->out_conns
@@ -315,6 +331,12 @@  static inline int of_coresight_get_cpu(struct device *dev)
 {
 	return -ENODEV;
 }
+
+static inline const char *of_coresight_get_device_name(struct device *dev)
+{
+	return NULL;
+}
+
 #endif
 
 #ifdef CONFIG_ACPI
@@ -794,6 +816,15 @@  int coresight_get_cpu(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(coresight_get_cpu);
 
+const char *coresight_get_device_name(struct device *dev)
+{
+	if (is_of_node(dev->fwnode))
+		return of_coresight_get_device_name(dev);
+	else
+		return NULL;
+}
+EXPORT_SYMBOL_GPL(coresight_get_device_name);
+
 struct coresight_platform_data *
 coresight_get_platform_data(struct device *dev)
 {
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index a269fffaf991..caa17c8af865 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -675,6 +675,7 @@  static inline void coresight_write64(struct coresight_device *csdev, u64 val, u3
 #endif		/* IS_ENABLED(CONFIG_CORESIGHT) */
 
 extern int coresight_get_cpu(struct device *dev);
+extern const char *coresight_get_device_name(struct device *dev);
 
 struct coresight_platform_data *coresight_get_platform_data(struct device *dev);
 struct coresight_connection *