coresight: Minor sparse and style fixes
cover coresight: Minor sparse and style fixes
I got a report that kcalloc() didn't exist in coresight-cti-platform.c on arm builds and that looked like we didn't include very many headers to get prototypes of functions like kcalloc(), etc. The first patch fixes this problem by including the headers and then the rest of these patches fix minor sparse and style issues that I saw while looking through the coresight directory.
Pathes based on v5.7-rc1.
Stephen Boyd (5):
coresight: Include required headers in C files
coresight: Mark some functions static
coresight: Don't initialize variables unnecessarily
coresight: Initialize arg in sparse friendly way
coresight: Avoid casting void pointers
.../coresight/coresight-cti-platform.c | 11 ++++++++--- .../hwtracing/coresight/coresight-cti-sysfs.c | 17 ++++++++++++----- drivers/hwtracing/coresight/coresight-cti.c | 6 +++--- drivers/hwtracing/coresight/coresight-cti.h | 10 +++++++++- drivers/hwtracing/coresight/coresight-etb10.c | 2 +- drivers/hwtracing/coresight/coresight-etm3x.c | 2 +- drivers/hwtracing/coresight/coresight-etm4x.c | 2 +- .../hwtracing/coresight/coresight-platform.c | 4 ++-- drivers/hwtracing/coresight/coresight-priv.h | 9 ++++++--- drivers/hwtracing/coresight/coresight-tmc.c | 2 +- 10 files changed, 44 insertions(+), 21 deletions(-)
base-commit: 8f3d9f354286745c751374f5f1fcafee6b3f3136
Signature · 1 line
Sent by a computer, using git, on the internet
PATCH 1/5 coresight: Include required headers in C files
We should include headers that C files use in the C files that use them and avoid relying on implicit includes as much as possible. This helps avoid compiler errors in the future about missing declarations when header files change includes in the future.
--- drivers/hwtracing/coresight/coresight-cti-platform.c | 8 +++++++- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 7 +++++++ drivers/hwtracing/coresight/coresight-cti.h | 10 +++++++++- 3 files changed, 23 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-cti-platform.c +7 -1
@@ -2,11 +2,17 @@/* * Copyright (c) 2019, The Linaro Limited. All rights reserved. */ +#include <linux/coresight.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/of.h> +#include <linux/property.h> +#include <linux/slab.h> #include <dt-bindings/arm/coresight-cti-dt.h> -#include <linux/of.h> #include "coresight-cti.h" +#include "coresight-priv.h" /* Number of CTI signals in the v8 architecturally defined connection */ #define NR_V8PE_IN_SIGS 2
drivers/hwtracing/coresight/coresight-cti-sysfs.c +7 -0
@@ -4,7 +4,14 @@* Author: Mike Leach <[email protected]> */ +#include <linux/atomic.h> #include <linux/coresight.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/sysfs.h> #include "coresight-cti.h"
drivers/hwtracing/coresight/coresight-cti.h +9 -1
@@ -7,8 +7,10 @@#ifndef _CORESIGHT_CORESIGHT_CTI_H#define _CORESIGHT_CORESIGHT_CTI_H -#include <asm/local.h> +#include <linux/list.h> #include <linux/spinlock.h> +#include <linux/types.h> +#include "coresight-priv.h" /*
@@ -52,6 +54,12 @@*/ #define CTIINOUTEN_MAX 32 +struct attribute ; +struct attribute_group ; +struct coresight_device ; +struct device ; +struct fwnode_handle ; +/** * Group of related trigger signals *
Signature · 1 line
Sent by a computer, using git, on the internet
PATCH 2/5 coresight: Mark some functions static
In reply to Stephen BoydThese functions aren't used outside the file they're in. Mark them static to indicate as such and silence tools like sparse.
--- drivers/hwtracing/coresight/coresight-cti-platform.c | 3 +-- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 2 +- drivers/hwtracing/coresight/coresight-cti.c | 6 +++--- drivers/hwtracing/coresight/coresight-etb10.c | 2 +- drivers/hwtracing/coresight/coresight-platform.c | 4 ++-- drivers/hwtracing/coresight/coresight-tmc.c | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-)
drivers/hwtracing/coresight/coresight-cti-platform.c +1 -2
@@ -435,8 +435,7 @@ static int cti_plat_create_impdef_connections(struct device *dev, }/* get the hardware configuration & connection data. */ -int cti_plat_get_hw_data (struct device *dev, -struct cti_drvdata *drvdata) +static int cti_plat_get_hw_data (struct device *dev,struct cti_drvdata *drvdata) {int rc =0 ;struct cti_device *cti_dev = &drvdata->ctidev;
drivers/hwtracing/coresight/coresight-cti-sysfs.c +1 -1
@@ -1146,7 +1146,7 @@ static int cti_create_con_attr_set(struct device *dev, int con_idx, }/* create the array of group pointers for the CTI sysfs groups */ -int cti_create_cons_groups (struct device *dev,struct cti_device *ctidev) +static int cti_create_cons_groups (struct device *dev,struct cti_device *ctidev) {int nr_groups;
drivers/hwtracing/coresight/coresight-cti.c +3 -3
@@ -19,7 +19,7 @@*/ /* net of CTI devices connected via CTM */ -LIST_HEAD (ect_net); +static LIST_HEAD (ect_net);/* protect the list */ static DEFINE_MUTEX (ect_mutex);
@@ -578,12 +578,12 @@ int cti_disable(struct coresight_device *csdev)return cti_disable_hw (drvdata); } -const struct coresight_ops_ect cti_ops_ect = { +static const struct coresight_ops_ect cti_ops_ect = { .enable = cti_enable, .disable = cti_disable, }; -const struct coresight_ops cti_ops = { +static const struct coresight_ops cti_ops = { .ect_ops = &cti_ops_ect, };
drivers/hwtracing/coresight/coresight-etb10.c +1 -1
@@ -717,7 +717,7 @@ static const struct attribute_group coresight_etb_mgmt_group = { .name = "mgmt", }; -const struct attribute_group *coresight_etb_groups[] = { +static const struct attribute_group *coresight_etb_groups[] = { &coresight_etb_group, &coresight_etb_mgmt_group,NULL ,
drivers/hwtracing/coresight/coresight-platform.c +2 -2
@@ -501,7 +501,7 @@ static inline bool acpi_validate_dsd_graph(const union acpi_object *graph) }/* acpi_get_dsd_graph - Find the _DSD Graph property for the given device. */ -const union acpi_object * +static const union acpi_object *acpi_get_dsd_graph (struct acpi_device *adev) {int i;
@@ -564,7 +564,7 @@ acpi_validate_coresight_graph(const union acpi_object *cs_graph)* Returns the pointer to the CoreSight Graph Package when found. Otherwise * returns NULL. */ -const union acpi_object * +static const union acpi_object *acpi_get_coresight_graph (struct acpi_device *adev) {const union acpi_object *graph_list, *graph;
drivers/hwtracing/coresight/coresight-tmc.c +1 -1
@@ -361,7 +361,7 @@ static const struct attribute_group coresight_tmc_mgmt_group = { .name = "mgmt", }; -const struct attribute_group *coresight_tmc_groups[] = { +static const struct attribute_group *coresight_tmc_groups[] = { &coresight_tmc_group, &coresight_tmc_mgmt_group,NULL ,
Signature · 1 line
Sent by a computer, using git, on the internet
PATCH 4/5 coresight: Initialize arg in sparse friendly way
In reply to Stephen BoydSparse gets annoyed when this initializer is 0 but the first struct member is a pointer. Just use { } to initialize instead so that sparse is quiet.
--- drivers/hwtracing/coresight/coresight-etm3x.c | 2 +- drivers/hwtracing/coresight/coresight-etm4x.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x.c +1 -1
@@ -504,7 +504,7 @@ static int etm_enable_perf(struct coresight_device *csdev,static int etm_enable_sysfs (struct coresight_device *csdev) {struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent); -struct etm_enable_arg arg = {0 }; +struct etm_enable_arg arg = { };int ret;spin_lock (&drvdata->spinlock);
drivers/hwtracing/coresight/coresight-etm4x.c +1 -1
@@ -412,7 +412,7 @@ static int etm4_enable_perf(struct coresight_device *csdev,static int etm4_enable_sysfs (struct coresight_device *csdev) {struct etmv4_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent); -struct etm4_enable_arg arg = {0 }; +struct etm4_enable_arg arg = { };int ret;spin_lock (&drvdata->spinlock);
Signature · 1 line
Sent by a computer, using git, on the internet
PATCH 5/5 coresight: Avoid casting void pointers
In reply to Stephen BoydWe don't need to cast void pointers, such as the amba_id data. Assign to a local variable to make the code prettier and also return NULL instead of 0 to make sparse happy.
--- drivers/hwtracing/coresight/coresight-priv.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/hwtracing/coresight/coresight-priv.h +6 -3
@@ -206,9 +206,12 @@ cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}/* extract the data value from a UCI structure given amba_id pointer. */ static inline void *coresight_get_uci_data (const struct amba_id *id) { -if (id->data) -return ((struct amba_cs_uci_id *)(id->data))->data; -return 0 ; +struct amba_cs_uci_id *uci_id = id->data; + +if (uci_id) +return id->data; + +return NULL ; }void coresight_release_platform_data (struct coresight_platform_data *pdata);
Signature · 1 line
Sent by a computer, using git, on the internet
PATCH 3/5 coresight: Don't initialize variables unnecessarily
In reply to Stephen BoydThese variables are assigned again before they're used. Leave them unassigned at first so that the compiler can detect problems in the future with use before initialization.
--- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-cti-sysfs.c +4 -4
@@ -1043,8 +1043,8 @@ static int cti_create_con_sysfs_attr(struct device *dev, enum cti_conn_attr_type attr_type, int attr_idx) { -struct dev_ext_attribute *eattr =0 ; -char *name =0 ; +struct dev_ext_attribute *eattr; +char *name; eattr =devm_kzalloc (dev,sizeof (struct dev_ext_attribute ),GFP_KERNEL );
@@ -1163,8 +1163,8 @@ static int cti_create_cons_groups(struct device *dev, struct cti_device *ctidev)int cti_create_cons_sysfs (struct device *dev,struct cti_drvdata *drvdata) {struct cti_device *ctidev = &drvdata->ctidev; -int err =0 , con_idx =0 , i; -struct cti_trig_con *tc =NULL ; +int err, con_idx =0 , i; +struct cti_trig_con *tc; err =cti_create_cons_groups (dev, ctidev);if (err)
Signature · 1 line
Sent by a computer, using git, on the internet
Re: [PATCH 5/5] coresight: Avoid casting void pointers
In reply to Stephen BoydQuoted 3 lines · Stephen Boyd
We don't need to cast void pointers, such as the
amba_iddata. Assign to a local variable to make the code prettier and also return NULL instead of 0 to make sparse happy.
[]
drivers/hwtracing/coresight/coresight-priv.h
Quoted 1 line
drivers/hwtracing/coresight/coresight-priv.h +0
-0
[]
drivers/hwtracing/coresight/coresight-priv.h cti_remove_assoc_from_csdev(struct coresight_device *csdev) {} · line 212
Quoted 11 lines
drivers/hwtracing/coresight/coresight-priv.h +4
-3@@ -206,9 +206,12 @@ cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}/* extract the data value from a UCI structure given amba_id pointer. */ static inline void *coresight_get_uci_data (const struct amba_id *id) { -if (id->data) -return ((struct amba_cs_uci_id *)(id->data))->data; -return 0 ; +struct amba_cs_uci_id *uci_id = id->data; + +if (uci_id) +return id->data;
Missing one more level of indirection here yes?
return uci_id->data;
drivers/hwtracing/coresight/coresight-priv.h cti_remove_assoc_from_csdev(struct coresight_device *csdev) {} · line 215
Quoted 3 lines
drivers/hwtracing/coresight/coresight-priv.h +2
-0+ +return NULL ; }
And this code would generally be written to return the expected value at the bottom of the function and any unusual return early like:
static inline void *coresight_get_uci_data(const struct amba_id *id)
{
struct amba_cs_uci_id *uci_id = id->data;
if (!uci_id)
return NULL;
return uci_id->data;
}Re: [PATCH 1/5] coresight: Include required headers in C files
In reply to Stephen BoydQuoted 74 lines · Stephen Boyd
We should include headers that C files use in the C files that use them and avoid relying on implicit includes as much as possible. This helps avoid compiler errors in the future about missing declarations when header files change includes in the future.
Cc Douglas Anderson <[email protected]>Cc Suzuki K Poulose <[email protected]>Cc Mike Leach <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- drivers/hwtracing/coresight/coresight-cti-platform.c | 8 +++++++- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 7 +++++++ drivers/hwtracing/coresight/coresight-cti.h | 10 +++++++++- 3 files changed, 23 insertions(+), 2 deletions(-)drivers/hwtracing/coresight/coresight-cti-platform.c +7
-1@@ -2,11 +2,17 @@/* * Copyright (c) 2019, The Linaro Limited. All rights reserved. */ +#include <linux/coresight.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/of.h> +#include <linux/property.h> +#include <linux/slab.h> #include <dt-bindings/arm/coresight-cti-dt.h> -#include <linux/of.h> #include "coresight-cti.h" +#include "coresight-priv.h" /* Number of CTI signals in the v8 architecturally defined connection */ #define NR_V8PE_IN_SIGS 2drivers/hwtracing/coresight/coresight-cti-sysfs.c +7
-0@@ -4,7 +4,14 @@* Author: Mike Leach <[email protected]> */ +#include <linux/atomic.h> #include <linux/coresight.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/sysfs.h> #include "coresight-cti.h" drivers/hwtracing/coresight/coresight-cti.h +3
-1@@ -7,8 +7,10 @@#ifndef _CORESIGHT_CORESIGHT_CTI_H#define _CORESIGHT_CORESIGHT_CTI_H -#include <asm/local.h> +#include <linux/list.h> #include <linux/spinlock.h> +#include <linux/types.h> +#include "coresight-priv.h" /*
drivers/hwtracing/coresight/coresight-cti.h line 62
Quoted 9 lines
drivers/hwtracing/coresight/coresight-cti.h +6
-0@@ -52,6 +54,12 @@*/ #define CTIINOUTEN_MAX 32 +struct attribute ; +struct attribute_group ; +struct coresight_device ; +struct device ; +struct fwnode_handle ; +
I would prefer adding the headers rather than forward declarations, it scales better.
Thanks,
Mathieu
Quoted 6 lines
drivers/hwtracing/coresight/coresight-cti.h +0
-0/** * Group of related trigger signals * Signature · 1 line
Sent by a computer, using git, on the internet
Quoted 13 lines · Stephen Boyd
I got a report that
kcalloc()didn't exist incoresight-cti-platform.con arm builds and that looked like we didn't include very many headers to get prototypes of functions likekcalloc(), etc. The first patch fixes this problem by including the headers and then the rest of these patches fix minor sparse and style issues that I saw while looking through the coresight directory.Pathes based on v5.7-rc1.
Cc Suzuki K Poulose <[email protected]>Cc Mike Leach <[email protected]>Cc Douglas Anderson <[email protected]>
Quoted 6 lines
Stephen Boyd (5):
coresight: Include required headers in C files
coresight: Mark some functions static
coresight: Don't initialize variables unnecessarily
coresight: Initialize arg in sparse friendly way
coresight: Avoid casting void pointers
I have applied patches 2, 3 and 4, so no need to send them again. Note that I dropped changes to coresight-cti.c and coresight-etb10.c in patch 2 as the changes were already in my coresight-next branch.
Thanks,
Mathieu
Quoted 18 lines
.../coresight/coresight-cti-platform.c | 11 ++++++++--- .../hwtracing/coresight/coresight-cti-sysfs.c | 17 ++++++++++++----- drivers/hwtracing/coresight/coresight-cti.c | 6 +++--- drivers/hwtracing/coresight/coresight-cti.h | 10 +++++++++- drivers/hwtracing/coresight/coresight-etb10.c | 2 +- drivers/hwtracing/coresight/coresight-etm3x.c | 2 +- drivers/hwtracing/coresight/coresight-etm4x.c | 2 +- .../hwtracing/coresight/coresight-platform.c | 4 ++-- drivers/hwtracing/coresight/coresight-priv.h | 9 ++++++--- drivers/hwtracing/coresight/coresight-tmc.c | 2 +- 10 files changed, 44 insertions(+), 21 deletions(-)base-commit:
8f3d9f354286745c751374f5f1fcafee6b3f3136Signature · 1 line
Sent by a computer, using git, on the internet
Re: [PATCH 1/5] coresight: Include required headers in C files
In reply to Mathieu PoirierQuoting Mathieu Poirier (2020-04-27 09:34:46)
Quoted 21 lines · Stephen Boyd
Quoted 20 lines
drivers/hwtracing/coresight/coresight-cti.h +3
-1@@ -7,8 +7,10 @@#ifndef _CORESIGHT_CORESIGHT_CTI_H#define _CORESIGHT_CORESIGHT_CTI_H -#include <asm/local.h> +#include <linux/list.h> #include <linux/spinlock.h> +#include <linux/types.h> +#include "coresight-priv.h" /* @@ -52,6 +54,12 @@*/ #define CTIINOUTEN_MAX 32
Quoted 10 lines
drivers/hwtracing/coresight/coresight-cti.h line 62
Quoted 6 lines
drivers/hwtracing/coresight/coresight-cti.h +6
-0+struct attribute ; +struct attribute_group ; +struct coresight_device ; +struct device ; +struct fwnode_handle ; +I would prefer adding the headers rather than forward declarations, it scales better.
Ok. I'm worried that including too many headers when they're not necessary means it's easier to get into the problem that I'm trying to solve here where kcalloc() isn't defined. Anyway, I'll update the patch and resend!