Skip to contentSkip to conversation

coresight: cti: Remove unnecessary NULL check in cti_sig_type_name

PATCH In review Nathan Chancellor 3 participants 4 messages Mar 2, 2020 – Mar 4, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coresight: cti: Remove unnecessary NULL check in cti_sig_type_name

Clang warns:

drivers/hwtracing/coresight/coresight-cti-sysfs.c:948:11: warning:
address of array 'grp->sig_types' will always evaluate to 'true' [-Wpointer-bool-conversion]

        if (grp->sig_types) {
        ~~  ~~~~~^~~~~~~~~

1 warning generated.

sig_types is at the end of a struct so it cannot be NULL.

Fixes 85b6684eab65 ("coresight: cti: Add connection information to sysfs")
---
 drivers/hwtracing/coresight/coresight-cti-sysfs.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-cti-sysfs.c +2 -4
index abb7f492c2cb..214d6552b494 100644
@@ -945,10 +945,8 @@ cti_sig_type_name(struct cti_trig_con *con, int used_count, bool in)
 	int idx = 0;
 	struct cti_trig_grp *grp = in ? con->con_in : con->con_out;
 
-	if (grp->sig_types) {
-		if (used_count < grp->nr_sigs)
-			idx = grp->sig_types[used_count];
-	}
+	if (used_count < grp->nr_sigs)
+		idx = grp->sig_types[used_count];
 	return sig_type_names[idx];
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Nathan Chancellor

Clang warns:

drivers/hwtracing/coresight/coresight-cti-sysfs.c:948:11: warning:
address of array 'grp->sig_types' will always evaluate to 'true' [-Wpointer-bool-conversion]

        if (grp->sig_types) {
        ~~  ~~~~~^~~~~~~~~
Quoted 7 lines

1 warning generated.

sig_types is at the end of a struct so it cannot be NULL.

Fixes 85b6684eab65 ("coresight: cti: Add connection information to sysfs")

Yep, GCC and Clang both eliminate the false case as impossible:
https://godbolt.org/z/tjbDqR

Quoted 22 lines
---
 drivers/hwtracing/coresight/coresight-cti-sysfs.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-cti-sysfs.c +2 -5
index abb7f492c2cb..214d6552b494 100644
@@ -945,10 +945,8 @@ cti_sig_type_name(struct cti_trig_con *con, int used_count, bool in)
        int idx = 0;
        struct cti_trig_grp *grp = in ? con->con_in : con->con_out;
 
-       if (grp->sig_types) {
-               if (used_count < grp->nr_sigs)
-                       idx = grp->sig_types[used_count];
-       }
+       if (used_count < grp->nr_sigs)
+               idx = grp->sig_types[used_count];
        return sig_type_names[idx];
 }
 
--
Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 15 lines · Nick Desaulniers
Quoted 12 lines · Nathan Chancellor

Clang warns:

drivers/hwtracing/coresight/coresight-cti-sysfs.c:948:11: warning:
address of array 'grp->sig_types' will always evaluate to 'true' [-Wpointer-bool-conversion]

        if (grp->sig_types) {
        ~~  ~~~~~^~~~~~~~~

1 warning generated.

sig_types is at the end of a struct so it cannot be NULL.

Quoted 7 lines
Quoted 3 lines
Fixes 85b6684eab65 ("coresight: cti: Add connection information to sysfs")

Yep, GCC and Clang both eliminate the false case as impossible:
https://godbolt.org/z/tjbDqR

0day just reported this, too (3 minutes after you sent your patch)
https://groups.google.com/forum/#!msg/clang-built-linux/_SpkRyhMIxI/IrBtEk-8AAAJ
If you wanted to show some love for the bot:

Quoted 28 lines
Quoted 13 lines
---
 drivers/hwtracing/coresight/coresight-cti-sysfs.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-cti-sysfs.c +0 -0
index abb7f492c2cb..214d6552b494 100644
@@ -945,10 +945,8 @@ cti_sig_type_name(struct cti_trig_con *con, int used_count, bool in)
        int idx = 0;
        struct cti_trig_grp *grp = in ? con->con_in : con->con_out;
 

drivers/hwtracing/coresight/coresight-cti-sysfs.c cti_sig_type_name(struct cti_trig_con *con, int used_count, bool in)

Quoted 10 lines
drivers/hwtracing/coresight/coresight-cti-sysfs.c +2 -5
-       if (grp->sig_types) {
-               if (used_count < grp->nr_sigs)
-                       idx = grp->sig_types[used_count];
-       }
+       if (used_count < grp->nr_sigs)
+               idx = grp->sig_types[used_count];
        return sig_type_names[idx];
 }
 
--

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
In reply to Nathan Chancellor
Quoted 25 lines · Nathan Chancellor

Clang warns:

drivers/hwtracing/coresight/coresight-cti-sysfs.c:948:11: warning:
address of array 'grp->sig_types' will always evaluate to 'true' [-Wpointer-bool-conversion]

        if (grp->sig_types) {
        ~~  ~~~~~^~~~~~~~~

1 warning generated.

sig_types is at the end of a struct so it cannot be NULL.

Fixes 85b6684eab65 ("coresight: cti: Add connection information to sysfs")
---
 drivers/hwtracing/coresight/coresight-cti-sysfs.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-cti-sysfs.c +0 -0
index abb7f492c2cb..214d6552b494 100644
@@ -945,10 +945,8 @@ cti_sig_type_name(struct cti_trig_con *con, int used_count, bool in)
        int idx = 0;

drivers/hwtracing/coresight/coresight-cti-sysfs.c cti_sig_type_name(struct cti_trig_con *con, int used_count, bool in) · line 951

Quoted 10 lines
drivers/hwtracing/coresight/coresight-cti-sysfs.c +2 -4
        struct cti_trig_grp *grp = in ? con->con_in : con->con_out;
 
-       if (grp->sig_types) {
-               if (used_count < grp->nr_sigs)
-                       idx = grp->sig_types[used_count];
-       }
+       if (used_count < grp->nr_sigs)
+               idx = grp->sig_types[used_count];
        return sig_type_names[idx];
 }

Applied - thanks,
Mathieu

Quoted 4 lines
drivers/hwtracing/coresight/coresight-cti-sysfs.c +0 -1
--

2.25.1